def on_command(): resend_backuped_reports() mp = MeasurementProtocol() mp.send("screenview") if is_ci(): measure_ci()
def is_disabled_progressbar(): return any( [ get_session_var("force_option"), is_ci(), getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true", ] )
def get_user_agent(): data = ["PlatformIO/%s" % __version__, "CI/%d" % int(is_ci())] if get_session_var("caller_id"): data.append("Caller/%s" % get_session_var("caller_id")) if os.getenv("PLATFORMIO_IDE"): data.append("IDE/%s" % os.getenv("PLATFORMIO_IDE")) data.append("Python/%s" % platform.python_version()) data.append("Platform/%s" % platform.platform()) return " ".join(data)
def cli(ctx, **options): storage_cmds = ("install", "uninstall", "update", "list") # skip commands that don't need storage folder if ctx.invoked_subcommand not in storage_cmds or ( len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help") ): return storage_dirs = list(options["storage_dir"]) if options["global"]: storage_dirs.append(get_project_global_lib_dir()) if not storage_dirs: if is_platformio_project(): storage_dirs = [get_project_dir()] elif is_ci(): storage_dirs = [get_project_global_lib_dir()] 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", ) if not storage_dirs: raise NotGlobalLibDir( get_project_dir(), get_project_global_lib_dir(), ctx.invoked_subcommand ) in_silence = PlatformioCLI.in_silence() ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY] = options["environment"] ctx.meta[CTX_META_INPUT_DIRS_KEY] = storage_dirs ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [] ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY] = {} for storage_dir in storage_dirs: if not is_platformio_project(storage_dir): ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir) continue with fs.cd(storage_dir): config = ProjectConfig.get_instance( os.path.join(storage_dir, "platformio.ini") ) config.validate(options["environment"], silent=in_silence) libdeps_dir = config.get_optional_dir("libdeps") for env in config.envs(): if options["environment"] and env not in options["environment"]: continue storage_dir = os.path.join(libdeps_dir, env) ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir) ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY][storage_dir] = config.get( "env:" + env, "lib_deps", [] )
def _prefill_custom_data(self): def _filter_args(items): result = [] stop = False for item in items: item = str(item).lower() result.append(item) if stop: break if item == "account": stop = True return result caller_id = str(app.get_session_var("caller_id")) self["cd1"] = util.get_systype() self["cd4"] = 1 if (not is_ci() and (caller_id or not is_container())) else 0 if caller_id: self["cd5"] = caller_id.lower()
def get_request_defheaders(): data = (__version__, int(is_ci()), requests.utils.default_user_agent()) return {"User-Agent": "PlatformIO/%s CI/%d %s" % data}
def after_upgrade(ctx): terminal_width, _ = click.get_terminal_size() last_version = app.get_state_item("last_version", "0.0.0") if last_version == __version__: return if last_version == "0.0.0": app.set_state_item("last_version", __version__) elif semantic_version.Version.coerce(util.pepver_to_semver( last_version)) > semantic_version.Version.coerce( util.pepver_to_semver(__version__)): click.secho("*" * terminal_width, fg="yellow") click.secho( "Obsolete PIO Core v%s is used (previous was %s)" % (__version__, last_version), fg="yellow", ) click.secho("Please remove multiple PIO Cores from a system:", fg="yellow") click.secho( "https://docs.platformio.org/page/faq.html" "#multiple-pio-cores-in-a-system", fg="cyan", ) click.secho("*" * terminal_width, fg="yellow") return else: click.secho("Please wait while upgrading PlatformIO...", fg="yellow") app.clean_cache() # Update PlatformIO's Core packages update_core_packages(silent=True) u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) click.secho( "PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green", ) telemetry.send_event( category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__), ) else: raise exception.UpgradeError("Auto upgrading...") click.echo("") # PlatformIO banner click.echo("*" * terminal_width) click.echo("If you like %s, please:" % (click.style("PlatformIO", fg="cyan"))) click.echo( "- %s us on Twitter to stay up-to-date " "on the latest project news > %s" % ( click.style("follow", fg="cyan"), click.style("https://twitter.com/PlatformIO_Org", fg="cyan"), )) click.echo("- %s it on GitHub > %s" % ( click.style("star", fg="cyan"), click.style("https://github.com/platformio/platformio", fg="cyan"), )) if not getenv("PLATFORMIO_IDE"): click.echo("- %s PlatformIO IDE for embedded development > %s" % ( click.style("try", fg="cyan"), click.style("https://platformio.org/platformio-ide", fg="cyan"), )) if not is_ci(): click.echo("- %s us with PlatformIO Plus > %s" % ( click.style("support", fg="cyan"), click.style("https://pioplus.com", fg="cyan"), )) click.echo("*" * terminal_width) click.echo("")