From c09ce71fcec766357c6fcd7c4debfea9b7c43a1b Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 9 Sep 2019 20:17:03 +0200 Subject: [PATCH] [core] Replace aliases logic with simple dict Since aliases are so rarely used, just hardcode the list of aliases inside the engine for now. This combines the advantage of the speedup of the previous implementation with the robustness of the first implementation. As trade-off, extensibility suffers, but given the small number of aliases, that's OK for now. fixes #437 --- bumblebee/engine.py | 32 +++++++++------------------- bumblebee/modules/aliases/datetime | 2 -- bumblebee/modules/aliases/datetimetz | 2 -- bumblebee/modules/aliases/pulseaudio | 2 -- bumblebee/modules/aliases/test | 1 - 5 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 bumblebee/modules/aliases/datetime delete mode 100644 bumblebee/modules/aliases/datetimetz delete mode 100644 bumblebee/modules/aliases/pulseaudio delete mode 100644 bumblebee/modules/aliases/test diff --git a/bumblebee/engine.py b/bumblebee/engine.py index fa54899..600945e 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -142,7 +142,7 @@ class Engine(object): self._running = True self._modules = [] self.input = inp - self._aliases = self._read_aliases() + self._aliases = self._aliases() self.load_modules(config.modules()) self._current_module = None self._theme = theme @@ -230,27 +230,15 @@ class Engine(object): self.input.register_callback(obj=module, button=button["id"], cmd=module.parameter(button["name"])) - def _read_aliases(self): - """Retruns a dictionary that maps every alias to its real module name""" - result = {} - m_path = os.path.abspath(bumblebee.modules.__file__) - m_path = os.path.dirname(m_path) - ALIASES_PATH = m_path + "/aliases/" - for name in os.listdir(ALIASES_PATH): - try: - # listdir does not retur full paths - f_path = ALIASES_PATH + name - # skip any directory - if not os.path.isfile(f_path): continue - with open(f_path) as f: - for alias in f.readlines(): - alias = alias.strip() - # skip empty lines - if len(alias) == 0: continue - result[alias] = name - except Exception as error: - log.warning("failed to load aliases of {}: {}".format(name, str(error))) - return result + def _aliases(self): + return { + 'date': 'datetime', + 'time': 'datetime', + 'datetz': 'datetimetz', + 'timetz': 'datetimetz', + 'pasink': 'pulseaudio', + 'pasource': 'pulseaudio', + } def _load_module(self, module_name, config_name=None): """Load specified module and return it as object""" diff --git a/bumblebee/modules/aliases/datetime b/bumblebee/modules/aliases/datetime deleted file mode 100644 index 8e43d6a..0000000 --- a/bumblebee/modules/aliases/datetime +++ /dev/null @@ -1,2 +0,0 @@ -date -time diff --git a/bumblebee/modules/aliases/datetimetz b/bumblebee/modules/aliases/datetimetz deleted file mode 100644 index 08f6d17..0000000 --- a/bumblebee/modules/aliases/datetimetz +++ /dev/null @@ -1,2 +0,0 @@ -datetz -timetz diff --git a/bumblebee/modules/aliases/pulseaudio b/bumblebee/modules/aliases/pulseaudio deleted file mode 100644 index 9bcee50..0000000 --- a/bumblebee/modules/aliases/pulseaudio +++ /dev/null @@ -1,2 +0,0 @@ -pasink -pasource diff --git a/bumblebee/modules/aliases/test b/bumblebee/modules/aliases/test deleted file mode 100644 index dc52a4f..0000000 --- a/bumblebee/modules/aliases/test +++ /dev/null @@ -1 +0,0 @@ -test-alias