You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

#!/usr/bin/env python
from machlib.menu import Menu, get_data_from
import argparse
from configparser import ConfigParser, ExtendedInterpolation
import os
import os.path
import errno
# default configuration and menu files
_default_configuration_file = '~/.config/mach5/config.ini'
# -------------------- MAIN --------------------
# Parse command line options
arg_parser = argparse.ArgumentParser(
description='Our simple chords application')
arg_parser.add_argument('-c', '--cfg', help='Config ini file')
arg_parser.add_argument('-m', '--menu', help='Menu yaml file')
args = arg_parser.parse_args()
# load config file
cfg_file = args.cfg if args.cfg else _default_configuration_file
cfg_file = os.path.expanduser(cfg_file)
if not os.path.exists(cfg_file):
raise FileNotFoundError(errno.ENOENT,
os.strerror(errno.ENOENT), cfg_file)
_configuration = ConfigParser(interpolation=ExtendedInterpolation())
found = _configuration.read(cfg_file)
# [TODO] next lines should raise an error
if (not found):
print('[ERROR] Config file not found')
raise FileNotFoundError
menu_file = args.menu if args.menu\
else _configuration['General']['default_menu_file']
menu_file = os.path.expanduser(menu_file)
if not os.path.exists(menu_file):
raise FileNotFoundError(errno.ENOENT,
os.strerror(errno.ENOENT), menu_file)
Menu(get_data_from(menu_file)).get_command().execute()