def lib_update(ctx, libid): lm = LibraryManager() for id_, latest_version in (lm.get_latest_versions() or {}).items(): if libid and int(id_) not in libid: continue info = lm.get_info(int(id_)) click.echo("Updating [ %s ] %s library:" % ( click.style(id_, fg="yellow"), click.style(info['name'], fg="cyan"))) current_version = info['version'] if latest_version is None: click.secho("Unknown library", fg="red") continue click.echo("Versions: Current=%s, Latest=%s \t " % ( current_version, latest_version), nl=False) if current_version == latest_version: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) continue else: click.echo("[%s]" % (click.style("Out-of-date", fg="red"))) ctx.invoke(lib_uninstall, libid=[int(id_)]) ctx.invoke(lib_install, libid=[int(id_)])
def lib_install(ctx, libid, version): lm = LibraryManager(get_lib_dir()) for id_ in libid: click.echo( "Installing library [ %s ]:" % click.style(str(id_), fg="green")) try: if not lm.install(id_, version): continue info = lm.get_info(id_) click.secho( "The library #%s '%s' has been successfully installed!" % (str(id_), info['name']), fg="green") if "dependencies" in info: click.secho("Installing dependencies:", fg="yellow") _dependencies = info['dependencies'] if not isinstance(_dependencies, list): _dependencies = [_dependencies] for item in _dependencies: try: lib_install_dependency(ctx, item) except AssertionError: raise exception.LibInstallDependencyError(str(item)) except exception.LibAlreadyInstalledError: click.secho("Already installed", fg="yellow")
def lib_show(libid): lm = LibraryManager() info = lm.get_info(libid) click.secho(info['name'], fg="cyan") click.echo("-" * len(info['name'])) _authors = [] for author in info['authors']: _data = [] for key in ("name", "email", "url", "maintainer"): if not author[key]: continue if key == "email": _data.append("<%s>" % author[key]) elif key == "maintainer": _data.append("(maintainer)") else: _data.append(author[key]) _authors.append(" ".join(_data)) click.echo("Authors: %s" % ", ".join(_authors)) click.echo("Keywords: %s" % ", ".join(info['keywords'])) if "frameworks" in info: click.echo("Frameworks: %s" % ", ".join(info['frameworks'])) if "platforms" in info: click.echo("Platforms: %s" % ", ".join(info['platforms'])) click.echo("Version: %s" % info['version']) click.echo() click.echo(info['description']) click.echo()
def lib_install(ctx, libid, version): lm = LibraryManager() for id_ in libid: click.echo( "Installing library [ %s ]:" % click.style(str(id_), fg="green")) try: if not lm.install(id_, version): continue info = lm.get_info(id_) click.secho( "The library #%s '%s' has been successfully installed!" % (str(id_), info['name']), fg="green") if "dependencies" in info: click.secho("Installing dependencies:", fg="yellow") _dependencies = info['dependencies'] if not isinstance(_dependencies, list): _dependencies = [_dependencies] for item in _dependencies: try: lib_install_dependency(ctx, item) except AssertionError: raise exception.LibInstallDependencyError(str(item)) except exception.LibAlreadyInstalled: click.secho("Already installed", fg="yellow")
def lib_show(libid): lm = LibraryManager(get_lib_dir()) info = lm.get_info(libid) click.secho(info['name'], fg="cyan") click.echo("-" * len(info['name'])) _authors = [] for author in info['authors']: _data = [] for key in ("name", "email", "url", "maintainer"): if not author[key]: continue if key == "email": _data.append("<%s>" % author[key]) elif key == "maintainer": _data.append("(maintainer)") else: _data.append(author[key]) _authors.append(" ".join(_data)) click.echo("Authors: %s" % ", ".join(_authors)) click.echo("Keywords: %s" % ", ".join(info['keywords'])) if "frameworks" in info: click.echo("Frameworks: %s" % ", ".join(info['frameworks'])) if "platforms" in info: click.echo("Platforms: %s" % ", ".join(info['platforms'])) click.echo("Version: %s" % info['version']) click.echo() click.echo(info['description']) click.echo()
def lib_uninstall(libid): lm = LibraryManager(get_lib_dir()) for id_ in libid: info = lm.get_info(id_) if lm.uninstall(id_): click.secho("The library #%s '%s' has been successfully " "uninstalled!" % (str(id_), info['name']), fg="green")
def lib_update(): lm = LibraryManager(get_lib_dir()) lib_ids = [str(item['id']) for item in lm.get_installed().values()] if not lib_ids: return versions = get_api_result("/lib/version/" + str(",".join(lib_ids))) for id_ in lib_ids: info = lm.get_info(int(id_)) click.echo("Updating [ %s ] %s library:" % ( click.style(id_, fg="yellow"), click.style(info['name'], fg="cyan"))) current_version = info['version'] latest_version = versions[id_] if latest_version is None: click.secho("Unknown library", fg="red") continue click.echo("Versions: Current=%s, Latest=%s \t " % ( current_version, latest_version), nl=False) if current_version == latest_version: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) continue else: click.echo("[%s]" % (click.style("Out-of-date", fg="red"))) lib_uninstall([int(id_)]) lib_install([int(id_)])
def lib_update(): lm = LibraryManager(get_lib_dir()) lib_ids = [str(item['id']) for item in lm.get_installed().values()] if not lib_ids: return versions = get_api_result("/lib/version/" + str(",".join(lib_ids))) for id_ in lib_ids: info = lm.get_info(int(id_)) click.echo("Updating [ %s ] %s library:" % (click.style( id_, fg="yellow"), click.style(info['name'], fg="cyan"))) current_version = info['version'] latest_version = versions[id_] if latest_version is None: click.secho("Unknown library", fg="red") continue click.echo("Versions: Current=%s, Latest=%s \t " % (current_version, latest_version), nl=False) if current_version == latest_version: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) continue else: click.echo("[%s]" % (click.style("Out-of-date", fg="red"))) lib_uninstall([int(id_)]) lib_install([int(id_)])
def lib_update(ctx, libid): lm = LibraryManager() for id_, latest_version in (lm.get_latest_versions() or {}).items(): if libid and int(id_) not in libid: continue info = lm.get_info(int(id_)) click.echo("Updating [ %s ] %s library:" % (click.style( id_, fg="yellow"), click.style(info['name'], fg="cyan"))) current_version = info['version'] if latest_version is None: click.secho("Unknown library", fg="red") continue click.echo("Versions: Current=%s, Latest=%s \t " % (current_version, latest_version), nl=False) if current_version == latest_version: click.echo("[%s]" % (click.style("Up-to-date", fg="green"))) continue else: click.echo("[%s]" % (click.style("Out-of-date", fg="red"))) ctx.invoke(lib_uninstall, libid=[int(id_)]) ctx.invoke(lib_install, libid=[int(id_)])
def lib_uninstall(libid): lm = LibraryManager() for id_ in libid: info = lm.get_info(id_) if lm.uninstall(id_): click.secho("The library #%s '%s' has been successfully " "uninstalled!" % (str(id_), info['name']), fg="green")
def lib_list(): lm = LibraryManager(get_lib_dir()) items = lm.get_installed().values() if not items: return echo_liblist_header() for item in items: item['authornames'] = [i['name'] for i in item['authors']] echo_liblist_item(item)
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 lib_list(json_output): lm = LibraryManager() items = lm.get_installed().values() if json_output: click.echo(json.dumps(items)) return if not items: return echo_liblist_header() for item in sorted(items, key=lambda i: i['id']): item['authornames'] = [i['name'] for i in item['authors']] echo_liblist_item(item)
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)