add cli with optional config path

This commit is contained in:
2021-04-13 13:34:57 +02:00
parent 7342721715
commit b8f26d6965
2 changed files with 32 additions and 10 deletions

View File

@@ -105,14 +105,17 @@ def source_volume_mute(name):
result = volume(name) result = volume(name)
return result return result
def config_load(): def config_load(conf=''):
config = ConfigParser(strict=False) config = ConfigParser(strict=False)
config_file = "controldeck.conf" if conf:
full_config_file_path = path.dirname(path.realpath(__file__)) + sep + config_file full_config_file_path = conf
if not path.exists(config_file): else:
config_folder = path.join(path.expanduser("~"), '.config', APP_NAME.lower()) config_file = "controldeck.conf"
makedirs(config_folder, exist_ok=True) full_config_file_path = path.dirname(path.realpath(__file__)) + sep + config_file
full_config_file_path = path.join(config_folder, 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(full_config_file_path) config.read(full_config_file_path)
except Exception as e: except Exception as e:

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import argparse
from webview import create_window, start from webview import create_window, start
import controldeck import controldeck
def main(): def main(conf=''):
if controldeck.process("ps -ef | grep -i controldeck | grep -v controldeck-gui | grep -v grep") == "": if controldeck.process("ps -ef | grep -i controldeck | grep -v controldeck-gui | grep -v grep") == "":
controldeck.process("controldeck &", output=False) controldeck.process("controldeck &", output=False)
config = controldeck.config_load() config = controldeck.config_load(conf=conf)
url = config.get('gui', 'url', fallback='http://0.0.0.0:8000') + "/?gui" url = config.get('gui', 'url', fallback='http://0.0.0.0:8000') + "/?gui"
try: try:
width = int(config.get('gui', 'width', fallback=800)) width = int(config.get('gui', 'width', fallback=800))
@@ -68,5 +69,23 @@ def main():
text_select=False) text_select=False)
start() start()
def cli():
parser = argparse.ArgumentParser(
description=__doc__, prefix_chars='-',
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument('-c', '--config', nargs='?', type=str, default='',
help="Specify a path to a custom config file (default: ~/.config/controldeck/controldeck.conf)")
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose output")
parser.add_argument('-D', '--debug', dest='debug', action='store_true', help=argparse.SUPPRESS)
args = parser.parse_args()
if args.debug:
print(args)
main(conf=args.config)
return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(cli())