Added failover if core configs not present

This commit is contained in:
itdominator 2023-03-03 21:20:53 -06:00
parent 596608642f
commit 333d8ccdf0
2 changed files with 18 additions and 4 deletions

View File

@ -52,14 +52,14 @@ class ControllerData:
for child in widget.get_children(): for child in widget.get_children():
widget.remove(child) 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) proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
retcode = proc.wait() retcode = proc.wait()
data = proc.stdout.read() 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 = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
proc.stdin.write(data.encode("utf-8")) proc.stdin.write(data.encode(encoding))
proc.stdin.close() proc.stdin.close()
retcode = proc.wait() retcode = proc.wait()

View File

@ -9,6 +9,10 @@ import inspect
from .start_check_mixin import StartCheckMixin from .start_check_mixin import StartCheckMixin
class MissingConfigError(Exception):
pass
class Settings(StartCheckMixin): class Settings(StartCheckMixin):
def __init__(self): def __init__(self):
@ -41,14 +45,24 @@ class Settings(StartCheckMixin):
if not os.path.exists(self._DEFAULT_ICONS): if not os.path.exists(self._DEFAULT_ICONS):
self.DEFAULT_ICONS = f"{self._USR_PATH}/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): if not os.path.exists(self._GLADE_FILE):
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade" 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): if not os.path.exists(self._KEY_BINDINGS_FILE):
self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json" 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): if not os.path.exists(self._CSS_FILE):
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css" 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): if not os.path.exists(self._WINDOW_ICON):
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png" 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: with open(self._KEY_BINDINGS_FILE) as file: