[docs]defhermes_simulation(args:List[str]|None=None)->None:"""HermesPy Command Line Interface. Default entry point to execute hermespy `.yml` files via terminals. Args: args ([List[str], optional): Command line arguments. By default, the system argument vector will be interpreted. """# Recover command line arguments from system if none are providedargs=sys.argv[1:]ifargsisNoneelseargsparser=argparse.ArgumentParser(description="HermesPy - The Heterogeneous Mobile Radio Simulator",prog="hermes")parser.add_argument("-o",help="output directory to which results will be dumped",type=str)parser.add_argument("-s",help="style of result plots",type=str)parser.add_argument("-t","--test",action="store_true",help="run in test-mode, does not dump results")parser.add_argument("-l","--log",action="store_true",help="log the console information to a txt file")parser.add_argument("config",help="parameters source file from which to read the simulation configuration",type=str,)arguments=parser.parse_args(args)# Create consoleconsole=Console(record=arguments.log)console.show_cursor(False)# Draw welcome headerconsole.print("\n[bold green]Welcome to HermesPy - The Heterogeneous Radio Mobile Simulator\n")console.print(f"Version: {__version__}")console.print(f"Maintainer: {__maintainer__}")console.print(f"Contact: {__email__}")console.print("\nFor detailed instructions, refer to the documentation https://hermespy.org/")console.print("Please report any bugs to https://github.com/Barkhausen-Institut/hermespy/issues\n")console.print(f"Configuration will be read from '{arguments.config}'")withconsole.status("Initializing Environment...",spinner="dots"):################### Import executable from YAML config dumpfactory=Factory()try:# Load serializable objects from configuration filesserializables:Sequence[Serializable]=factory.from_path(arguments.config)# Filter out non-executables from the serialization listexecutables:Sequence[Executable]=[sforsinserializablesifisinstance(s,Executable)]# Abort execution if no executable was foundiflen(executables)<1:console.log("No executable routine was detected, aborting execution",style="red")sys.exit(-1)# For now, only single executables are supportedexecutable=executables[0]executable.results_dir=(Executable.default_results_dir()ifarguments.oisNoneelsearguments.o)exceptConstructorErroraserror:console.log(f"YAML import failed during parsing of line {error.problem_mark.line} in file '{error.problem_mark.name}':\n\t{error.problem}",style="red",)sys.exit(-1)# Configure consoleexecutable.console=console# Configure styleifarguments.sisnotNone:executable.style=arguments.s# Inform about the results directoryconsole.print(f"Results will be saved in '{executable.results_dir}'")# Dump current configuration to results directoryifnotarguments.test:shutil.copy(arguments.config,executable.results_dir)################### run simulationexecutable.execute()############ Goodbye :)console.print("Configuration executed. Goodbye.")# Save logifarguments.log:console.save_text(os.path.join(executable.results_dir,"log.txt"))
if__name__=="__main__":# pragma: no cover# Run hermespy default entry pointhermes_simulation()