From 333d8ccdf052f6bb720d80cb18489d2aea3d5712 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 3 Mar 2023 21:20:53 -0600 Subject: [PATCH] Added failover if core configs not present --- src/core/controller_data.py | 8 ++++---- src/utils/settings/settings.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/controller_data.py b/src/core/controller_data.py index d37cbe5..2e59e1a 100644 --- a/src/core/controller_data.py +++ b/src/core/controller_data.py @@ -52,14 +52,14 @@ class ControllerData: for child in widget.get_children(): widget.remove(child) - def get_clipboard_data(self) -> str: + def get_clipboard_data(self, encoding="utf-8") -> str: proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE) retcode = proc.wait() data = proc.stdout.read() - return data.decode("utf-8").strip() + return data.decode(encoding).strip() - def set_clipboard_data(self, data: type) -> None: + def set_clipboard_data(self, data: type, encoding="utf-8") -> None: proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE) - proc.stdin.write(data.encode("utf-8")) + proc.stdin.write(data.encode(encoding)) proc.stdin.close() retcode = proc.wait() diff --git a/src/utils/settings/settings.py b/src/utils/settings/settings.py index 00347de..b2bfb86 100644 --- a/src/utils/settings/settings.py +++ b/src/utils/settings/settings.py @@ -9,6 +9,10 @@ import inspect from .start_check_mixin import StartCheckMixin +class MissingConfigError(Exception): + pass + + class Settings(StartCheckMixin): def __init__(self): @@ -41,14 +45,24 @@ class Settings(StartCheckMixin): if not os.path.exists(self._DEFAULT_ICONS): self.DEFAULT_ICONS = f"{self._USR_PATH}/icons" + if not os.path.exists(self._DEFAULT_ICONS): + raise MissingConfigError("Unable to find the application icons directory.") if not os.path.exists(self._GLADE_FILE): self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade" + if not os.path.exists(self._GLADE_FILE): + raise MissingConfigError("Unable to find the application Glade file.") if not os.path.exists(self._KEY_BINDINGS_FILE): self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json" + if not os.path.exists(self._KEY_BINDINGS_FILE): + raise MissingConfigError("Unable to find the application Keybindings file.") if not os.path.exists(self._CSS_FILE): self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css" + if not os.path.exists(self._CSS_FILE): + raise MissingConfigError("Unable to find the application Stylesheet file.") if not os.path.exists(self._WINDOW_ICON): self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png" + if not os.path.exists(self._WINDOW_ICON): + raise MissingConfigError("Unable to find the application icon.") with open(self._KEY_BINDINGS_FILE) as file: