From ae0a8aa4f0c50edffa3201318c9cc27e0f135f8d Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Sat, 3 Apr 2021 21:18:20 +0200 Subject: [PATCH] add new config location to ~/.config/controldeck/controldeck.conf --- controldeck.py | 17 +++++++++++++---- controldeck.conf => example/controldeck.conf | 0 2 files changed, 13 insertions(+), 4 deletions(-) rename controldeck.conf => example/controldeck.conf (100%) diff --git a/controldeck.py b/controldeck.py index 09ef675..4c3e4a8 100644 --- a/controldeck.py +++ b/controldeck.py @@ -1,9 +1,12 @@ #!/usr/bin/env python +from os import path, sep, makedirs from subprocess import Popen, PIPE, STDOUT from configparser import ConfigParser, DuplicateSectionError from re import search, IGNORECASE from justpy import Div, WebPage, SetRoute, justpy +APP_NAME = "ControlDeck" + def process(args): try: # with shell=True args can be a string @@ -67,7 +70,7 @@ class ButtonSound(Div): @SetRoute('/') def application(): - wp = WebPage(title="ControlDeck", body_classes="bg-gray-900") + wp = WebPage(title=APP_NAME, body_classes="bg-gray-900") wp.head_html = '' # div = Div(classes="flex flex-wrap", a=wp) @@ -76,13 +79,19 @@ def application(): # Button(text="Sleep", command='systemctl suspend', a=div2) config = ConfigParser(strict=False) - volume_dict = {} - button_dict = {} + config_file = "controldeck.conf" + full_config_file_path = path.dirname(path.realpath(__file__)) + sep + config_file + if not path.exists(config_file): + config_folder = path.join(path.expanduser("~"), '.config', APP_NAME.lower()) + makedirs(config_folder, exist_ok=True) + full_config_file_path = path.join(config_folder, config_file) try: - config.read('controldeck.conf') + config.read(full_config_file_path) except Exception as e: print(f"{e}") #print(config.sections()) + volume_dict = {} + button_dict = {} for i in config.sections(): iname = None iname = search("^([0-9]*.?)volume", i, flags=IGNORECASE) diff --git a/controldeck.conf b/example/controldeck.conf similarity index 100% rename from controldeck.conf rename to example/controldeck.conf