def main(): parser = ArgumentParser() main = parser.add_argument_group('main') main.add_argument('file', type=str, help='file path to save the exported routes to') main.add_argument('--epsg', dest='epsg', type=int, default=2223, help='epsg system to convert routes to; default is 2223') common = parser.add_argument_group('common') common.add_argument( '--folder', type=str, dest='folder', default='.', help='file path to the directory containing Icarus run data' '; default is the working directory') common.add_argument( '--log', type=str, dest='log', default=None, help= 'file path to save the process log; by default the log is not saved') common.add_argument( '--level', type=str, dest='level', default='info', help='verbosity level of the process log; default is "info"', choices=('notset', 'debug', 'info', 'warning', 'error', 'critical')) common.add_argument( '--replace', dest='replace', action='store_true', default=False, help='automatically replace existing data; do not prompt the user') args = parser.parse_args() handlers = [] handlers.append(log.StreamHandler()) if args.log is not None: handlers.append(log.FileHandler(args.log, 'w')) log.basicConfig( format='%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(message)s', level=getattr(log, args.level.upper()), handlers=handlers) path = lambda x: os.path.abspath(os.path.join(args.folder, x)) home = path('') log.info('Running link export tool.') log.info(f'Loading run data from {home}.') database = SqliteUtil(path('database.db'), readonly=True) try: export_links(database, args.file, 2223, args.epsg) except: log.exception('Critical error while exporting routes:') exit(1) database.close()
conditions = config['simulation']['sample'] planspath = path('input/plans.xml.gz') vehiclespath = path('input/vehicles.xml.gz') log.info('Running population generation tool.') log.info(f'Loading run data from {home}.') database = SqliteUtil(path('database.db')) plans = Plans(database) if not plans.ready(): log.warning('Dependent data not parsed or generated.') log.warning('Input plans depend on population generation.') exit(1) elif plans.complete(planspath, vehiclespath): log.warning( 'Input plans already generated. Would you like to replace it? [Y/n]') if input().lower() not in ('y', 'yes', 'yeet'): log.info('User chose to keep existing plan; exiting generation tool.') exit() try: log.info('Starting population generation.') plans.generate(planspath, vehiclespath, modes, **conditions) except: log.exception('Critical error while generating input plans; ' 'terminating process and exiting.') exit(1) database.close()