add new config location to ~/.config/controldeck/controldeck.conf

This commit is contained in:
2021-04-03 21:18:20 +02:00
parent 0e23771ab1
commit ae0a8aa4f0
2 changed files with 13 additions and 4 deletions

View File

@@ -1,9 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
from os import path, sep, makedirs
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
from configparser import ConfigParser, DuplicateSectionError from configparser import ConfigParser, DuplicateSectionError
from re import search, IGNORECASE from re import search, IGNORECASE
from justpy import Div, WebPage, SetRoute, justpy from justpy import Div, WebPage, SetRoute, justpy
APP_NAME = "ControlDeck"
def process(args): def process(args):
try: try:
# with shell=True args can be a string # with shell=True args can be a string
@@ -67,7 +70,7 @@ class ButtonSound(Div):
@SetRoute('/') @SetRoute('/')
def application(): def application():
wp = WebPage(title="ControlDeck", body_classes="bg-gray-900") wp = WebPage(title=APP_NAME, body_classes="bg-gray-900")
wp.head_html = '<meta name="viewport" content="width=device-width, initial-scale=1">' wp.head_html = '<meta name="viewport" content="width=device-width, initial-scale=1">'
# div = Div(classes="flex flex-wrap", a=wp) # div = Div(classes="flex flex-wrap", a=wp)
@@ -76,13 +79,19 @@ def application():
# Button(text="Sleep", command='systemctl suspend', a=div2) # Button(text="Sleep", command='systemctl suspend', a=div2)
config = ConfigParser(strict=False) config = ConfigParser(strict=False)
volume_dict = {} config_file = "controldeck.conf"
button_dict = {} 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: try:
config.read('controldeck.conf') config.read(full_config_file_path)
except Exception as e: except Exception as e:
print(f"{e}") print(f"{e}")
#print(config.sections()) #print(config.sections())
volume_dict = {}
button_dict = {}
for i in config.sections(): for i in config.sections():
iname = None iname = None
iname = search("^([0-9]*.?)volume", i, flags=IGNORECASE) iname = search("^([0-9]*.?)volume", i, flags=IGNORECASE)