diff --git a/bumblebee_status/core/module.py b/bumblebee_status/core/module.py index dad06e2..145d16d 100644 --- a/bumblebee_status/core/module.py +++ b/bumblebee_status/core/module.py @@ -17,6 +17,7 @@ except Exception as e: log = logging.getLogger(__name__) +import sys """Loads a module by name @@ -45,7 +46,14 @@ def load(module_name, config=core.config.Config([]), theme=None): log.debug("importing {} from contrib".format(module_short)) return getattr(mod, "Module")(config, theme) except ImportError as e: - log.fatal("failed to import {} from contrib: {}".format(module_short, e)) + try: + log.warning("failed to import {} from system: {}".format(module_short, e)) + mod = importlib.machinery.SourceFileLoader("modules.{}".format(module_short), + os.path.expanduser("~/.config/bumblebee-status/modules/{}.py".format(module_short))).load_module() + log.debug("importing {} from user".format(module_short)) + return getattr(mod, "Module")(config, theme) + except ImportError as e: + log.fatal("failed to import {}: {}".format(module_short, e)) return Error(config=config, module=module_name, error="unable to load module") diff --git a/docs/development/module.rst b/docs/development/module.rst index 113a6f7..cc71900 100644 --- a/docs/development/module.rst +++ b/docs/development/module.rst @@ -11,6 +11,7 @@ Adding a new module to ``bumblebee-status`` is straight-forward: ``bumblebee-status`` (i.e. a module called ``bumblebee_status/modules/contrib/test.py`` will be loaded using ``bumblebee-status -m test``) +- Alternatively, you can put your module in ``~/.config/bumblebee-status/modules/`` - The module name must follow the `Python Naming Conventions `_ - See below for how to actually write the module - Test (run ``bumblebee-status`` in the CLI)