def write_example_config(): garrick_dir, config_file_name = locate_config_file() default_print_info( 'Your config file is {}.'.format(os.path.join(garrick_dir, config_file_name)) ) default_print_info( 'I am writing a file called {}.example into the same directory.'.format(config_file_name) ) default_print_instruction( 'You can work from this file to restore your garrick.conf file to a valid state.' ) print() example_config_file = resource_filename(Requirement.parse('garrick'), 'garrick.conf.example') copyfile(example_config_file, os.path.join(garrick_dir, '{}.example'.format(config_file_name))) raise Exception('Invalid or incomplete config file.')
def get_config(): garrick_dir, config_file_name = locate_config_file() config_file = os.path.join(garrick_dir, config_file_name) config = configparser.ConfigParser(allow_no_value = True) try: config.read(config_file) except Exception as exception: print() default_print_error('Something is wrong with your config file.') default_print_error('ConfigParser has thrown the following exception:') print() print(exception) print() write_example_config() return config
def pick_db_file(): db_files = parse_db_files() garrick_dir, _ = locate_config_file() if len(db_files) == 1: db_file = db_files[0] else: for i in range(len(db_files)): print('{}. {}'.format(i + 1, db_files[i])) while True: selection = colored_prompt('Enter the number of the database file to use: ') if selection.isdigit() and int(selection) in range(1, len(db_files) + 1): db_number = int(selection) break db_file = db_files[db_number - 1] return os.path.join(garrick_dir, db_file)