def load(module_name, config=core.config.Config([]), theme=None):
    error = None
    module_short, alias = (module_name.split(":") + [module_name])[0:2]
    config.set("__alias__", alias)

    try:
        mod = importlib.import_module("modules.core.{}".format(module_short))
        log.debug("importing {} from core".format(module_short))
        return getattr(mod, "Module")(config, theme)
    except ImportError as e:
        try:
            log.warning("failed to import {} from core: {}".format(
                module_short, e))
            mod = importlib.import_module(
                "modules.contrib.{}".format(module_short))
            log.debug("importing {} from contrib".format(module_short))
            return getattr(mod, "Module")(config, theme)
        except ImportError as e:
            try:
                log.warning("failed to import {} from system: {}".format(
                    module_short, e))
                return import_user(module_short, config, theme)
            except ImportError as e:
                log.fatal("import failed: {}".format(e))
        log.fatal("failed to import {}".format(module_short))
    return Error(config=config,
                 module=module_name,
                 error="unable to load module")
Exemple #2
0
def load(module_name, config=core.config.Config([]), theme=None):
    error = None
    module_short, alias = (module_name.split(":") + [module_name])[0:2]
    config.set("__alias__", alias)
    for namespace in ["core", "contrib"]:
        try:
            mod = importlib.import_module("modules.{}.{}".format(
                namespace, module_short))
            log.debug("importing {} from {}.{}".format(module_short, namespace,
                                                       module_short))
            return getattr(mod, "Module")(config, theme)
        except ImportError as e:
            log.debug("failed to import {}: {}".format(module_name, e))
            error = e
    log.fatal("failed to import {}: {}".format(module_name, error))
    return Error(config=config, module=module_name, error=error)
Exemple #3
0
def load(module_name, config=core.config.Config([]), theme=None):
    error = None
    module_short, alias = (module_name.split(":") + [module_name])[0:2]
    config.set("__alias__", alias)

    try:
        mod = importlib.import_module("modules.core.{}".format(module_short))
        log.debug("importing {} from core".format(module_short))
        return getattr(mod, "Module")(config, theme)
    except ImportError as e:
        try:
            log.warning("failed to import {} from core: {}".format(
                module_short, e))
            mod = importlib.import_module(
                "modules.contrib.{}".format(module_short))
            log.debug("importing {} from contrib".format(module_short))
            return getattr(mod, "Module")(config, theme)
        except ImportError as e:
            usermod = os.path.expanduser(
                "~/.config/bumblebee-status/modules/{}.py".format(
                    module_short))
            if os.path.exists(usermod):
                try:
                    log.warning("failed to import {} from system: {}".format(
                        module_short, e))
                    mod = importlib.machinery.SourceFileLoader(
                        "modules.{}".format(module_short),
                        os.path.expanduser(usermod)).load_module()
                    log.debug("importing {} from user".format(module_short))
                    return getattr(mod, "Module")(config, theme)
                except ImportError as e:
                    log.fatal("import failed: {}".format(e))
        log.fatal("failed to import {}".format(module_short))
    return Error(config=config,
                 module=module_name,
                 error="unable to load module")
def build_module(percpu=False):
    config = core.config.Config(["-p", "percpu={}".format(percpu)])
    config.set("cpu.percpu", percpu)
    return modules.core.cpu.Module(config=config, theme=None)