def main(): e = Environment() e.load() conf = configure() try: current_command = sys.argv[1] except IndexError: current_command = None parser = argparse.ArgumentParser(prog='ino', formatter_class=FlexiFormatter, description=__doc__) subparsers = parser.add_subparsers() is_command = lambda x: inspect.isclass(x) and issubclass(x, Command ) and x != Command commands = [ cls(e) for _, cls in inspect.getmembers(ino.commands, is_command) ] for cmd in commands: p = subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line) if current_command != cmd.name: continue cmd.setup_arg_parser(p) p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name)) args = parser.parse_args() try: run_anywhere = "init clean list-models serial" in_project_dir = os.path.isdir(e.src_dir) if not in_project_dir and current_command not in run_anywhere: raise Abort("No project found in this directory.") e.process_args(args) if current_command not in run_anywhere: # For valid projects create .build & lib if not os.path.isdir(e.build_dir): os.makedirs(e.build_dir) if not os.path.isdir(e.lib_dir): os.makedirs(e.lib_dir) with open('lib/.holder', 'w') as f: f.write("") args.func(args) except Abort as exc: print colorize(str(exc), 'red') sys.exit(1) except KeyboardInterrupt: print 'Terminated by user' finally: e.dump()
def main(): e = Environment() e.load() conf = configure() try: current_command = sys.argv[1] except IndexError: current_command = None parser = argparse.ArgumentParser(prog='ino', formatter_class=FlexiFormatter, description=__doc__) subparsers = parser.add_subparsers() is_command = lambda x: inspect.isclass(x) and issubclass(x, Command ) and x != Command commands = [ cls(e) for _, cls in inspect.getmembers(ino.commands, is_command) ] for cmd in commands: p = subparsers.add_parser(cmd.name, formatter_class=FlexiFormatter, help=cmd.help_line) if current_command != cmd.name: continue cmd.setup_arg_parser(p) p.set_defaults(func=cmd.run, **conf.as_dict(cmd.name)) args = parser.parse_args() try: e.process_args(args) if current_command not in 'clean init' and not os.path.isdir( e.build_dir): os.makedirs(e.build_dir) args.func(args) except Abort as exc: print colorize(str(exc), 'red') sys.exit(1) except KeyboardInterrupt: print 'Terminated by user' finally: e.dump()
def run(self): logging.info("Starting arduino thread") port = Environment().guess_serial_port() arduino.main_loop(arduino.connect(port), self.arduino_cbk)