diff --git a/.codeclimate.yml b/.codeclimate.yml index 928f344..ec80874 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,10 +1,6 @@ engines: duplication: enabled: true - exclude_fingerprints: - - 729e672cc5eafa97b4ff7b4487b43e73 - - b6bcd0bad16e901a7e93b31776477fde - - 39aa354fb2009c102f8b297a4eade693 config: languages: - python diff --git a/bumblebee/engine.py b/bumblebee/engine.py index 5c8d848..4645cf8 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -26,11 +26,9 @@ class Module(object): this base class. """ def __init__(self, engine, config={}, widgets=[]): - self.name = self.__module__.split(".")[-1] + self.name = config.get("name", self.__module__.split(".")[-1]) self._config = config - if "name" not in self._config: - self._config["name"] = self.name - self.id = self._config["name"] + self.id = self.name self._widgets = [] if widgets: self._widgets = widgets if isinstance(widgets, list) else [widgets] @@ -50,7 +48,7 @@ class Module(object): def parameter(self, name, default=None): """Return the config parameter 'name' for this module""" - name = "{}.{}".format(self._config["name"], name) + name = "{}.{}".format(self.name, name) return self._config["config"].get(name, default) class Engine(object): @@ -65,6 +63,7 @@ class Engine(object): self._running = True self._modules = [] self.input = inp + self._aliases = self._read_aliases() self.load_modules(config.modules()) self.input.register_callback(None, bumblebee.input.WHEEL_UP, @@ -80,8 +79,19 @@ class Engine(object): self._modules.append(self._load_module(module["module"], module["name"])) return self._modules + def _read_aliases(self): + result = {} + for module in all_modules(): + mod = importlib.import_module("bumblebee.modules.{}".format(module["name"])) + for alias in getattr(mod, "ALIASES", []): + result[alias] = module["name"] + return result + def _load_module(self, module_name, config_name=None): """Load specified module and return it as object""" + if module_name in self._aliases: + config_name is config_name if config_name else module_name + module_name = self._aliases[module_name] if config_name is None: config_name = module_name try: diff --git a/bumblebee/modules/date.py b/bumblebee/modules/date.py deleted file mode 120000 index bde6404..0000000 --- a/bumblebee/modules/date.py +++ /dev/null @@ -1 +0,0 @@ -datetime.py \ No newline at end of file diff --git a/bumblebee/modules/datetime.py b/bumblebee/modules/datetime.py index 2ee074b..6d6b594 100644 --- a/bumblebee/modules/datetime.py +++ b/bumblebee/modules/datetime.py @@ -12,6 +12,8 @@ from __future__ import absolute_import import datetime import bumblebee.engine +ALIASES = [ "date", "time" ] + def default_format(module): default = "%x %X" if module == "date": @@ -25,8 +27,7 @@ class Module(bumblebee.engine.Module): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.get_time) ) - module = self.__module__.split(".")[-1] - self._fmt = self.parameter("format", default_format(module)) + self._fmt = self.parameter("format", default_format(self.name)) def get_time(self): return datetime.datetime.now().strftime(self._fmt) diff --git a/bumblebee/modules/time.py b/bumblebee/modules/time.py deleted file mode 120000 index bde6404..0000000 --- a/bumblebee/modules/time.py +++ /dev/null @@ -1 +0,0 @@ -datetime.py \ No newline at end of file