def cli(ctx, **options): non_storage_cmds = ("search", "show", "register", "stats", "builtin") # skip commands that don't need storage folder if ctx.invoked_subcommand in non_storage_cmds or \ (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")): return storage_dir = options['storage_dir'] if not storage_dir: if options['global']: storage_dir = join(util.get_home_dir(), "lib") elif util.is_platformio_project(): storage_dir = util.get_projectlibdeps_dir() elif util.is_ci(): storage_dir = join(util.get_home_dir(), "lib") click.secho( "Warning! Global library storage is used automatically. " "Please use `platformio lib --global %s` command to remove " "this warning." % ctx.invoked_subcommand, fg="yellow") elif util.is_platformio_project(storage_dir): with util.cd(storage_dir): storage_dir = util.get_projectlibdeps_dir() if not storage_dir and not util.is_platformio_project(): raise exception.NotGlobalLibDir(util.get_project_dir(), join(util.get_home_dir(), "lib"), ctx.invoked_subcommand) ctx.obj = LibraryManager(storage_dir) if "--json-output" not in ctx.args: click.echo("Library Storage: " + storage_dir)
def init_base_project(project_dir): if not util.is_platformio_project(project_dir): copyfile( join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) lib_dir = join(project_dir, "lib") src_dir = join(project_dir, "src") config = util.load_project_config(project_dir) if config.has_option("platformio", "src_dir"): src_dir = join(project_dir, config.get("platformio", "src_dir")) for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) init_lib_readme(lib_dir) init_ci_conf(project_dir) init_cvs_ignore(project_dir)
def init_base_project(project_dir): if util.is_platformio_project(project_dir): return copyfile( join(util.get_source_dir(), "projectconftpl.ini"), join(project_dir, "platformio.ini")) with util.cd(project_dir): dir_to_readme = [ (util.get_projectsrc_dir(), None), (util.get_projectinclude_dir(), init_include_readme), (util.get_projectlib_dir(), init_lib_readme), (util.get_projecttest_dir(), init_test_readme), ] for (path, cb) in dir_to_readme: if isdir(path): continue makedirs(path) if cb: cb(path)
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # find project directory on upper level if isfile(project_dir): project_dir = util.find_project_dir_above(project_dir) if not util.is_platformio_project(project_dir): raise exception.NotPlatformIOProject(project_dir) with util.cd(project_dir): # clean obsolete .pioenvs dir if not disable_auto_clean: try: _clean_pioenvs_dir(util.get_projectpioenvs_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "`.pioenvs` directory from the project manually to avoid " "build issues" % util.get_projectpioenvs_dir(force=True), fg="yellow", ) config = util.load_project_config() check_project_defopts(config) assert check_project_envs(config, environment) env_default = None if config.has_option("platformio", "env_default"): env_default = [e.strip() for e in config.get("platformio", "env_default").split(",")] results = [] start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any( [ environment and envname not in environment, not environment and env_default and envname not in env_default, ] ) if skipenv: results.append((envname, None)) continue if results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options["piotest"] = ctx.meta["piotest"] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) results.append((envname, ep.process())) if len(results) > 1: click.echo() print_summary(results, start_time) if any([status is False for (_, status) in results]): raise exception.ReturnErrorCode(1) return True
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # find project directory on upper level if isfile(project_dir): project_dir = util.find_project_dir_above(project_dir) if not util.is_platformio_project(project_dir): raise exception.NotPlatformIOProject(project_dir) with util.cd(project_dir): # clean obsolete build dir if not disable_auto_clean: try: _clean_build_dir(util.get_projectbuild_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "it manually to avoid build issues" % util.get_projectbuild_dir(force=True), fg="yellow") config = util.load_project_config() env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) check_project_defopts(config) check_project_envs(config, environment or env_default) results = [] start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any([ environment and envname not in environment, not environment and env_default and envname not in env_default ]) if skipenv: results.append((envname, None)) continue if not silent and results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) result = (envname, ep.process()) results.append(result) if result[1] and "monitor" in ep.get_build_targets() and \ "nobuild" not in ep.get_build_targets(): ctx.invoke( cmd_device_monitor, environment=environment[0] if environment else None) found_error = any(status is False for (_, status) in results) if (found_error or not silent) and len(results) > 1: click.echo() print_summary(results, start_time) if found_error: raise exception.ReturnErrorCode(1) return True
def cli( ctx, # pylint: disable=R0913 project_dir, board, ide, project_option, env_prefix, silent): if not silent: if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho("will be used for the project.", fg="yellow") click.echo("") click.echo("The next files/directories have been created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Put project header files here" % click.style("include", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) click.echo("%s - Put project source files here" % click.style("src", fg="cyan")) click.echo("%s - Project Configuration File" % click.style("platformio.ini", fg="cyan")) is_new_project = not util.is_platformio_project(project_dir) init_base_project(project_dir) if board: fill_project_envs(ctx, project_dir, board, project_option, env_prefix, ide is not None) if ide: env_name = get_best_envname(project_dir, board) if not env_name: raise exception.BoardNotDefined() pg = ProjectGenerator(project_dir, ide, env_name) pg.generate() if is_new_project: init_ci_conf(project_dir) init_cvs_ignore(project_dir) if silent: return if ide: click.secho( "\nProject has been successfully %s including configuration files " "for `%s` IDE." % ("initialized" if is_new_project else "updated", ide), fg="green") else: click.secho( "\nProject has been successfully %s! Useful commands:\n" "`pio run` - process/build project from the current directory\n" "`pio run --target upload` or `pio run -t upload` " "- upload firmware to a target\n" "`pio run --target clean` - clean project (remove compiled files)" "\n`pio run --help` - additional information" % ("initialized" if is_new_project else "updated"), fg="green")
def cli( ctx, # pylint: disable=R0913 project_dir, board, ide, project_option, env_prefix, silent): if not silent: if project_dir == getcwd(): click.secho( "\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho("will be used for the project.", fg="yellow") click.echo("") click.echo("The next files/directories have been created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Put project header files here" % click.style( "include", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) click.echo("%s - Put project source files here" % click.style( "src", fg="cyan")) click.echo("%s - Project Configuration File" % click.style( "platformio.ini", fg="cyan")) is_new_project = not util.is_platformio_project(project_dir) init_base_project(project_dir) if board: fill_project_envs(ctx, project_dir, board, project_option, env_prefix, ide is not None) if ide: env_name = get_best_envname(project_dir, board) if not env_name: raise exception.BoardNotDefined() pg = ProjectGenerator(project_dir, ide, env_name) pg.generate() if is_new_project: init_ci_conf(project_dir) init_cvs_ignore(project_dir) if silent: return if ide: click.secho( "\nProject has been successfully %s including configuration files " "for `%s` IDE." % ("initialized" if is_new_project else "updated", ide), fg="green") else: click.secho( "\nProject has been successfully %s! Useful commands:\n" "`pio run` - process/build project from the current directory\n" "`pio run --target upload` or `pio run -t upload` " "- upload firmware to a target\n" "`pio run --target clean` - clean project (remove compiled files)" "\n`pio run --help` - additional information" % ("initialized" if is_new_project else "updated"), fg="green")
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # find project directory on upper level if isfile(project_dir): project_dir = util.find_project_dir_above(project_dir) if not util.is_platformio_project(project_dir): raise exception.NotPlatformIOProject(project_dir) with util.cd(project_dir): # clean obsolete .pioenvs dir if not disable_auto_clean: try: _clean_pioenvs_dir(util.get_projectpioenvs_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "`.pioenvs` directory from the project manually to avoid " "build issues" % util.get_projectpioenvs_dir(force=True), fg="yellow") config = util.load_project_config() check_project_defopts(config) assert check_project_envs(config, environment) env_default = None if config.has_option("platformio", "env_default"): env_default = util.parse_conf_multi_values( config.get("platformio", "env_default")) results = [] start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any([ environment and envname not in environment, not environment and env_default and envname not in env_default ]) if skipenv: results.append((envname, None)) continue if not silent and results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) result = (envname, ep.process()) results.append(result) if result[1] and "monitor" in ep.get_build_targets() and \ "nobuild" not in ep.get_build_targets(): ctx.invoke(cmd_device_monitor) found_error = any([status is False for (_, status) in results]) if (found_error or not silent) and len(results) > 1: click.echo() print_summary(results, start_time) if found_error: raise exception.ReturnErrorCode(1) return True
def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # find project directory on upper level if isfile(project_dir): project_dir = util.find_project_dir_above(project_dir) if not util.is_platformio_project(project_dir): raise exception.NotPlatformIOProject(project_dir) with util.cd(project_dir): # clean obsolete .pioenvs dir if not disable_auto_clean: try: _clean_pioenvs_dir(util.get_projectpioenvs_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "`.pioenvs` directory from the project manually to avoid " "build issues" % util.get_projectpioenvs_dir(force=True), fg="yellow") config = util.load_project_config() check_project_defopts(config) assert check_project_envs(config, environment) env_default = None if config.has_option("platformio", "env_default"): env_default = [ e.strip() for e in config.get("platformio", "env_default").split(",") ] results = {} start_time = time() for section in config.sections(): if not section.startswith("env:"): continue envname = section[4:] skipenv = any([ environment and envname not in environment, not environment and env_default and envname not in env_default ]) if skipenv: results[envname] = None continue if results: click.echo() options = {} for k, v in config.items(section): options[k] = v if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, silent, verbose) results[envname] = ep.process() if len(results) > 1: click.echo() print_header("[%s]" % click.style("SUMMARY")) successed = True for envname, status in results.items(): status_str = click.style("SUCCESS", fg="green") if status is False: successed = False status_str = click.style("ERROR", fg="red") elif status is None: status_str = click.style("SKIP", fg="yellow") click.echo("Environment %s\t[%s]" % (click.style(envname, fg="cyan"), status_str), err=status is False) print_header( "[%s] Took %.2f seconds" % ((click.style("SUCCESS", fg="green", bold=True) if successed else click.style("ERROR", fg="red", bold=True)), time() - start_time), is_error=not successed) if any([r is False for r in results.values()]): raise exception.ReturnErrorCode() return True