def lib_install( # pylint: disable=too-many-arguments ctx, libraries, save, silent, interactive, force): storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY] storage_libdeps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, []) installed_manifests = {} for storage_dir in storage_dirs: if not silent and (libraries or storage_dir in storage_libdeps): print_storage_header(storage_dirs, storage_dir) lm = LibraryManager(storage_dir) if libraries: for library in libraries: pkg_dir = lm.install(library, silent=silent, interactive=interactive, force=force) installed_manifests[library] = lm.load_manifest(pkg_dir) elif storage_dir in storage_libdeps: builtin_lib_storages = None for library in storage_libdeps[storage_dir]: try: pkg_dir = lm.install(library, silent=silent, interactive=interactive, force=force) installed_manifests[library] = lm.load_manifest(pkg_dir) except exception.LibNotFound as e: if builtin_lib_storages is None: builtin_lib_storages = get_builtin_libs() if not silent or not is_builtin_lib( builtin_lib_storages, library): click.secho("Warning! %s" % e, fg="yellow") if not save or not libraries: return input_dirs = ctx.meta.get(CTX_META_INPUT_DIRS_KEY, []) project_environments = ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY] for input_dir in input_dirs: config = ProjectConfig.get_instance( os.path.join(input_dir, "platformio.ini")) config.validate(project_environments) for env in config.envs(): if project_environments and env not in project_environments: continue config.expand_interpolations = False lib_deps = config.get("env:" + env, "lib_deps", []) for library in libraries: if library in lib_deps: continue manifest = installed_manifests[library] try: assert library.lower() == manifest["name"].lower() assert semantic_version.Version(manifest["version"]) lib_deps.append("{name}@^{version}".format(**manifest)) except (AssertionError, ValueError): lib_deps.append(library) config.set("env:" + env, "lib_deps", lib_deps) config.save()
def lib_update(ctx, libraries, only_check, dry_run, json_output): storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY] only_check = dry_run or only_check json_result = {} for storage_dir in storage_dirs: if not json_output: print_storage_header(storage_dirs, storage_dir) lm = LibraryManager(storage_dir) _libraries = libraries if not _libraries: _libraries = [ manifest['__pkg_dir'] for manifest in lm.get_installed() ] if only_check and json_output: result = [] for library in _libraries: pkg_dir = library if isdir(library) else None requirements = None url = None if not pkg_dir: name, requirements, url = lm.parse_pkg_uri(library) pkg_dir = lm.get_package_dir(name, requirements, url) if not pkg_dir: continue latest = lm.outdated(pkg_dir, requirements) if not latest: continue manifest = lm.load_manifest(pkg_dir) manifest['versionLatest'] = latest result.append(manifest) json_result[storage_dir] = result else: for library in _libraries: lm.update(library, only_check=only_check) if json_output: return click.echo( dump_json_to_unicode(json_result[storage_dirs[0]] if len(storage_dirs) == 1 else json_result)) return True