Starta på innganspunktet for programmet, lagde en init funksjon

This commit is contained in:
Trygve 2023-11-17 21:52:44 +01:00
parent de4f288a4a
commit 3894eb7284

36
otime/main.py Normal file
View File

@ -0,0 +1,36 @@
import argparse
import file_io
import iof_xml
# Main entrypoint for now. Cli with two options; init will make the files needed and run will start the program from the specified directory
def main():
parser = argparse.ArgumentParser(description='Otime very alpha version 😁')
subparsers = parser.add_subparsers(dest='command')
parser_init = subparsers.add_parser('init', help='INIT')
parser_init.add_argument('--entries', required=True, dest='entries_file', action='store', default='./',
help='The xml file with entries')
parser_init.add_argument('--courses', required=True, dest='courses_file', action='store', default='./',
help='The xml with courses')
parser_init.add_argument('--dir', required=False, dest='dir', action='store', default='./',
help='Specify a directort, if not set the files are created in the current directory')
args = parser.parse_args()
if args.command == 'init':
init_dir(args.dir, args.entries_file, args.courses_file)
def init_dir(project_dir, entries_xml_file, courses_xml_file):
# Lager mappe med en config fil, en csv fil med løpere og en fil med mtr data
csv_db_path = project_dir + '/runners.csv'
config_path = project_dir + '/config.yaml'
mtr_path = project_dir + 'mtr.yaml'
event = iof_xml.event_from_xml_entries(entries_xml_file)
event.courses = iof_xml.courses_from_xml(courses_xml_file)
file_io.write_runners_csv(event, csv_db_path)
file_io.write_config(event, config_path)
file_io.write_card_dumps(event, mtr_path)
if __name__ == '__main__':
main()