def create_index_file(index_file_name, database_list): """ Write the index (list of records) for a given system to a disk file. :param index_file_name: index file name :type index_file_name: str :param database_list: list of databases for the given system :type database_list: list :return: """ record_name_list = [] for database_name in database_list: print(database_name) # Open database and macro substitution file (if any) db = DatabaseFile(file_name=database_name) m = read_subs_file(database_name) # Create a list with all records in the databases record_name_list.extend([r[0] for r in db.next_record_name()]) # print record_name_list # Substitute macros if the macro substitution file was defined. # There's no need to replace macros in the record fields since # only record names are written to the index files. if m is not None: record_name_list = [m.replace_macros(r) for r in record_name_list] # Write the index file f = open(index_file_name, 'w') f.write("\n".join(str(x.strip()) for x in record_name_list)) f.close()
def list_records(f, file_name, p_args): """ This is the callback function for process_file_list. It will get called once for each file in the input file list. List records in a database file. :param f: database file :param file_name: file name (not used) :param p_args: command line arguments :return: None """ if debug_flag: print('\n--list_records', f, file_name, p_args) df = DatabaseFile(f) for record_name, record_type in df.next_record_name(): if p_args.type: print(record_name + ', ' + record_type) else: print(record_name) df.close() return