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(arguments=None, compiled_dir=""): if arguments is not None: sys.argv = arguments e = Environment() e.load() #e.output_dir = compiled_dir + ".build" 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 main(): e = Environment() e.load() conf = configure() try: current_command = sys.argv[1] except IndexError: current_command = None parser = argparse.ArgumentParser(prog='ino-cocoduino', 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' and not os.path.isdir(e.build_dir): os.mkdir(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 sanitize_dirs(environment): if not os.path.isdir(environment.src_dir): raise Abort("Sources directory '%s' not exists!" % environment.src_dir) if not os.path.isdir(environment.build_dir): os.makedirs(environment.build_dir) if not os.path.isdir(environment.lib_dir): os.makedirs(environment.lib_dir) open('lib/.holder', 'w').close() if __name__ == "__main__": cmd_name, args = build_args(environment) try: environment.process_args(args) if cmd_name in ("preprocess", "build", "upload", "build-tests"): sanitize_dirs(environment) args.func(args) except Abort as exc: print(colorize(str(exc), 'red')) sys.exit(1) except KeyboardInterrupt: print('Terminated by user') finally: environment.dump()