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) http.ensure_internet_on(raise_exception=True) # Update PlatformIO's Core packages update_core_packages(silent=True) latest_version = get_latest_version() if pepver_to_semver(latest_version) <= 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("")
async def fetch_content(uri, data=None, headers=None, cache_valid=None): if not headers: headers = { "User-Agent": ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) " "AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 " "Safari/603.3.8") } cache_key = ContentCache.key_from_args(uri, data) if cache_valid else None with ContentCache() as cc: if cache_key: result = cc.get(cache_key) if result is not None: return result # check internet before and resolve issue with 60 seconds timeout ensure_internet_on(raise_exception=True) session = helpers.requests_session() if data: r = await session.post(uri, data=data, headers=headers, timeout=__default_requests_timeout__) else: r = await session.get(uri, headers=headers, timeout=__default_requests_timeout__) r.raise_for_status() result = r.text if cache_valid: with ContentCache() as cc: cc.set(cache_key, result, cache_valid) return result
def update( # pylint: disable=too-many-arguments self, from_spec, to_spec=None, only_check=False, silent=False, show_incompatible=True, ): pkg = self.get_package(from_spec) if not pkg or not pkg.metadata: raise UnknownPackageError(from_spec) if not silent: click.echo( "{} {:<45} {:<35}".format( "Checking" if only_check else "Updating", click.style(pkg.metadata.spec.humanize(), fg="cyan"), "%s @ %s" % (pkg.metadata.version, to_spec.requirements) if to_spec and to_spec.requirements else str(pkg.metadata.version), ), nl=False, ) if not ensure_internet_on(): if not silent: click.echo("[%s]" % (click.style("Off-line", fg="yellow"))) return pkg outdated = self.outdated(pkg, to_spec) if not silent: self.print_outdated_state(outdated, only_check, show_incompatible) if only_check or not outdated.is_outdated(allow_incompatible=False): return pkg try: self.lock() return self._update(pkg, outdated, silent=silent) finally: self.unlock()
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("")