diff --git a/web-greeter/globals.py b/web-greeter/globals.py index eb2fa02..b9b9ee7 100644 --- a/web-greeter/globals.py +++ b/web-greeter/globals.py @@ -59,6 +59,8 @@ from PyQt5.QtWidgets import QMainWindow from PyQt5.QtGui import QColor import subprocess +from utils import theme + # Typing Helpers BridgeObj = Type[BridgeObject] @@ -173,6 +175,7 @@ class WebGreeter(App): def load_theme(self): self.logger.debug('Loading theme...') + theme.checkTheme(self) theme_url = '/{0}/{1}/index.html'.format(self.config.themes_dir, self.config.greeter.theme) self._web_container.load(theme_url) diff --git a/web-greeter/utils/theme.py b/web-greeter/utils/theme.py index 128d3f6..d1636bf 100644 --- a/web-greeter/utils/theme.py +++ b/web-greeter/utils/theme.py @@ -33,6 +33,49 @@ import os # This Application from .pkg_json import PackageJSON +from logging import ( + getLogger, + DEBUG, + Formatter, + StreamHandler, +) + +log_format = ''.join([ + '%(asctime)s [ %(levelname)s ] %(filename)s %(', + 'lineno)d: %(message)s' +]) +formatter = Formatter(fmt=log_format, datefmt="%Y-%m-%d %H:%M:%S") +logger = getLogger("theme") +logger.propagate = False +stream_handler = StreamHandler() +stream_handler.setLevel(DEBUG) +stream_handler.setFormatter(formatter) +logger.setLevel(DEBUG) +logger.addHandler(stream_handler) + +def checkTheme(self): + themes = listThemes(self) + config_theme = self.config.greeter.theme + default = "gruvbox" + if self.config.greeter.theme in themes: + pass + else: + logger.error("Config theme not valid: \"{0}\". Going with \"{1}\" theme".format(config_theme, default)) + self.config.greeter.theme = default + + +def listThemes(self): + themes_dir = self.config.themes_dir + themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes" + filenames = os.listdir(themes_dir) + + dirlist = [] + for file in filenames: + if os.path.isdir(os.path.join(themes_dir, file)): + dirlist.append(file) + + return dirlist + class Theme: """