From dcc42036e810bfa8fadb603157a213961416a61c Mon Sep 17 00:00:00 2001 From: nginsburg Date: Tue, 4 Feb 2020 19:06:26 -0500 Subject: [PATCH] using pkg_resources --- .gitignore | 1 + bumblebee/theme.py | 44 +++++++++---------- {themes => bumblebee/themes}/default.json | 0 .../themes}/dracula-powerline.json | 0 .../themes}/firefox-dark-powerline.json | 0 .../themes}/greyish-powerline.json | 0 .../themes}/gruvbox-light.json | 0 .../themes}/gruvbox-powerline-light.json | 0 .../themes}/gruvbox-powerline.json | 0 {themes => bumblebee/themes}/gruvbox.json | 0 .../themes}/iceberg-dark-powerline.json | 0 .../themes}/iceberg-powerline.json | 0 .../themes}/iceberg-rainbow.json | 0 {themes => bumblebee/themes}/iceberg.json | 0 {themes => bumblebee/themes}/icons/ascii.json | 0 .../themes}/icons/awesome-fonts.json | 0 .../themes}/icons/ionicons.json | 0 .../themes}/icons/paxy97.json | 0 {themes => bumblebee/themes}/icons/test.json | 0 .../themes}/onedark-powerline.json | 0 {themes => bumblebee/themes}/powerline.json | 0 {themes => bumblebee/themes}/sac_red.json | 0 .../themes}/solarized-dark-awesome.json | 0 .../themes}/solarized-powerline.json | 0 {themes => bumblebee/themes}/solarized.json | 0 {themes => bumblebee/themes}/test.json | 0 {themes => bumblebee/themes}/test_cycle.json | 0 .../themes}/test_invalid.json | 0 .../themes}/wal-powerline.json | 0 themes | 1 + 30 files changed, 24 insertions(+), 22 deletions(-) rename {themes => bumblebee/themes}/default.json (100%) rename {themes => bumblebee/themes}/dracula-powerline.json (100%) rename {themes => bumblebee/themes}/firefox-dark-powerline.json (100%) rename {themes => bumblebee/themes}/greyish-powerline.json (100%) rename {themes => bumblebee/themes}/gruvbox-light.json (100%) rename {themes => bumblebee/themes}/gruvbox-powerline-light.json (100%) rename {themes => bumblebee/themes}/gruvbox-powerline.json (100%) rename {themes => bumblebee/themes}/gruvbox.json (100%) rename {themes => bumblebee/themes}/iceberg-dark-powerline.json (100%) rename {themes => bumblebee/themes}/iceberg-powerline.json (100%) rename {themes => bumblebee/themes}/iceberg-rainbow.json (100%) rename {themes => bumblebee/themes}/iceberg.json (100%) rename {themes => bumblebee/themes}/icons/ascii.json (100%) rename {themes => bumblebee/themes}/icons/awesome-fonts.json (100%) rename {themes => bumblebee/themes}/icons/ionicons.json (100%) rename {themes => bumblebee/themes}/icons/paxy97.json (100%) rename {themes => bumblebee/themes}/icons/test.json (100%) rename {themes => bumblebee/themes}/onedark-powerline.json (100%) rename {themes => bumblebee/themes}/powerline.json (100%) rename {themes => bumblebee/themes}/sac_red.json (100%) rename {themes => bumblebee/themes}/solarized-dark-awesome.json (100%) rename {themes => bumblebee/themes}/solarized-powerline.json (100%) rename {themes => bumblebee/themes}/solarized.json (100%) rename {themes => bumblebee/themes}/test.json (100%) rename {themes => bumblebee/themes}/test_cycle.json (100%) rename {themes => bumblebee/themes}/test_invalid.json (100%) rename {themes => bumblebee/themes}/wal-powerline.json (100%) create mode 120000 themes diff --git a/.gitignore b/.gitignore index 724c296..4996eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ var/ *.egg-info/ .installed.cfg *.egg +build/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 9b09231..50e0c19 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -9,31 +9,30 @@ import json import io import re import logging - -try: - import requests - from requests.exceptions import RequestException -except ImportError: - pass +import pkg_resources import bumblebee.error def theme_path(): """Return the path of the theme directory""" return [ - os.path.dirname("{}/../themes/".format(os.path.dirname(os.path.realpath(__file__)))), - os.path.dirname("{}/../../../../share/bumblebee-status/themes/".format(os.path.dirname(os.path.realpath(__file__)))), - os.path.dirname(os.path.expanduser("~/.config/bumblebee-status/themes/")), + os.path.realpath(x) for x in [ + os.path.dirname("{}/../themes/".format(os.path.dirname(os.path.realpath(__file__)))), + os.path.dirname( + "{}/../../../../share/bumblebee-status/themes/".format( + os.path.dirname(os.path.realpath(__file__)))), + os.path.dirname(os.path.expanduser("~/.config/bumblebee-status/themes/")), + pkg_resources.resource_filename('bumblebee', 'themes')] if os.path.exists(x) ] def themes(): - themes = {} + themes_dict = {} for path in theme_path(): for filename in glob.iglob("{}/*.json".format(path)): if "test" not in filename: - themes[os.path.basename(filename).replace(".json", "")] = 1 - result = list(themes.keys()) + themes_dict[os.path.basename(filename).replace(".json", "")] = 1 + result = list(themes_dict.keys()) result.sort() return result @@ -59,7 +58,7 @@ class Theme(object): path = os.path.expanduser("~/.config/bumblebee-status/") try: os.makedirs(path) - except Exception: + except OSError: pass try: if os.path.exists("{}/symbols.json".format(path)): @@ -73,8 +72,8 @@ class Theme(object): code = chr(code) self._symbols["${{{}}}".format(icon["id"])] = code self._symbols["${{{}}}".format(icon["name"])] = code - except Exception as e: - logging.error("failed to load symbols: {}".format(str(e))) + except Exception as err: + logging.error("failed to load symbols: %s", err) def _init(self, data): """Initialize theme from data structure""" @@ -96,7 +95,7 @@ class Theme(object): def reset(self): """Reset theme to initial state""" - self._cycle = self._cycles[0] if len(self._cycles) > 0 else {} + self._cycle = self._cycles[0] if self._cycles else {} self._cycle_idx = 0 self._widget = None self._prevbg = None @@ -105,6 +104,7 @@ class Theme(object): icon = self._get(widget, "icon", None) if icon is None: return self._get(widget, "prefix", None) + return None def get(self, widget, attribute, default_value=""): return self._get(widget, attribute, default_value) @@ -189,10 +189,10 @@ class Theme(object): def _load_colors(self, name): """Load colors for a theme""" try: - if name == "wal": + if name.lower() == "wal": return self._load_wal_colors() - except Exception as e: - logging.error("failed to load colors: {}".format(str(e))) + except Exception as err: + logging.error("failed to load colors: %s", err) def _load_icons(self, name): """Load icons for a theme""" @@ -217,7 +217,7 @@ class Theme(object): if os.path.isfile(full_name): path = os.path.dirname(full_name) name = os.path.basename(full_name) - name,_,_ = name.rpartition(".json") + name, _, _ = name.rpartition(".json") return self.load(name, path) if not isinstance(path, list): @@ -249,7 +249,7 @@ class Theme(object): if self._widget != widget: self._prevbg = self.bg(self._widget) self._widget = widget - if len(self._cycles) > 0: + if self._cycles: self._cycle_idx = (self._cycle_idx + 1) % len(self._cycles) self._cycle = self._cycles[self._cycle_idx] @@ -283,7 +283,7 @@ class Theme(object): if mod and not mod.parameter("is-unittest"): value = widget.get_module().parameter("theme.{}".format(name), value) - if isinstance(value, list) or isinstance(value, dict): + if isinstance(value, (dict, list)): return value return self._colorset.get(value, value) diff --git a/themes/default.json b/bumblebee/themes/default.json similarity index 100% rename from themes/default.json rename to bumblebee/themes/default.json diff --git a/themes/dracula-powerline.json b/bumblebee/themes/dracula-powerline.json similarity index 100% rename from themes/dracula-powerline.json rename to bumblebee/themes/dracula-powerline.json diff --git a/themes/firefox-dark-powerline.json b/bumblebee/themes/firefox-dark-powerline.json similarity index 100% rename from themes/firefox-dark-powerline.json rename to bumblebee/themes/firefox-dark-powerline.json diff --git a/themes/greyish-powerline.json b/bumblebee/themes/greyish-powerline.json similarity index 100% rename from themes/greyish-powerline.json rename to bumblebee/themes/greyish-powerline.json diff --git a/themes/gruvbox-light.json b/bumblebee/themes/gruvbox-light.json similarity index 100% rename from themes/gruvbox-light.json rename to bumblebee/themes/gruvbox-light.json diff --git a/themes/gruvbox-powerline-light.json b/bumblebee/themes/gruvbox-powerline-light.json similarity index 100% rename from themes/gruvbox-powerline-light.json rename to bumblebee/themes/gruvbox-powerline-light.json diff --git a/themes/gruvbox-powerline.json b/bumblebee/themes/gruvbox-powerline.json similarity index 100% rename from themes/gruvbox-powerline.json rename to bumblebee/themes/gruvbox-powerline.json diff --git a/themes/gruvbox.json b/bumblebee/themes/gruvbox.json similarity index 100% rename from themes/gruvbox.json rename to bumblebee/themes/gruvbox.json diff --git a/themes/iceberg-dark-powerline.json b/bumblebee/themes/iceberg-dark-powerline.json similarity index 100% rename from themes/iceberg-dark-powerline.json rename to bumblebee/themes/iceberg-dark-powerline.json diff --git a/themes/iceberg-powerline.json b/bumblebee/themes/iceberg-powerline.json similarity index 100% rename from themes/iceberg-powerline.json rename to bumblebee/themes/iceberg-powerline.json diff --git a/themes/iceberg-rainbow.json b/bumblebee/themes/iceberg-rainbow.json similarity index 100% rename from themes/iceberg-rainbow.json rename to bumblebee/themes/iceberg-rainbow.json diff --git a/themes/iceberg.json b/bumblebee/themes/iceberg.json similarity index 100% rename from themes/iceberg.json rename to bumblebee/themes/iceberg.json diff --git a/themes/icons/ascii.json b/bumblebee/themes/icons/ascii.json similarity index 100% rename from themes/icons/ascii.json rename to bumblebee/themes/icons/ascii.json diff --git a/themes/icons/awesome-fonts.json b/bumblebee/themes/icons/awesome-fonts.json similarity index 100% rename from themes/icons/awesome-fonts.json rename to bumblebee/themes/icons/awesome-fonts.json diff --git a/themes/icons/ionicons.json b/bumblebee/themes/icons/ionicons.json similarity index 100% rename from themes/icons/ionicons.json rename to bumblebee/themes/icons/ionicons.json diff --git a/themes/icons/paxy97.json b/bumblebee/themes/icons/paxy97.json similarity index 100% rename from themes/icons/paxy97.json rename to bumblebee/themes/icons/paxy97.json diff --git a/themes/icons/test.json b/bumblebee/themes/icons/test.json similarity index 100% rename from themes/icons/test.json rename to bumblebee/themes/icons/test.json diff --git a/themes/onedark-powerline.json b/bumblebee/themes/onedark-powerline.json similarity index 100% rename from themes/onedark-powerline.json rename to bumblebee/themes/onedark-powerline.json diff --git a/themes/powerline.json b/bumblebee/themes/powerline.json similarity index 100% rename from themes/powerline.json rename to bumblebee/themes/powerline.json diff --git a/themes/sac_red.json b/bumblebee/themes/sac_red.json similarity index 100% rename from themes/sac_red.json rename to bumblebee/themes/sac_red.json diff --git a/themes/solarized-dark-awesome.json b/bumblebee/themes/solarized-dark-awesome.json similarity index 100% rename from themes/solarized-dark-awesome.json rename to bumblebee/themes/solarized-dark-awesome.json diff --git a/themes/solarized-powerline.json b/bumblebee/themes/solarized-powerline.json similarity index 100% rename from themes/solarized-powerline.json rename to bumblebee/themes/solarized-powerline.json diff --git a/themes/solarized.json b/bumblebee/themes/solarized.json similarity index 100% rename from themes/solarized.json rename to bumblebee/themes/solarized.json diff --git a/themes/test.json b/bumblebee/themes/test.json similarity index 100% rename from themes/test.json rename to bumblebee/themes/test.json diff --git a/themes/test_cycle.json b/bumblebee/themes/test_cycle.json similarity index 100% rename from themes/test_cycle.json rename to bumblebee/themes/test_cycle.json diff --git a/themes/test_invalid.json b/bumblebee/themes/test_invalid.json similarity index 100% rename from themes/test_invalid.json rename to bumblebee/themes/test_invalid.json diff --git a/themes/wal-powerline.json b/bumblebee/themes/wal-powerline.json similarity index 100% rename from themes/wal-powerline.json rename to bumblebee/themes/wal-powerline.json diff --git a/themes b/themes new file mode 120000 index 0000000..fe07097 --- /dev/null +++ b/themes @@ -0,0 +1 @@ +bumblebee/themes/ \ No newline at end of file