| @@ 144-176 (lines=33) @@ | ||
| 141 | if plugin is not None: |
|
| 142 | if name is None: |
|
| 143 | command_list = {} |
|
| 144 | for key in self._commands.keys(): |
|
| 145 | if self._commands[key].plugin == plugin: |
|
| 146 | command_list[key] = self._commands[key] |
|
| 147 | return command_list |
|
| 148 | else: |
|
| 149 | if name in self._commands.keys(): |
|
| 150 | if self._commands[name].plugin == plugin: |
|
| 151 | return self._commands[name] |
|
| 152 | else: |
|
| 153 | return None |
|
| 154 | else: |
|
| 155 | return None |
|
| 156 | else: |
|
| 157 | if name is None: |
|
| 158 | return self._commands |
|
| 159 | else: |
|
| 160 | if name in self._commands.keys(): |
|
| 161 | return self._commands[name] |
|
| 162 | else: |
|
| 163 | return None |
|
| 164 | ||
| 165 | def register(self, command, description, function, params=[], plugin=None): |
|
| 166 | """ |
|
| 167 | Registers a new command, which can be used on a command line interface (cli). |
|
| 168 | ||
| 169 | :param command: Name of the command |
|
| 170 | :param description: Description of the command. Is used as help message on cli |
|
| 171 | :param function: function reference, which gets invoked if command gets called. |
|
| 172 | :param params: list of click options and arguments |
|
| 173 | :param plugin: the plugin, which registered this command |
|
| 174 | :return: command object |
|
| 175 | """ |
|
| 176 | if command in self._commands.keys(): |
|
| 177 | raise CommandExistException("Command %s already registered by %s" % (command, |
|
| 178 | self._commands[command].plugin.name)) |
|
| 179 | ||
| @@ 154-185 (lines=32) @@ | ||
| 151 | else: |
|
| 152 | return None |
|
| 153 | ||
| 154 | def get_receiver(self, receiver=None, plugin=None): |
|
| 155 | """ |
|
| 156 | Get one or more signals. |
|
| 157 | ||
| 158 | :param receiver: Name of the signal |
|
| 159 | :type receiver: str |
|
| 160 | :param plugin: Plugin object, under which the signals where registered |
|
| 161 | :type plugin: GwBasePattern |
|
| 162 | """ |
|
| 163 | if plugin is not None: |
|
| 164 | if receiver is None: |
|
| 165 | receiver_list = {} |
|
| 166 | for key in self.receivers.keys(): |
|
| 167 | if self.receivers[key].plugin == plugin: |
|
| 168 | receiver_list[key] = self.receivers[key] |
|
| 169 | return receiver_list |
|
| 170 | else: |
|
| 171 | if receiver in self.receivers.keys(): |
|
| 172 | if self.receivers[receiver].plugin == plugin: |
|
| 173 | return self.receivers[receiver] |
|
| 174 | else: |
|
| 175 | return None |
|
| 176 | else: |
|
| 177 | return None |
|
| 178 | else: |
|
| 179 | if receiver is None: |
|
| 180 | return self.receivers |
|
| 181 | else: |
|
| 182 | if receiver in self.receivers.keys(): |
|
| 183 | return self.receivers[receiver] |
|
| 184 | else: |
|
| 185 | return None |
|
| 186 | ||
| 187 | ||
| 188 | class Signal: |
|
| @@ 121-152 (lines=32) @@ | ||
| 118 | rv = self.signals[signal].send(plugin, text="test") |
|
| 119 | return rv |
|
| 120 | ||
| 121 | def get(self, signal=None, plugin=None): |
|
| 122 | """ |
|
| 123 | Get one or more signals. |
|
| 124 | ||
| 125 | :param signal: Name of the signal |
|
| 126 | :type signal: str |
|
| 127 | :param plugin: Plugin object, under which the signals where registered |
|
| 128 | :type plugin: GwBasePattern |
|
| 129 | """ |
|
| 130 | if plugin is not None: |
|
| 131 | if signal is None: |
|
| 132 | signals_list = {} |
|
| 133 | for key in self.signals.keys(): |
|
| 134 | if self.signals[key].plugin == plugin: |
|
| 135 | signals_list[key] = self.signals[key] |
|
| 136 | return signals_list |
|
| 137 | else: |
|
| 138 | if signal in self.signals.keys(): |
|
| 139 | if self.signals[signal].plugin == plugin: |
|
| 140 | return self.signals[signal] |
|
| 141 | else: |
|
| 142 | return None |
|
| 143 | else: |
|
| 144 | return None |
|
| 145 | else: |
|
| 146 | if signal is None: |
|
| 147 | return self.signals |
|
| 148 | else: |
|
| 149 | if signal in self.signals.keys(): |
|
| 150 | return self.signals[signal] |
|
| 151 | else: |
|
| 152 | return None |
|
| 153 | ||
| 154 | def get_receiver(self, receiver=None, plugin=None): |
|
| 155 | """ |
|
| @@ 143-174 (lines=32) @@ | ||
| 140 | if document is None: |
|
| 141 | documents_list = {} |
|
| 142 | for key in self.documents.keys(): |
|
| 143 | if self.documents[key].plugin == plugin: |
|
| 144 | documents_list[key] = self.documents[key] |
|
| 145 | return documents_list |
|
| 146 | else: |
|
| 147 | if document in self.documents.keys(): |
|
| 148 | if self.documents[document].plugin == plugin: |
|
| 149 | return self.documents[document] |
|
| 150 | else: |
|
| 151 | return None |
|
| 152 | else: |
|
| 153 | return None |
|
| 154 | else: |
|
| 155 | if document is None: |
|
| 156 | return self.documents |
|
| 157 | else: |
|
| 158 | if document in self.documents.keys(): |
|
| 159 | return self.documents[document] |
|
| 160 | else: |
|
| 161 | return None |
|
| 162 | ||
| 163 | ||
| 164 | class Document: |
|
| 165 | """ |
|
| 166 | Groundwork document class. Used to store name, file_path, alias and plugin. |
|
| 167 | ||
| 168 | This information is mostly used to generated overviews about registered documents. |
|
| 169 | ||
| 170 | :param name: Name of the document |
|
| 171 | :type name: str |
|
| 172 | :param content: Content of the document, which is used for documentation building |
|
| 173 | :type content: str (jinja + rst) |
|
| 174 | :param plugin: The plugin, which registered this document |
|
| 175 | :type plugin: GwBasePattern |
|
| 176 | :param description: short description of document |
|
| 177 | """ |
|
| @@ 140-171 (lines=32) @@ | ||
| 137 | if name is None: |
|
| 138 | shared_objects_list = {} |
|
| 139 | for key in self._shared_objects.keys(): |
|
| 140 | if self._shared_objects[key].plugin == plugin: |
|
| 141 | shared_objects_list[key] = self._shared_objects[key] |
|
| 142 | return shared_objects_list |
|
| 143 | else: |
|
| 144 | if name in self._shared_objects.keys(): |
|
| 145 | if self._shared_objects[name].plugin == plugin: |
|
| 146 | return self._shared_objects[name] |
|
| 147 | else: |
|
| 148 | return None |
|
| 149 | else: |
|
| 150 | return None |
|
| 151 | else: |
|
| 152 | if name is None: |
|
| 153 | return self._shared_objects |
|
| 154 | else: |
|
| 155 | if name in self._shared_objects.keys(): |
|
| 156 | return self._shared_objects[name] |
|
| 157 | else: |
|
| 158 | return None |
|
| 159 | ||
| 160 | def access(self, name): |
|
| 161 | """ |
|
| 162 | Returns the object of the shared_object, if the given name has been registered. |
|
| 163 | ||
| 164 | Unlike :func:`get()`, which returns the complete instance of a shared object, including |
|
| 165 | name, description, plugin, access() returns the object only (without any meta data). |
|
| 166 | ||
| 167 | :param name: Name of the shared object |
|
| 168 | :return: object, whatever it may be... |
|
| 169 | """ |
|
| 170 | return self.get(name, plugin=None).obj |
|
| 171 | ||
| 172 | def register(self, name, description, obj, plugin): |
|
| 173 | """ |
|
| 174 | Registers a new shared object. |
|
| @@ 139-170 (lines=32) @@ | ||
| 136 | del (self.recipes[recipe]) |
|
| 137 | self.__log.debug("Recipe %s got unregistered" % recipe) |
|
| 138 | ||
| 139 | def get(self, recipe=None, plugin=None): |
|
| 140 | """ |
|
| 141 | Get one or more recipes. |
|
| 142 | ||
| 143 | :param recipe: Name of the recipe |
|
| 144 | :type recipe: str |
|
| 145 | :param plugin: Plugin object, under which the recipe where registered |
|
| 146 | :type plugin: GwBasePattern |
|
| 147 | """ |
|
| 148 | if plugin is not None: |
|
| 149 | if recipe is None: |
|
| 150 | recipes_list = {} |
|
| 151 | for key in self.recipes.keys(): |
|
| 152 | if self.recipes[key].plugin == plugin: |
|
| 153 | recipes_list[key] = self.recipes[key] |
|
| 154 | return recipes_list |
|
| 155 | else: |
|
| 156 | if recipe in self.recipes.keys(): |
|
| 157 | if self.recipes[recipe].plugin == plugin: |
|
| 158 | return self.recipes[recipe] |
|
| 159 | else: |
|
| 160 | return None |
|
| 161 | else: |
|
| 162 | return None |
|
| 163 | else: |
|
| 164 | if recipe is None: |
|
| 165 | return self.recipes |
|
| 166 | else: |
|
| 167 | if recipe in self.recipes.keys(): |
|
| 168 | return self.recipes[recipe] |
|
| 169 | else: |
|
| 170 | return None |
|
| 171 | ||
| 172 | def build(self, recipe, plugin=None): |
|
| 173 | """ |
|