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") 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 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 after_upgrade(ctx): 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__) else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") clean_cache() u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) # update development platforms pm = PlatformManager() for manifest in pm.get_installed(): # pm.update(manifest['name'], "^" + manifest['version']) pm.update(manifest['name']) # update PlatformIO Plus tool if installed pioplus_update() click.secho( "PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") telemetry.on_event( category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__)) else: raise exception.UpgradeError("Auto upgrading...") click.echo("") # PlatformIO banner terminal_width, _ = click.get_terminal_size() 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 IoT development > %s" % (click.style( "try", fg="cyan"), click.style( "http://platformio.org/platformio-ide", fg="cyan"))) if not util.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("")
def _prefill_custom_data(self): self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = 1 if not util.is_ci() else 0 if app.get_session_var("caller_id"): self['cd5'] = str(app.get_session_var("caller_id")).lower()
def after_upgrade(ctx): 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__) else: click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") clean_cache() u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) # update development platforms pm = PlatformManager() for manifest in pm.get_installed(): # pm.update(manifest['name'], "^" + manifest['version']) pm.update(manifest['name']) # update PlatformIO Plus tool if installed pioplus_update() click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") telemetry.on_event(category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__)) else: raise exception.UpgradeError("Auto upgrading...") click.echo("") # PlatformIO banner terminal_width, _ = click.get_terminal_size() 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 IoT development > %s" % (click.style("try", fg="cyan"), click.style("http://platformio.org/platformio-ide", fg="cyan"))) if not util.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("")
def on_command(): resend_backuped_reports() mp = MeasurementProtocol() mp.send("screenview") if util.is_ci(): measure_ci()
def after_upgrade(ctx): last_version = app.get_state_item("last_version", "0.0.0") if last_version == __version__: return terminal_width, _ = click.get_terminal_size() # promotion click.echo("") 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 IoT development > %s" % ( click.style("try", fg="cyan"), click.style("http://platformio.org/#!/platformio-ide", fg="cyan") )) if not util.is_ci(): click.echo("- %s to keep PlatformIO alive! > %s" % ( click.style("donate", fg="cyan"), click.style("http://platformio.org/#!/donate", fg="cyan") )) click.echo("*" * terminal_width) click.echo("") if last_version == "0.0.0": app.set_state_item("last_version", __version__) return click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) ctx.invoke(cmd_platforms_update) click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") telemetry.on_event(category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__)) else: raise exception.UpgradeError("Auto upgrading...") click.echo("")
def _prefill_custom_data(self): caller_id = str(app.get_session_var("caller_id")) self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = 1 if (not util.is_ci() and (caller_id or not util.is_container())) else 0 if caller_id: self['cd5'] = caller_id.lower()
def start(self): if util.is_ci(): click.echo("Unpacking...") for item in self._unpacker.get_items(): self._unpacker.extract_item(item, self._dest_dir) else: with click.progressbar(self._unpacker.get_items(), label="Unpacking") as pb: for item in pb: self._unpacker.extract_item(item, self._dest_dir) return True
def after_upgrade(ctx): last_version = app.get_state_item("last_version", "0.0.0") if last_version == __version__: return terminal_width, _ = click.get_terminal_size() # promotion click.echo("") 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 IoT development > %s" % (click.style("try", fg="cyan"), click.style("http://platformio.org/#!/platformio-ide", fg="cyan"))) if not util.is_ci(): click.echo("- %s to keep PlatformIO alive! > %s" % (click.style("donate", fg="cyan"), click.style("http://platformio.org/#!/donate", fg="cyan"))) click.echo("*" * terminal_width) click.echo("") if last_version == "0.0.0": app.set_state_item("last_version", __version__) return click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) ctx.invoke(cmd_platforms_update) click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") telemetry.on_event(category="Auto", action="Upgrade", label="%s > %s" % (last_version, __version__)) else: raise exception.UpgradeError("Auto upgrading...") click.echo("")
def on_command(): resend_backuped_reports() mp = MeasurementProtocol() mp.send("screenview") if util.is_ci(): measure_ci() if app.get_session_var("caller_id"): measure_caller(app.get_session_var("caller_id"))
def get_setting(name): if name == "enable_prompts": # disable prompts for Continuous Integration systems # and when global "--force" option is set if any([is_ci(), get_session_var("force_option")]): return False _env_name = "PLATFORMIO_SETTING_%s" % name.upper() if _env_name in environ: return sanitize_setting(name, getenv(_env_name)) with State() as data: if "settings" in data and name in data['settings']: return data['settings'][name] return DEFAULT_SETTINGS[name]['value']
def start(self): itercontent = self._request.iter_content(chunk_size=self.CHUNK_SIZE) f = open(self._destination, "wb") chunks = int(ceil(self.get_size() / float(self.CHUNK_SIZE))) if util.is_ci(): click.echo("Downloading...") for _ in range(0, chunks): f.write(next(itercontent)) else: with click.progressbar(length=chunks, label="Downloading") as pb: for _ in pb: f.write(next(itercontent)) f.close() self._request.close() self._preserve_filemtime(self.get_lmtime())
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 util.is_ci() and (caller_id or not is_container())) else 0) if caller_id: self["cd5"] = caller_id.lower()
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['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) # self['cd3'] = " ".join(_filter_args(sys.argv[1:])) self['cd4'] = 1 if (not util.is_ci() and (caller_id or not is_container())) else 0 if caller_id: self['cd5'] = caller_id.lower()
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['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) # self['cd3'] = " ".join(_filter_args(sys.argv[1:])) self['cd4'] = 1 if (not util.is_ci() and (caller_id or not util.is_container())) else 0 if caller_id: self['cd5'] = caller_id.lower()
def on_command(ctx): # pylint: disable=W0613 mp = MeasurementProtocol() mp.send("screenview") if util.is_ci(): measure_ci()
def is_disabled_progressbar(): return is_ci() or getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true"
def is_disabled_progressbar(): return any([ get_session_var("force_option"), util.is_ci(), getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true" ])
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.on_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 IoT development > %s" % (click.style("try", fg="cyan"), click.style("https://platformio.org/platformio-ide", fg="cyan"))) if not util.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("")
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( "http://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.on_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 IoT development > %s" % (click.style("try", fg="cyan"), click.style("http://platformio.org/platformio-ide", fg="cyan"))) if not util.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("")