src.plugins.plugin_plugins_manager

Plugin to manage plugins

 1"""Plugin to manage plugins"""
 2import inspect
 3from src.cmd_types.commands import ExecutableCommand
 4from src.cmd_types.output import CommandOutput
 5from src.decorators import commands_register as cmd_register
 6
 7__author__ = "default"
 8__version__ = "1.0.0"
 9
10@cmd_register.command("plugins", flags=["-s"])
11class PluginsCommand(ExecutableCommand):
12    def _parse_args(self):
13        flags = self.parse_flags()
14        strict = flags["-s"]
15        if not self.args:
16            return "help", strict
17
18        return self.args[-1], strict
19
20    @cmd_register.display_in_help()
21    def extra_long_title_that_does_nothing(self):
22        """Bla bla bla"""
23        return
24
25    @cmd_register.display_in_help()
26    def reload(self, strict):
27        """Reloads plugins. --strict to raise error when failed to import"""
28
29        caller_frame = inspect.currentframe().f_back
30
31        while not getattr(caller_frame.f_locals["self"], "load_modules", None):
32            caller_frame = caller_frame.f_back
33
34        caller_obj = caller_frame.f_locals["self"]
35
36        self.logger.debug("Reloading plugins...")
37
38        caller_obj.load_modules(strict)
39
40        self.logger.debug("Done reloading plugins")
41
42    def execute(self):
43        action, strict = self._parse_args()
44
45        f = getattr(self, action, None)
46
47        if getattr(f, "__display_help__", False):
48            return f(strict)
49
50        msg = f"Unknown action: {action}"
51        return CommandOutput(stderr=msg, errcode=1)
@cmd_register.command('plugins', flags=['-s'])
class PluginsCommand(src.cmd_types.commands.ExecutableCommand):
11@cmd_register.command("plugins", flags=["-s"])
12class PluginsCommand(ExecutableCommand):
13    def _parse_args(self):
14        flags = self.parse_flags()
15        strict = flags["-s"]
16        if not self.args:
17            return "help", strict
18
19        return self.args[-1], strict
20
21    @cmd_register.display_in_help()
22    def extra_long_title_that_does_nothing(self):
23        """Bla bla bla"""
24        return
25
26    @cmd_register.display_in_help()
27    def reload(self, strict):
28        """Reloads plugins. --strict to raise error when failed to import"""
29
30        caller_frame = inspect.currentframe().f_back
31
32        while not getattr(caller_frame.f_locals["self"], "load_modules", None):
33            caller_frame = caller_frame.f_back
34
35        caller_obj = caller_frame.f_locals["self"]
36
37        self.logger.debug("Reloading plugins...")
38
39        caller_obj.load_modules(strict)
40
41        self.logger.debug("Done reloading plugins")
42
43    def execute(self):
44        action, strict = self._parse_args()
45
46        f = getattr(self, action, None)
47
48        if getattr(f, "__display_help__", False):
49            return f(strict)
50
51        msg = f"Unknown action: {action}"
52        return CommandOutput(stderr=msg, errcode=1)

Abstract class for executable commands(has no undo method)

Parameters
  • args: list of arguments passed to the command
@cmd_register.display_in_help()
def extra_long_title_that_does_nothing(self):
21    @cmd_register.display_in_help()
22    def extra_long_title_that_does_nothing(self):
23        """Bla bla bla"""
24        return

Bla bla bla

@cmd_register.display_in_help()
def reload(self, strict):
26    @cmd_register.display_in_help()
27    def reload(self, strict):
28        """Reloads plugins. --strict to raise error when failed to import"""
29
30        caller_frame = inspect.currentframe().f_back
31
32        while not getattr(caller_frame.f_locals["self"], "load_modules", None):
33            caller_frame = caller_frame.f_back
34
35        caller_obj = caller_frame.f_locals["self"]
36
37        self.logger.debug("Reloading plugins...")
38
39        caller_obj.load_modules(strict)
40
41        self.logger.debug("Done reloading plugins")

Reloads plugins. --strict to raise error when failed to import

def execute(self):
43    def execute(self):
44        action, strict = self._parse_args()
45
46        f = getattr(self, action, None)
47
48        if getattr(f, "__display_help__", False):
49            return f(strict)
50
51        msg = f"Unknown action: {action}"
52        return CommandOutput(stderr=msg, errcode=1)

Executes command

logger: logging.Logger = <Logger plugins (WARNING)>
name: str = 'plugins'

Name of the command

flags: list | None = ['-s']

Flags names to parse(with '-' in front)