[core] Allow module loading from user directory
If a module fails to load from both core and contrib, fall back to loading by file name from "~/.config/bumblebee-status/modules/<name>.py" fixes #757
This commit is contained in:
parent
413abdcae7
commit
21ded8f640
2 changed files with 10 additions and 1 deletions
|
@ -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")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue