def main(): params = parse_args() if params.get('project_home', '') == '': params.update(project_home=os.getcwd()) apply_if(params, load_sketch_conf(params.get('project_home'))) # print(json.dumps(params, indent=4)) out('%(GRAY)s%(BOLD)sStart of Arduino Sketch Utility.') out('%(BOLD)s-------') CMD_MAP = { 'create': create_or_update_command, 'update': create_or_update_command, 'build': build_command, 'rebuild': rebuild_command, 'clean': clean_command, 'deploy': not_implemented, 'variant-list': variant_list, 'library-list': not_implemented, 'show': show_command, 'version': version_cmd, } cmd = params.get('command') if cmd == 'help': for command, method in CMD_MAP.items(): out( ' %(GRAY)s%(BOLD)s%(command)s%(RESET)s%(doc)s', command=command, doc=method.__doc__ ) else: CMD_MAP.get(cmd, command_not_found)(**params) out('%(BOLD)s-------') out('%(GRAY)s%(BOLD)sEnd of Arduino Sketch Utility.')
def variant_list(sdk_variant_dir, variant, **params): ''' Mostra a lista de variantes reconhecida pela SDK do arduino. ''' pathname = "avr" if variant == pathname: out(' %(GREEN)s%(BOLD)s%(pathname)s', pathname=pathname) else: out(' %(GREEN)s%(pathname)s', pathname=pathname) if sdk_variant_dir is not None and os.path.isdir(sdk_variant_dir) is True: for pathname in os.listdir(sdk_variant_dir): path = os.path.join(sdk_variant_dir, pathname) if os.path.isdir(path) and variant == pathname: out(' %(GREEN)s%(BOLD)s%(pathname)s', pathname=pathname) elif os.path.isdir(path): out(' %(GREEN)s%(pathname)s', pathname=pathname)
def show_command(**params): ''' Mostra informações da configuração atual do projeto. ''' params = expand_project_path(params) if params.get('clock', None) is None: params.update(clock=0) tpl = [ '%(CYAN)s%(BOLD)sMCU name%(RESET)s: %(mcu)s', '%(CYAN)s%(BOLD)sMCU clock%(RESET)s: %(clock)0.2f MHz', '%(CYAN)s%(BOLD)sVariant%(RESET)s: %(variant)s', '%(CYAN)s%(BOLD)sArduino SDK%(RESET)s: %(sdk_home)s', ' - %(CYAN)s%(BOLD)sVariants%(RESET)s: %(sdk_variant_dir)s', ' - %(CYAN)s%(BOLD)sLibraries%(RESET)s: %(sdk_libary_dir)s', ' - %(CYAN)s%(BOLD)sSources%(RESET)s: %(sdk_source_dir)s', ' - %(CYAN)s%(BOLD)sProgramer%(RESET)s: %(programer)s', ' - %(CYAN)s%(BOLD)sSerial port%(RESET)s: %(serial)s', '%(CYAN)s%(BOLD)sAVR Compiler%(RESET)s: %(avr_home)s', ' - %(CYAN)s%(BOLD)sCC%(RESET)s: %(cc)s', ' - %(CYAN)s%(BOLD)sLD%(RESET)s: %(ld)s', ' - %(CYAN)s%(BOLD)sOBJCOPY%(RESET)s: %(objcopy)s', ' - %(CYAN)s%(BOLD)sAR%(RESET)s: %(ar)s', ' - %(CYAN)s%(BOLD)sASM%(RESET)s: %(asm)s', ' - %(CYAN)s%(BOLD)sSIZE%(RESET)s: %(size)s', ' - %(CYAN)s%(BOLD)sINCLUDE%(RESET)s: %(avr_include)s', ' - %(CYAN)s%(BOLD)sLIB%(RESET)s: %(avr_lib)s', '%(CYAN)s%(BOLD)sProject Path%(RESET)s: %(project_home)s', ' - %(CYAN)s%(BOLD)sSources%(RESET)s: %(source_dir)s', ' - %(CYAN)s%(BOLD)sLibrary%(RESET)s: %(lib_dir)s', ' - %(CYAN)s%(BOLD)sBinary%(RESET)s: %(bin_dir)s', ' - %(CYAN)s%(BOLD)sInclude%(RESET)s: %(include_dir)s' ] out('\n'.join(tpl), **params)
def version_cmd(*args, **kwargs): ''' Mostra a versão do sketchduino. ''' out('Sketchduino version %(BOLD)s%(GREEN)s%(version)s', version=__version__)
def create_or_update_command(command=None, **kargs): ''' Manipula o projeto. ''' params = expand_project_path( sdk_refresh( find_avr_toolchain(kargs) ) ) project_home = kargs.get('project_home') temp_dir = os.path.join(project_home, 'tmp') out('Creating sketch in %(CYAN)s%(project_home)s', endline='%(RESET)s ', **params) out(create_directory_tree(project_home), endline='') out(create_directory_tree(temp_dir), endline='') out(create_directory_tree(kargs.get('source_dir')), endline='') out(create_directory_tree(kargs.get('lib_dir')), endline='') out(create_directory_tree(kargs.get('bin_dir')), endline='') out(create_directory_tree(kargs.get('include_dir')), endline='') out(create_main(**kargs), endline='') out(create_or_update_makefile(**kargs), endline='') with codecs.open(os.path.join(project_home, 'sketch.json'), 'w', 'utf-8') as fd: json.dump(params, fd, indent=4) out('', **params)
def command_not_found(**kargs): ''' Commando não encontrado. ''' out('The command %(RED)s%(BLINK)s%(command)s%(RESET)s not found!', **kargs)
def not_implemented(**kargs): ''' Comando não implementado até o momento. ''' out('Not implemented command %(RED)s%(BLINK)s%(command)s', **kargs)