def check_internal_updates(ctx, what): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24 if (time() - interval) < last_check.get(what + "_update", 0): return last_check[what + '_update'] = int(time()) app.set_state_item("last_check", last_check) outdated_items = [] if what == "platforms": for platform in PlatformFactory.get_platforms(installed=True).keys(): p = PlatformFactory.newPlatform(platform) if p.is_outdated(): outdated_items.append(platform) elif what == "libraries": lm = LibraryManager() outdated_items = lm.get_outdated() if not outdated_items: return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho("There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow") if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) click.secho("`platformio %s update`" % ("lib" if what == "libraries" else "platforms"), fg="cyan", nl=False) click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": ctx.invoke(cmd_platforms_update) elif what == "libraries": ctx.invoke(cmd_libraries_update) click.echo() telemetry.on_event(category="Auto", action="Update", label=what.title()) click.echo("*" * terminal_width) click.echo("")
def test_check_pio_upgrade(clirunner, validate_cliresult, isolated_pio_home): def _patch_pio_version(version): maintenance.__version__ = version cmd_upgrade.VERSION = version.split(".", 3) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 last_check = {"platformio_upgrade": time() - interval - 1} origin_version = maintenance.__version__ # check development version _patch_pio_version("3.0.0-a1") app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["platform", "list"]) validate_cliresult(result) assert "There is a new version" in result.output assert "Please upgrade" in result.output # check stable version _patch_pio_version("2.11.0") app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["platform", "list"]) validate_cliresult(result) assert "There is a new version" in result.output assert "Please upgrade" in result.output # restore original version _patch_pio_version(origin_version)
def platforms_show(ctx, platform): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if platform not in installed_platforms: if (not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform)): ctx.invoke(platforms_install, platforms=[platform]) else: raise PlatformNotInstalledYet(platform) p = PlatformFactory.newPlatform(platform) click.echo("{name:<20} - {description} [ {url} ]".format( name=click.style(p.get_type(), fg="cyan"), description=p.get_description(), url=p.get_vendor_url())) installed_packages = PackageManager.get_installed() for name in p.get_installed_packages(): data = installed_packages[name] pkgalias = p.get_pkg_alias(name) click.echo("----------") click.echo("Package: %s" % click.style(name, fg="yellow")) if pkgalias: click.echo("Alias: %s" % pkgalias) click.echo("Version: %d" % int(data['version'])) click.echo("Installed: %s" % datetime.fromtimestamp( data['time']).strftime("%Y-%m-%d %H:%M:%S"))
def _autoinstall_platform(ctx, platform, targets): installed_platforms = PlatformFactory.get_platforms(installed=True).keys() cmd_options = {} p = PlatformFactory.newPlatform(platform) if "uploadlazy" in targets: upload_tools = p.pkg_aliases_to_names(["uploader"]) # platform without uploaders if not upload_tools and platform in installed_platforms: return # uploaders are already installed if set(upload_tools) <= set(p.get_installed_packages()): return cmd_options["skip_default_package"] = True if upload_tools: cmd_options["with_package"] = ["uploader"] elif platform in installed_platforms and set(p.get_default_packages()) <= set(p.get_installed_packages()): return if not app.get_setting("enable_prompts") or click.confirm( "The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform ): ctx.invoke(cmd_platforms_install, platforms=[platform], **cmd_options)
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) latest_version = get_latest_version() if (latest_version == __version__ or Upgrader.version_to_int(latest_version) < Upgrader.version_to_int(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via " % latest_version, fg="yellow", nl=False) click.secho("platformio upgrade", fg="cyan", nl=False) click.secho(" command.\nChanges: ", fg="yellow", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def _ignore_hit(): if not app.get_setting("enable_telemetry"): return True if app.get_session_var("caller_id") and \ all(c in sys.argv for c in ("run", "idedata")): return True return False
def settings_get(name): list_tpl = "{name:<40} {value:<35} {description}" click.echo( list_tpl.format( name=click.style("Name", fg="cyan"), value=(click.style("Value", fg="green") + click.style(" [Default]", fg="yellow")), description="Description", ) ) click.echo("-" * 90) for _name, _data in sorted(app.DEFAULT_SETTINGS.items()): if name and name != _name: continue _value = app.get_setting(_name) _value_str = str(_value) if isinstance(_value, bool): _value_str = "Yes" if _value else "No" _value_str = click.style(_value_str, fg="green") if _value != _data["value"]: _defvalue_str = str(_data["value"]) if isinstance(_data["value"], bool): _defvalue_str = "Yes" if _data["value"] else "No" _value_str += click.style(" [%s]" % _defvalue_str, fg="yellow") else: _value_str += click.style(" ", fg="yellow") click.echo( list_tpl.format(name=click.style(_name, fg="cyan"), value=_value_str, description=_data["description"]) )
def _get_api_result(url, params=None, data=None, auth=None): # pylint: disable=too-many-branches from platformio.app import get_setting result = None r = None disable_ssl_check = sys.version_info < (2, 7, 9) headers = get_request_defheaders() if not url.startswith("http"): url = __apiurl__ + url if not get_setting("enable_ssl"): url = url.replace("https://", "http://") try: if data: r = _api_request_session().post( url, params=params, data=data, headers=headers, auth=auth, verify=disable_ssl_check ) else: r = _api_request_session().get(url, params=params, headers=headers, auth=auth, verify=disable_ssl_check) result = r.json() r.raise_for_status() except requests.exceptions.HTTPError as e: if result and "message" in result: raise exception.APIRequestError(result["message"]) elif result and "errors" in result: raise exception.APIRequestError(result["errors"][0]["title"]) else: raise exception.APIRequestError(e) except ValueError: raise exception.APIRequestError("Invalid response: %s" % r.text.encode("utf-8")) finally: if r: r.close() return result
def _run_environment(ctx, name, options, targets, upload_port): variables = ["PIOENV=" + name] if upload_port: variables.append("UPLOAD_PORT=%s" % upload_port) for k, v in options.items(): k = k.upper() if k == "TARGETS" or (k == "UPLOAD_PORT" and upload_port): continue variables.append("%s=%s" % (k.upper(), v)) envtargets = [] if targets: envtargets = [t for t in targets] elif "targets" in options: envtargets = options['targets'].split() if "platform" not in options: raise exception.UndefinedEnvPlatform(name) platform = options['platform'] telemetry.on_run_environment(options, envtargets) installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (platform not in installed_platforms and ( not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform))): ctx.invoke(cmd_install, platforms=[platform]) p = PlatformFactory.newPlatform(platform) return p.run(variables, envtargets)
def lib_install_dependency(ctx, data): assert isinstance(data, dict) query = [] for key in data.keys(): if key in ("authors", "frameworks", "platforms", "keywords"): values = data[key] if not isinstance(values, list): values = [v.strip() for v in values.split(",") if v] for value in values: query.append('%s:"%s"' % (key[:-1], value)) elif isinstance(data[key], basestring): query.append('+"%s"' % data[key]) result = get_api_result("/lib/search", dict(query=" ".join(query))) assert result['total'] > 0 if result['total'] == 1 or not app.get_setting("enable_prompts"): ctx.invoke(lib_install, libid=[result['items'][0]['id']]) else: click.secho( "Conflict: More than one dependent libraries have been found " "by request %s:" % json.dumps(data), fg="red") echo_liblist_header() for item in result['items']: echo_liblist_item(item) deplib_id = click.prompt( "Please choose one dependent library ID", type=click.Choice([str(i['id']) for i in result['items']])) ctx.invoke(lib_install, libid=[int(deplib_id)])
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) try: latest_version = get_latest_version() except GetLatestVersionError: click.secho("Failed to check for PlatformIO upgrades", fg="red") return if (latest_version == __version__ or Upgrader.version_to_int(latest_version) < Upgrader.version_to_int(__version__)): return click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via " % latest_version, fg="yellow", nl=False) click.secho("platformio upgrade", fg="cyan", nl=False) click.secho(" command.\nChanges: ", fg="yellow", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html\n", fg="cyan")
def test_check_and_update_platforms(clirunner, validate_cliresult, isolated_pio_home): # enable library auto-updates result = clirunner.invoke( cli_pio, ["settings", "set", "auto_update_platforms", "Yes"]) # reset check time interval = int(app.get_setting("check_platforms_interval")) * 3600 * 24 last_check = {"platforms_update": time() - interval - 1} app.set_state_item("last_check", last_check) # fetch installed version result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"]) validate_cliresult(result) prev_data = json.loads(result.output) assert len(prev_data) == 1 # initiate auto-updating result = clirunner.invoke(cli_pio, ["platform", "show", "native"]) validate_cliresult(result) assert "There are the new updates for platforms (native)" in result.output assert "Please wait while updating platforms" in result.output assert "[Out-of-date]" in result.output # check updated version result = clirunner.invoke(cli_pio, ["platform", "list", "--json-output"]) validate_cliresult(result) assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
def test_check_and_update_libraries(clirunner, validate_cliresult): # enable library auto-updates result = clirunner.invoke( cli_pio, ["settings", "set", "auto_update_libraries", "Yes"]) # reset check time interval = int(app.get_setting("check_libraries_interval")) * 3600 * 24 last_check = {"libraries_update": time() - interval - 1} app.set_state_item("last_check", last_check) # fetch installed version result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"]) validate_cliresult(result) prev_data = json.loads(result.output) assert len(prev_data) == 1 # initiate auto-updating result = clirunner.invoke(cli_pio, ["lib", "-g", "show", "ArduinoJson"]) validate_cliresult(result) assert ("There are the new updates for libraries (ArduinoJson)" in result.output) assert "Please wait while updating libraries" in result.output assert re.search(r"Updating ArduinoJson\s+@ 5.6.7\s+\[[\d\.]+\]", result.output) # check updated version result = clirunner.invoke(cli_pio, ["lib", "-g", "list", "--json-output"]) validate_cliresult(result) assert prev_data[0]['version'] != json.loads(result.output)[0]['version']
def __init__(self, package_dir=None, repositories=None): if not repositories: repositories = [ "https://dl.bintray.com/platformio/dl-platforms/manifest.json", "{0}://dl.platformio.org/platforms/manifest.json".format( "https" if app.get_setting("enable_ssl") else "http" ), ] BasePkgManager.__init__(self, package_dir or join(util.get_home_dir(), "platforms"), repositories)
def send(self, hittype): if not app.get_setting("enable_telemetry"): return self['t'] = hittype # correct queue time if "qt" in self._params and isinstance(self['qt'], float): self['qt'] = int((time() - self['qt']) * 1000) MPDataPusher().push(self._params)
def lib_search(query, json_output, page, **filters): if not query: query = [] if not isinstance(query, list): query = list(query) for key, values in filters.iteritems(): for value in values: query.append('%s:"%s"' % (key, value)) result = get_api_result("/lib/search", dict(query=" ".join(query), page=page)) if json_output: click.echo(json.dumps(result)) return if result['total'] == 0: click.secho( "Nothing has been found by your request\n" "Try a less-specific search or use truncation (or wildcard) " "operator", fg="yellow", nl=False) click.secho(" *", fg="green") click.secho("For example: DS*, PCA*, DHT* and etc.\n", fg="yellow") click.echo("For more examples and advanced search syntax, " "please use documentation:") click.secho("http://docs.platformio.org" "/en/latest/userguide/lib/cmd_search.html\n", fg="cyan") return click.secho("Found %d libraries:\n" % result['total'], fg="green" if result['total'] else "yellow") if result['total']: echo_liblist_header() while True: for item in result['items']: echo_liblist_item(item) if (int(result['page']) * int(result['perpage']) >= int(result['total'])): break if (app.get_setting("enable_prompts") and click.confirm("Show next libraries?")): result = get_api_result( "/lib/search", dict(query=" ".join(query), page=int(result['page']) + 1) ) else: break
def _autoinstall_libs(ctx, libids_list): require_libs = [int(l.strip()) for l in libids_list.split(",")] installed_libs = [l["id"] for l in LibraryManager().get_installed().values()] not_intalled_libs = set(require_libs) - set(installed_libs) if not require_libs or not not_intalled_libs: return if not app.get_setting("enable_prompts") or click.confirm( "The libraries with IDs '%s' have not been installed yet. " "Would you like to install them now?" % ", ".join([str(i) for i in not_intalled_libs]) ): ctx.invoke(cmd_lib_install, libid=not_intalled_libs)
def test_check_lib_updates(clirunner, isolated_pio_home, validate_cliresult): # install obsolete library result = clirunner.invoke(cli_pio, ["lib", "-g", "install", "ArduinoJson@<6.13"]) validate_cliresult(result) # reset check time interval = int(app.get_setting("check_libraries_interval")) * 3600 * 24 last_check = {"libraries_update": time() - interval - 1} app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["lib", "-g", "list"]) validate_cliresult(result) assert "There are the new updates for libraries (ArduinoJson)" in result.output
def _get_api_result( url, # pylint: disable=too-many-branches params=None, data=None, auth=None): from platformio.app import get_setting result = None r = None verify_ssl = sys.version_info >= (2, 7, 9) headers = get_request_defheaders() if not url.startswith("http"): url = __apiurl__ + url if not get_setting("enable_ssl"): url = url.replace("https://", "http://") try: if data: r = _api_request_session().post( url, params=params, data=data, headers=headers, auth=auth, verify=verify_ssl) else: r = _api_request_session().get( url, params=params, headers=headers, auth=auth, verify=verify_ssl) result = r.json() r.raise_for_status() return r.text except requests.exceptions.HTTPError as e: if result and "message" in result: raise exception.APIRequestError(result['message']) elif result and "errors" in result: raise exception.APIRequestError(result['errors'][0]['title']) else: raise exception.APIRequestError(e) except ValueError: raise exception.APIRequestError( "Invalid response: %s" % r.text.encode("utf-8")) finally: if r: r.close() return None
def _install_from_piorepo(self, name, requirements): assert name.startswith("id="), name version = self.get_latest_repo_version(name, requirements) if not version: raise exception.UndefinedPackageVersion(requirements or "latest", util.get_systype()) dl_data = util.get_api_result("/lib/download/" + str(name[3:]), dict(version=version), cache_valid="30d") assert dl_data return self._install_from_url( name, dl_data['url'].replace("http://", "https://") if app.get_setting("strict_ssl") else dl_data['url'], requirements)
def lib_search(query, **filters): if not query: query = [] if not isinstance(query, list): query = list(query) for key, values in filters.iteritems(): for value in values: query.append('%s:"%s"' % (key, value)) result = get_api_result("/lib/search", dict(query=" ".join(query))) if result['total'] == 0: click.secho( "Nothing has been found by your request\n" "Try a less-specific search or use truncation (or wildcard) " "operator", fg="yellow", nl=False) click.secho(" *", fg="green") click.secho("For example: DS*, PCA*, DHT* and etc.\n", fg="yellow") click.echo("For more examples and advanced search syntax, " "please use documentation:") click.secho( "http://docs.platformio.org" "/en/latest/userguide/lib/cmd_search.html\n", fg="cyan") return click.secho("Found %d libraries:\n" % result['total'], fg="green" if result['total'] else "yellow") if result['total']: echo_liblist_header() while True: for item in result['items']: echo_liblist_item(item) if (int(result['page']) * int(result['perpage']) >= int( result['total'])): break if (app.get_setting("enable_prompts") and click.confirm("Show next libraries?")): result = get_api_result( "/lib/search", dict(query=" ".join(query), page=str(int(result['page']) + 1))) else: break
def _install_from_piorepo(self, name, requirements): assert name.startswith("id="), name version = self.get_latest_repo_version(name, requirements) if not version: raise exception.UndefinedPackageVersion(requirements or "latest", util.get_systype()) dl_data = util.get_api_result( "/lib/download/" + str(name[3:]), dict(version=version), cache_valid="30d") assert dl_data return self._install_from_url( name, dl_data['url'].replace("http://", "https://") if app.get_setting("enable_ssl") else dl_data['url'], requirements)
def test_check_lib_updates(clirunner, validate_cliresult, isolated_pio_home): # install obsolete library result = clirunner.invoke(cli_pio, ["lib", "-g", "install", "ArduinoJson@<5.7"]) validate_cliresult(result) # reset check time interval = int(app.get_setting("check_libraries_interval")) * 3600 * 24 last_check = {"libraries_update": time() - interval - 1} app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["lib", "-g", "list"]) validate_cliresult(result) assert ("There are the new updates for libraries (ArduinoJson)" in result.output)
def _autoinstall_libs(ctx, libids_list): require_libs = [int(l.strip()) for l in libids_list.split(",")] installed_libs = [ l['id'] for l in LibraryManager().get_installed().values() ] not_intalled_libs = set(require_libs) - set(installed_libs) if not require_libs or not not_intalled_libs: return if (not app.get_setting("enable_prompts") or click.confirm( "The libraries with IDs '%s' have not been installed yet. " "Would you like to install them now?" % ", ".join([str(i) for i in not_intalled_libs]))): ctx.invoke(cmd_lib_install, libid=not_intalled_libs)
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check["platformio_upgrade"] = int(time()) app.set_state_item("last_check", last_check) util.internet_on(raise_exception=True) # Update PlatformIO's Core packages update_core_packages(silent=True) latest_version = get_latest_version() if semantic_version.Version.coerce(util.pepver_to_semver( latest_version)) <= semantic_version.Version.coerce( util.pepver_to_semver(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho( "There is a new version %s of PlatformIO available.\n" "Please upgrade it via `" % latest_version, fg="yellow", nl=False, ) if getenv("PLATFORMIO_IDE"): click.secho("PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False) click.secho("`.", fg="yellow") elif join("Cellar", "platformio") in fs.get_source_dir(): click.secho("brew update && brew upgrade", fg="cyan", nl=False) click.secho("` command.", fg="yellow") else: click.secho("platformio upgrade", fg="cyan", nl=False) click.secho("` or `", fg="yellow", nl=False) click.secho("pip install -U platformio", fg="cyan", nl=False) click.secho("` command.", fg="yellow") click.secho("Changes: ", fg="yellow", nl=False) click.secho("https://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def _install_default_packages(self): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (self.get_type() in installed_platforms and set(self.get_default_packages()) <= set( self.get_installed_packages())): return True if (not app.get_setting("enable_prompts") or self.get_type() in installed_platforms or click.confirm( "The platform '%s' has not been installed yet. " "Would you like to install it now?" % self.get_type())): return self.install() else: raise exception.PlatformNotInstalledYet(self.get_type())
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise UnknownBoard(", ".join(set(board).difference(builtin_boards))) if project_dir == getcwd(): click.secho("The current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File" % click.style("platformio.ini", fg="cyan")) click.echo("%s - a source directory. Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - a directory for the project specific libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\n" "Now you can process it with `platformio run` command.", fg="green") else: click.secho("Aborted by user", fg="red")
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) util.internet_on(raise_exception=True) # Update PlatformIO's Core packages update_core_packages(silent=True) latest_version = get_latest_version() if semantic_version.Version.coerce(util.pepver_to_semver( latest_version)) <= semantic_version.Version.coerce( util.pepver_to_semver(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho( "There is a new version %s of PlatformIO available.\n" "Please upgrade it via `" % latest_version, fg="yellow", nl=False) if getenv("PLATFORMIO_IDE"): click.secho( "PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False) click.secho("`.", fg="yellow") elif join("Cellar", "platformio") in util.get_source_dir(): click.secho("brew update && brew upgrade", fg="cyan", nl=False) click.secho("` command.", fg="yellow") else: click.secho("platformio upgrade", fg="cyan", nl=False) click.secho("` or `", fg="yellow", nl=False) click.secho("pip install -U platformio", fg="cyan", nl=False) click.secho("` command.", fg="yellow") click.secho("Changes: ", fg="yellow", nl=False) click.secho( "https://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def _install_default_packages(self): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (self.get_type() in installed_platforms and set(self.get_default_packages()) <= set(self.get_installed_packages())): return True if (not app.get_setting("enable_prompts") or self.get_type() in installed_platforms or click.confirm( "The platform '%s' has not been installed yet. " "Would you like to install it now?" % self.get_type())): return self.install() else: raise exception.PlatformNotInstalledYet(self.get_type())
def test_check_platform_updates(clirunner, isolated_pio_core, validate_cliresult): # install obsolete platform result = clirunner.invoke(cli_pio, ["platform", "install", "native"]) validate_cliresult(result) os.remove(str(isolated_pio_core.join("platforms", "native", ".piopm"))) manifest_path = isolated_pio_core.join("platforms", "native", "platform.json") manifest = json.loads(manifest_path.read()) manifest["version"] = "0.0.0" manifest_path.write(json.dumps(manifest)) # reset check time interval = int(app.get_setting("check_platforms_interval")) * 3600 * 24 last_check = {"platforms_update": time() - interval - 1} app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["platform", "list"]) validate_cliresult(result) assert "There are the new updates for platforms (native)" in result.output
def test_check_platform_updates(clirunner, validate_cliresult, isolated_pio_home): # install obsolete platform result = clirunner.invoke(cli_pio, ["platform", "install", "native"]) validate_cliresult(result) manifest_path = isolated_pio_home.join("platforms", "native", "platform.json") manifest = json.loads(manifest_path.read()) manifest['version'] = "0.0.0" manifest_path.write(json.dumps(manifest)) # reset cached manifests PlatformManager().reset_cache() # reset check time interval = int(app.get_setting("check_platforms_interval")) * 3600 * 24 last_check = {"platforms_update": time() - interval - 1} app.set_state_item("last_check", last_check) result = clirunner.invoke(cli_pio, ["platform", "list"]) validate_cliresult(result) assert "There are the new updates for platforms (native)" in result.output
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) latest_version = get_latest_version() if (latest_version == __version__ or Upgrader.version_to_int(latest_version) < Upgrader.version_to_int(__version__)): return click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via " % latest_version, fg="yellow", nl=False) click.secho("platformio upgrade", fg="cyan", nl=False) click.secho(" command.\nChanges: ", fg="yellow", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html\n", fg="cyan")
def settings_get(name): tabular_data = [] for key, options in sorted(app.DEFAULT_SETTINGS.items()): if name and name != key: continue raw_value = app.get_setting(key) formatted_value = format_value(raw_value) if raw_value != options["value"]: default_formatted_value = format_value(options["value"]) formatted_value += "%s" % ( "\n" if len(default_formatted_value) > 10 else " ") formatted_value += "[%s]" % click.style(default_formatted_value, fg="yellow") tabular_data.append( (click.style(key, fg="cyan"), formatted_value, options["description"])) click.echo( tabulate(tabular_data, headers=["Name", "Current value [Default]", "Description"]))
def _get_api_result( path, # pylint: disable=too-many-branches params=None, data=None): from platformio.app import get_setting result = None r = None headers = get_request_defheaders() url = __apiurl__ if not get_setting("enable_ssl"): url = url.replace("https://", "http://") try: if data: r = _api_request_session().post(url + path, params=params, data=data, headers=headers) else: r = _api_request_session().get(url + path, params=params, headers=headers) result = r.json() r.raise_for_status() except requests.exceptions.HTTPError as e: if result and "errors" in result: raise exception.APIRequestError(result['errors'][0]['title']) else: raise exception.APIRequestError(e) except ValueError: raise exception.APIRequestError("Invalid response: %s" % r.text.encode("utf-8")) finally: if r: r.close() return result
def lib_search(query, **filters): if not query: query = "" for key, values in filters.iteritems(): for value in values: query += ' %s:"%s"' % (key, value) result = get_api_result("/lib/search", dict(query=query)) if result["total"] == 0: click.secho( "Nothing has been found by your request\n" "Try a less-specific search or use truncation (or wildcard) " "operator", fg="yellow", nl=False, ) click.secho(" *", fg="green") click.secho("For example: DS*, PCA*, DHT* and etc.\n", fg="yellow") click.echo("For more examples and advanced search syntax, " "please use documentation:") click.secho("http://docs.platformio.org" "/en/latest/userguide/lib/cmd_search.html\n", fg="cyan") return click.secho("Found %d libraries:\n" % result["total"], fg="green" if result["total"] else "yellow") if result["total"]: echo_liblist_header() while True: for item in result["items"]: echo_liblist_item(item) if int(result["page"]) * int(result["perpage"]) >= int(result["total"]): break if app.get_setting("enable_prompts") and click.confirm("Show next libraries?"): result = get_api_result("/lib/search", dict(query=query, page=str(int(result["page"]) + 1))) else: break
def check_platformio_upgrade(): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_platformio_interval")) * 3600 * 24 if (time() - interval) < last_check.get("platformio_upgrade", 0): return last_check['platformio_upgrade'] = int(time()) app.set_state_item("last_check", last_check) latest_version = get_latest_version() if (latest_version == __version__ or Upgrader.version_to_int(latest_version) < Upgrader.version_to_int(__version__)): return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via `" % latest_version, fg="yellow", nl=False) if getenv("PLATFORMIO_IDE"): click.secho("PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False) click.secho("`.", fg="yellow") else: click.secho("platformio upgrade", fg="cyan", nl=False) click.secho("` or `", fg="yellow", nl=False) click.secho("pip install -U platformio", fg="cyan", nl=False) click.secho("` command.", fg="yellow") click.secho("Changes: ", fg="yellow", nl=False) click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") click.echo("*" * terminal_width) click.echo("")
def run(self, variables, targets, silent, verbose): assert isinstance(variables, dict) assert isinstance(targets, list) self.configure_default_packages(variables, targets) self.install_packages(silent=True) self.silent = silent self.verbose = verbose or app.get_setting("force_verbose") if "clean" in targets: targets = ["-c", "."] variables['platform_manifest'] = self.manifest_path if "build_script" not in variables: variables['build_script'] = self.get_build_script() if not isfile(variables['build_script']): raise exception.BuildScriptNotFound(variables['build_script']) result = self._run_scons(variables, targets) assert "returncode" in result return result
def settings_get(name): list_tpl = "{name:<40} {value:<35} {description}" terminal_width, _ = click.get_terminal_size() click.echo( list_tpl.format( name=click.style("Name", fg="cyan"), value=(click.style("Value", fg="green") + click.style( " [Default]", fg="yellow")), description="Description")) click.echo("-" * terminal_width) for _name, _data in sorted(app.DEFAULT_SETTINGS.items()): if name and name != _name: continue _value = app.get_setting(_name) _value_str = str(_value) if isinstance(_value, bool): _value_str = "Yes" if _value else "No" _value_str = click.style(_value_str, fg="green") if _value != _data['value']: _defvalue_str = str(_data['value']) if isinstance(_data['value'], bool): _defvalue_str = "Yes" if _data['value'] else "No" _value_str += click.style(" [%s]" % _defvalue_str, fg="yellow") else: _value_str += click.style(" ", fg="yellow") click.echo( list_tpl.format( name=click.style(_name, fg="cyan"), value=_value_str, description=_data['description']))
def _prefill_custom_data(self): self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = (1 if app.get_setting("enable_prompts") or app.get_session_var("caller_id") else 0)
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 enable_auto_uploading, env_prefix): 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 project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") 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) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs( ctx, project_file, board, enable_auto_uploading, env_prefix, ide is not None ) if ide: if not board: raise exception.BoardNotDefined() if len(board) > 1: click.secho( "Warning! You have initialised project with more than 1 board" " for the specified IDE.\n" "However, the IDE features (code autocompletion, syntax lint)" " have been configured for the first board '%s' from your list" " '%s'." % (board[0], ", ".join(board)), fg="yellow" ) pg = ProjectGenerator( project_dir, ide, board[0]) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)\n" "`platformio run --help` - additional information", fg="green" )
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise exception.ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise exception.UnknownBoard( ", ".join(set(board).difference(builtin_boards))) # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "\nWould you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) 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 new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow" ) click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green" ) else: raise exception.AbortedByUser()
def _prefill_custom_data(self): self['cd1'] = get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = 1 if app.get_setting("enable_prompts") else 0
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) click.echo("") 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 project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(join(lib_dir, "readme.txt")): with open(join(lib_dir, "readme.txt"), "w") as f: f.write(""" This directory is intended for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file. The source code of each library should be placed in separate directory, like "lib/private_lib/[here are source files]". For example, see how can be organised `Foo` and `Bar` libraries: |--lib | |--Bar | | |--docs | | |--examples | | |--src | | |- Bar.c | | |- Bar.h | |--Foo | | |- Foo.c | | |- Foo.h | |- readme.txt --> THIS FILE |- platformio.ini |--src |- main.c Then in `src/main.c` you should use: #include <Foo.h> #include <Bar.h> // rest H/C/CPP code PlatformIO will find your libraries automatically, configure preprocessor's include paths and build them. See additional options for PlatformIO Library Dependency Finder `lib_*`: http://docs.platformio.org/en/latest/projectconf.html#lib-install """) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs( ctx, project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide, board[0] if board else None) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green" )
def check_internal_updates(ctx, what): # pylint: disable=too-many-branches last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24 if (time() - interval) < last_check.get(what + "_update", 0): return last_check[what + "_update"] = int(time()) app.set_state_item("last_check", last_check) http.ensure_internet_on(raise_exception=True) outdated_items = [] pm = PlatformPackageManager() if what == "platforms" else LibraryPackageManager() for pkg in pm.get_installed(): if pkg.metadata.name in outdated_items: continue conds = [ pm.outdated(pkg).is_outdated(), what == "platforms" and PlatformFactory.new(pkg).are_outdated_packages(), ] if any(conds): outdated_items.append(pkg.metadata.name) if not outdated_items: return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho( "There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow", ) if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) click.secho( "`platformio %s update`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False, ) click.secho(" command.\n", fg="yellow") click.secho( "If you want to manually check for the new versions " "without updating, please use ", fg="yellow", nl=False, ) click.secho( "`platformio %s update --dry-run`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False, ) click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": ctx.invoke(cmd_platform_update, platforms=outdated_items) elif what == "libraries": ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [pm.package_dir] ctx.invoke(cmd_lib_update, libraries=outdated_items) click.echo() telemetry.send_event(category="Auto", action="Update", label=what.title()) click.echo("*" * terminal_width) click.echo("")
def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command.") click.echo("") 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 project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow") click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green")
def cli( ctx, project_dir, board, ide, # pylint: disable=R0913 disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command.") click.echo("") 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 project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow") click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) if (app.get_setting("enable_prompts") and not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(join(lib_dir, "readme.txt")): with open(join(lib_dir, "readme.txt"), "w") as f: f.write(""" This directory is intended for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file. The source code of each library should be placed in separate directory, like "lib/private_lib/[here are source files]". For example, see how can be organised `Foo` and `Bar` libraries: |--lib | |--Bar | | |--docs | | |--examples | | |--src | | |- Bar.c | | |- Bar.h | |--Foo | | |- Foo.c | | |- Foo.h | |- readme.txt --> THIS FILE |- platformio.ini |--src |- main.c Then in `src/main.c` you should use: #include <Foo.h> #include <Bar.h> // rest H/C/CPP code PlatformIO will find your libraries automatically, configure preprocessor's include paths and build them. See additional options for PlatformIO Library Dependency Finder `lib_*`: http://docs.platformio.org/en/latest/projectconf.html#lib-install """) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(ctx, project_file, board, disable_auto_uploading, env_prefix) if ide: pg = ProjectGenerator(project_dir, ide, board[0] if board else None) pg.generate() click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green")
def check_internal_updates(ctx, what): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24 if (time() - interval) < last_check.get(what + "_update", 0): return last_check[what + '_update'] = int(time()) app.set_state_item("last_check", last_check) pm = PlatformManager() if what == "platforms" else LibraryManager() outdated_items = [] for manifest in pm.get_installed(): if manifest['name'] in outdated_items: continue conds = [ pm.outdated(manifest['__pkg_dir']), what == "platforms" and PlatformFactory.newPlatform( manifest['__pkg_dir']).are_outdated_packages() ] if any(conds): outdated_items.append(manifest['name']) if not outdated_items: return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho("There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow") if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) click.secho("`platformio %s update`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False) click.secho(" command.\n", fg="yellow") click.secho( "If you want to manually check for the new versions " "without updating, please use ", fg="yellow", nl=False) click.secho("`platformio %s update --only-check`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False) click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": ctx.invoke(cmd_platform_update, platforms=outdated_items) elif what == "libraries": ctx.obj = pm ctx.invoke(cmd_lib_update, libraries=outdated_items) click.echo() telemetry.on_event(category="Auto", action="Update", label=what.title()) click.echo("*" * terminal_width) click.echo("")
def check_internal_updates(ctx, what): last_check = app.get_state_item("last_check", {}) interval = int(app.get_setting("check_%s_interval" % what)) * 3600 * 24 if (time() - interval) < last_check.get(what + "_update", 0): return last_check[what + '_update'] = int(time()) app.set_state_item("last_check", last_check) pm = PlatformManager() if what == "platforms" else LibraryManager() outdated_items = [] for manifest in pm.get_installed(): if manifest['name'] not in outdated_items and \ pm.is_outdated(manifest['name']): outdated_items.append(manifest['name']) if not outdated_items: return terminal_width, _ = click.get_terminal_size() click.echo("") click.echo("*" * terminal_width) click.secho( "There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow") if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) click.secho( "`platformio %s update`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False) click.secho(" command.\n", fg="yellow") click.secho( "If you want to manually check for the new versions " "without updating, please use ", fg="yellow", nl=False) click.secho( "`platformio %s update --only-check`" % ("lib --global" if what == "libraries" else "platform"), fg="cyan", nl=False) click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": ctx.invoke(cmd_platform_update, platforms=outdated_items) elif what == "libraries": ctx.obj = pm ctx.invoke(cmd_lib_update, libraries=outdated_items) click.echo() telemetry.on_event( category="Auto", action="Update", label=what.title()) click.echo("*" * terminal_width) click.echo("")