def get_api_result(url, params=None, data=None, auth=None, cache_valid=None): from platformio.app import ContentCache total = 0 max_retries = 5 cache_key = (ContentCache.key_from_args(url, params, data, auth) if cache_valid else None) while total < max_retries: try: with ContentCache() as cc: if cache_key: result = cc.get(cache_key) if result is not None: return json.loads(result) # check internet before and resolve issue with 60 seconds timeout internet_on(raise_exception=True) result = _get_api_result(url, params, data) if cache_valid: with ContentCache() as cc: cc.set(cache_key, result, cache_valid) return json.loads(result) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e: total += 1 if not PlatformioCLI.in_silence(): click.secho( "[API] ConnectionError: {0} (incremented retry: max={1}, " "total={2})".format(e, max_retries, total), fg="yellow") time.sleep(2 * total) raise exception.APIRequestError( "Could not connect to PlatformIO API Service. " "Please try later.")
def on_platformio_start(ctx, force, caller): app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) set_caller(caller) telemetry.on_command() if PlatformioCLI.in_silence(): return after_upgrade(ctx) if not ensure_python3(raise_exception=False): click.secho( """ Python 2 and Python 3.5 are not compatible with PlatformIO Core 5.0. Please check the migration guide on how to fix this warning message: """, fg="yellow", ) click.secho( "https://docs.platformio.org/en/latest/core/migration.html" "#drop-support-for-python-2-and-3-5", fg="blue", ) click.echo("")
def on_platformio_start(ctx, force, caller): app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) set_caller(caller) telemetry.on_command() if not PlatformioCLI.in_silence(): after_upgrade(ctx)
def on_platformio_start(ctx, force, caller): ensure_python3(raise_exception=True) app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) set_caller(caller) telemetry.on_command() if PlatformioCLI.in_silence(): return after_upgrade(ctx)
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 on_platformio_end(ctx, result): # pylint: disable=unused-argument if PlatformioCLI.in_silence(): return try: check_platformio_upgrade() check_internal_updates(ctx, "platforms") check_internal_updates(ctx, "libraries") except (exception.InternetIsOffline, exception.GetLatestVersionError, exception.APIRequestError): click.secho( "Failed to check for PlatformIO upgrades. " "Please check your Internet connection.", fg="red")
def load_manifest(self, src): path = src.path if isinstance(src, PackageItem) else src cache_key = "load_manifest-%s" % path result = self.memcache_get(cache_key) if result: return result candidates = ([ os.path.join(path, name) for name in self.manifest_names ] if os.path.isdir(path) else [path]) for item in candidates: if not os.path.isfile(item): continue try: result = ManifestParserFactory.new_from_file(item).as_dict() self.memcache_set(cache_key, result) return result except ManifestException as e: if not PlatformioCLI.in_silence(): self.print_message(str(e), fg="yellow") raise MissingPackageManifestError(", ".join(self.manifest_names))