def execute(cls, args): conffile = args.conffile # When no conffile is supplied, print usage and exit. if conffile is None: parser.parse_args([cls.key, '--help']) # if conffile is not file, print error message and exit. if not os.path.isfile(conffile): logger.error('File not found: `{}`'.format(conffile)) return try: # start reading file. with open(conffile, 'r') as f: simulators = [] for config in parse_config(f): simulators.append(Simulator(config)) except Exception as e: logger.error(e) return try: for simulator in simulators: simulator.run() except Exception as e: logger.error(e)
def execute(cls, args): target = args.target.lower() if target == 'all': # default case: print help of all commands. parser.print_help() return if target not in CommandPlugin.plugins: logger.error('Unkown command: `{}`'.format(target)) return parser.parse_args([args.target, '--help'])
def main(): # special case. When no argument is given print help. if len(sys.argv[1:]) == 0: parser.parse_args(['-h']) try: cp.scan() except Exception as e: logger.error("Unknown error: `{}`".format(e)) args = parser.parse_args(sys.argv[1:]) command = args.command.lower() try: cp.plugins[command].execute(args) except Exception: logger.error("Unknown command: `{}`".format(command))