def lib_stats(json_output): result = util.get_api_result("/lib/stats", cache_valid="1h") if json_output: return click.echo(dump_json_to_unicode(result)) for key in ("updated", "added"): tabular_data = [( click.style(item["name"], fg="cyan"), time.strftime("%c", util.parse_date(item["date"])), "https://platformio.org/lib/show/%s/%s" % (item["id"], quote(item["name"])), ) for item in result.get(key, [])] table = tabulate( tabular_data, headers=[ click.style("RECENTLY " + key.upper(), bold=True), "Date", "URL" ], ) click.echo(table) click.echo() for key in ("lastkeywords", "topkeywords"): tabular_data = [( click.style(name, fg="cyan"), "https://platformio.org/lib/search?query=" + quote("keyword:%s" % name), ) for name in result.get(key, [])] table = tabulate( tabular_data, headers=[ click.style( ("RECENT" if key == "lastkeywords" else "POPULAR") + " KEYWORDS", bold=True, ), "URL", ], ) click.echo(table) click.echo() for key, title in (("dlday", "Today"), ("dlweek", "Week"), ("dlmonth", "Month")): tabular_data = [( click.style(item["name"], fg="cyan"), "https://platformio.org/lib/show/%s/%s" % (item["id"], quote(item["name"])), ) for item in result.get(key, [])] table = tabulate( tabular_data, headers=[ click.style("FEATURED: " + title.upper(), bold=True), "URL" ], ) click.echo(table) click.echo() return True
def _print_lib_item(item): date = str( time.strftime("%c", util.parse_date(item['date'])) if "date" in item else "") url = click.style("https://platformio.org/lib/show/%s/%s" % (item['id'], quote(item['name'])), fg="blue") click.echo( (printitemdate_tpl if "date" in item else printitem_tpl).format( name=click.style(item['name'], fg="cyan"), date=date, url=url))
def _print_lib_item(item): date = str( time.strftime("%c", util.parse_date(item['date'])) if "date" in item else "") url = click.style( "https://platformio.org/lib/show/%s/%s" % (item['id'], quote(item['name'])), fg="blue") click.echo( (printitemdate_tpl if "date" in item else printitem_tpl).format( name=click.style(item['name'], fg="cyan"), date=date, url=url))
def _cmp_dates(datestr1, datestr2): date1 = util.parse_date(datestr1) date2 = util.parse_date(datestr2) if date1 == date2: return 0 return -1 if date1 < date2 else 1
def _cmp_dates(datestr1, datestr2): date1 = util.parse_date(datestr1) date2 = util.parse_date(datestr2) if date1 == date2: return 0 return -1 if date1 < date2 else 1
def lib_show(library, json_output): lm = LibraryManager() name, requirements, _ = lm.parse_pkg_uri(library) lib_id = lm.search_lib_id({ "name": name, "requirements": requirements }, silent=json_output, interactive=not json_output) lib = util.get_api_result("/lib/info/%d" % lib_id, cache_valid="1d") if json_output: return click.echo(dump_json_to_unicode(lib)) click.secho(lib['name'], fg="cyan") click.echo("=" * len(lib['name'])) click.secho("#ID: %d" % lib['id'], bold=True) click.echo(lib['description']) click.echo() click.echo( "Version: %s, released %s" % (lib['version']['name'], time.strftime("%c", util.parse_date(lib['version']['released'])))) click.echo("Manifest: %s" % lib['confurl']) for key in ("homepage", "repository", "license"): if key not in lib or not lib[key]: continue if isinstance(lib[key], list): click.echo("%s: %s" % (key.title(), ", ".join(lib[key]))) else: click.echo("%s: %s" % (key.title(), lib[key])) blocks = [] _authors = [] for author in lib.get("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)) if _authors: blocks.append(("Authors", _authors)) blocks.append(("Keywords", lib['keywords'])) for key in ("frameworks", "platforms"): if key not in lib or not lib[key]: continue blocks.append(("Compatible %s" % key, [i['title'] for i in lib[key]])) blocks.append(("Headers", lib['headers'])) blocks.append(("Examples", lib['examples'])) blocks.append(("Versions", [ "%s, released %s" % (v['name'], time.strftime("%c", util.parse_date(v['released']))) for v in lib['versions'] ])) blocks.append(("Unique Downloads", [ "Today: %s" % lib['dlstats']['day'], "Week: %s" % lib['dlstats']['week'], "Month: %s" % lib['dlstats']['month'] ])) for (title, rows) in blocks: click.echo() click.secho(title, bold=True) click.echo("-" * len(title)) for row in rows: click.echo(row) return True
def lib_show(library, json_output): lm = LibraryManager() name, requirements, _ = lm.parse_pkg_uri(library) lib_id = lm.search_lib_id({ "name": name, "requirements": requirements }, silent=json_output, interactive=not json_output) lib = get_api_result("/lib/info/%d" % lib_id, cache_valid="1d") if json_output: return click.echo(json.dumps(lib)) click.secho(lib['name'], fg="cyan") click.echo("=" * len(lib['name'])) click.secho("#ID: %d" % lib['id'], bold=True) click.echo(lib['description']) click.echo() click.echo( "Version: %s, released %s" % (lib['version']['name'], time.strftime("%c", util.parse_date(lib['version']['released'])))) click.echo("Manifest: %s" % lib['confurl']) for key in ("homepage", "repository", "license"): if key not in lib or not lib[key]: continue if isinstance(lib[key], list): click.echo("%s: %s" % (key.title(), ", ".join(lib[key]))) else: click.echo("%s: %s" % (key.title(), lib[key])) blocks = [] _authors = [] for author in lib.get("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)) if _authors: blocks.append(("Authors", _authors)) blocks.append(("Keywords", lib['keywords'])) for key in ("frameworks", "platforms"): if key not in lib or not lib[key]: continue blocks.append(("Compatible %s" % key, [i['title'] for i in lib[key]])) blocks.append(("Headers", lib['headers'])) blocks.append(("Examples", lib['examples'])) blocks.append(("Versions", [ "%s, released %s" % (v['name'], time.strftime("%c", util.parse_date(v['released']))) for v in lib['versions'] ])) blocks.append(("Unique Downloads", [ "Today: %s" % lib['dlstats']['day'], "Week: %s" % lib['dlstats']['week'], "Month: %s" % lib['dlstats']['month'] ])) for (title, rows) in blocks: click.echo() click.secho(title, bold=True) click.echo("-" * len(title)) for row in rows: click.echo(row) return True
def lib_show(library, json_output): lm = LibraryPackageManager() lib_id = lm.reveal_registry_package_id(library, silent=json_output) regclient = lm.get_registry_client_instance() lib = regclient.fetch_json_data("get", "/v2/lib/info/%d" % lib_id, cache_valid="1h") if json_output: return click.echo(dump_json_to_unicode(lib)) title = "{ownername}/{name}".format(**lib) click.secho(title, fg="cyan") click.echo("=" * len(title)) click.echo(lib["description"]) click.echo() click.secho("ID: %d" % lib["id"]) click.echo( "Version: %s, released %s" % ( lib["version"]["name"], time.strftime("%c", util.parse_date(lib["version"]["released"])), ) ) click.echo("Manifest: %s" % lib["confurl"]) for key in ("homepage", "repository", "license"): if key not in lib or not lib[key]: continue if isinstance(lib[key], list): click.echo("%s: %s" % (key.title(), ", ".join(lib[key]))) else: click.echo("%s: %s" % (key.title(), lib[key])) blocks = [] _authors = [] for author in lib.get("authors", []): _data = [] for key in ("name", "email", "url", "maintainer"): if not author.get(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)) if _authors: blocks.append(("Authors", _authors)) blocks.append(("Keywords", lib["keywords"])) for key in ("frameworks", "platforms"): if key not in lib or not lib[key]: continue blocks.append(("Compatible %s" % key, [i["title"] for i in lib[key]])) blocks.append(("Headers", lib["headers"])) blocks.append(("Examples", lib["examples"])) blocks.append( ( "Versions", [ "%s, released %s" % (v["name"], time.strftime("%c", util.parse_date(v["released"]))) for v in lib["versions"] ], ) ) blocks.append( ( "Unique Downloads", [ "Today: %s" % lib["dlstats"]["day"], "Week: %s" % lib["dlstats"]["week"], "Month: %s" % lib["dlstats"]["month"], ], ) ) for (title, rows) in blocks: click.echo() click.secho(title, bold=True) click.echo("-" * len(title)) for row in rows: click.echo(row) return True