diff --git a/src/sakia/app.py b/src/sakia/app.py index eccbc7aee6094c23f0e5568e6ff0f71021bdfa4b..8636db9b5ea52c84ed17f06c2a0d49895f263268 100644 --- a/src/sakia/app.py +++ b/src/sakia/app.py @@ -97,7 +97,7 @@ class Application(QObject): :param profile_name: :return: """ - self.plugins_dir = PluginsDirectory.in_config_path(self.options.config_path, profile_name).load_or_init() + self.plugins_dir = PluginsDirectory.in_config_path(self.options.config_path, profile_name).load_or_init(self.options.with_plugin) self.parameters = UserParametersFile.in_config_path(self.options.config_path, profile_name).load_or_init() self.db = SakiaDatabase.load_or_init(self.options, profile_name) diff --git a/src/sakia/data/files/plugins.py b/src/sakia/data/files/plugins.py index 14ae702cc1ab289cd60fbec0ab117ba4de5d8474..62ab7b6d327108c2cb002d59cb0d64c070f96798 100644 --- a/src/sakia/data/files/plugins.py +++ b/src/sakia/data/files/plugins.py @@ -7,13 +7,14 @@ import importlib from ..entities import Plugin -@attr.s(frozen=True) +@attr.s() class PluginsDirectory: """ The repository for UserParameters """ _path = attr.ib() plugins = attr.ib(default=[]) + with_plugin = attr.ib(default=None) _logger = attr.ib(default=attr.Factory(lambda: logging.getLogger('sakia'))) @classmethod @@ -23,7 +24,7 @@ class PluginsDirectory: os.makedirs(plugins_path) return cls(plugins_path) - def load_or_init(self): + def load_or_init(self, with_plugin): """ Init plugins """ @@ -44,6 +45,19 @@ class PluginsDirectory: self.plugins.append(Plugin(module_name, "", "", False, None, file)) self._logger.debug(str(e) + " with sys.path " + str(sys.path)) + if with_plugin: + sys.path.append(with_plugin) + module_name = os.path.splitext(os.path.basename(with_plugin))[0] + try: + plugin_module = importlib.import_module(module_name) + self.with_plugin = Plugin(plugin_module.PLUGIN_NAME, + plugin_module.PLUGIN_DESCRIPTION, + plugin_module.PLUGIN_VERSION, + True, + plugin_module, + with_plugin) + except ImportError as e: + self._logger.debug(str(e) + " with sys.path " + str(sys.path)) except OSError as e: self._logger.debug(str(e)) return self diff --git a/src/sakia/gui/main_window/model.py b/src/sakia/gui/main_window/model.py index fa6f19a799bc5768961aeaf90280163e4cf36710..b2e8664132a621eb7e52f6af1374551ef5ad169e 100644 --- a/src/sakia/gui/main_window/model.py +++ b/src/sakia/gui/main_window/model.py @@ -11,6 +11,6 @@ class MainWindowModel(QObject): self.app = app def load_plugins(self, main_window): - for plugin in self.app.plugins_dir.plugins: + for plugin in self.app.plugins_dir.plugins + [self.app.plugins_dir.with_plugin]: if plugin.imported: plugin.module.plugin_exec(self.app, main_window) diff --git a/src/sakia/options.py b/src/sakia/options.py index e81306021568c2e25b96a06b8cb98086b318b518..20f881e5de7232c2cec31406ccc73eb31fbcc019 100644 --- a/src/sakia/options.py +++ b/src/sakia/options.py @@ -24,6 +24,7 @@ class SakiaOptions: config_path = attr.ib(default=attr.Factory(config_path_factory)) currency = attr.ib(default="gtest") profile = attr.ib(default="Default Profile") + with_plugin = attr.ib(default="") _logger = attr.ib(default=attr.Factory(lambda: logging.getLogger('sakia'))) @classmethod @@ -53,6 +54,9 @@ class SakiaOptions: parser.add_option("--profile", dest="profile", default="Default Profile", help="Select profile to use") + parser.add_option("--withplugin", dest="with_plugin", default="", + help="Load a plugin (for development purpose)") + (options, args) = parser.parse_args(argv) if options.currency not in ROOT_SERVERS.keys(): @@ -63,6 +67,12 @@ class SakiaOptions: if options.profile: self.profile = options.profile + if options.with_plugin: + if path.isfile(options.with_plugin) and options.with_plugin.endswith(".zip"): + self.with_plugin = options.with_plugin + else: + raise RuntimeError("{:} is not a valid path to a zip file".format(options.with_plugin)) + if options.debug: self._logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(levelname)s:%(module)s:%(funcName)s:%(message)s')