PlatformIO Library Registry statistics with new pio lib stats

This commit is contained in:
Ivan Kravets
2016-12-23 21:57:11 +02:00
parent ede581182c
commit c504001f04
7 changed files with 98 additions and 13 deletions

View File

@ -4,9 +4,16 @@ Release Notes
PlatformIO 3.0 PlatformIO 3.0
-------------- --------------
3.2.2 (2016-12-??) 3.3.0 (2016-12-??)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
* PlatformIO Library Registry statistics with new
`pio lib stats <http://docs.platformio.org/page/userguide/lib/cmd_stats.html>`__ command
- Recently updated and added libraries
- Recent and popular keywords
- Featured libraries (today, week, month)
* Added support for templated methods in ``*.ino to *.cpp`` convertor * Added support for templated methods in ``*.ino to *.cpp`` convertor
(`pull #858 <https://github.com/platformio/platformio-core/pull/858>`_) (`pull #858 <https://github.com/platformio/platformio-core/pull/858>`_)
* Produce less noisy output when ``-s/--silent`` options are used for * Produce less noisy output when ``-s/--silent`` options are used for

2
docs

Submodule docs updated: c3780c6913...fb1008d660

View File

@ -14,7 +14,7 @@
import sys import sys
VERSION = (3, 2, "2a1") VERSION = (3, 3, "0a1")
__version__ = ".".join([str(s) for s in VERSION]) __version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio" __title__ = "platformio"

View File

@ -325,7 +325,7 @@ def get_cid():
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
pass pass
cid = str( cid = str(
uuid.UUID(bytes=hashlib.md5( uuid.UUID(bytes=hashlib.md5(str(_uid if _uid else uuid.getnode()))
str(_uid if _uid else uuid.getnode())).digest())) .digest()))
set_state_item("cid", cid) set_state_item("cid", cid)
return cid return cid

View File

@ -13,8 +13,10 @@
# limitations under the License. # limitations under the License.
import json import json
from datetime import datetime
from os.path import join from os.path import join
from time import sleep from time import sleep
from urllib import quote
import click import click
@ -44,7 +46,7 @@ from platformio.util import get_api_result
@click.pass_context @click.pass_context
def cli(ctx, **options): def cli(ctx, **options):
# skip commands that don't need storage folder # skip commands that don't need storage folder
if ctx.invoked_subcommand in ("search", "register") or \ if ctx.invoked_subcommand in ("search", "register", "stats") or \
(len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")): (len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
return return
storage_dir = options['storage_dir'] storage_dir = options['storage_dir']
@ -116,7 +118,7 @@ def lib_update(lm, libraries, only_check):
####### #######
LIBLIST_TPL = ("[{id:^14}] {name:<25} {compatibility:<30} " LIBLIST_TPL = ("[{id:^15}] {name:<25} {compatibility:<30} "
"\"{authornames}\": {description}") "\"{authornames}\": {description}")
@ -317,3 +319,81 @@ def lib_register(config_url):
result['message'], result['message'],
fg="green" fg="green"
if "successed" in result and result['successed'] else "red") if "successed" in result and result['successed'] else "red")
@cli.command("stats", short_help="Library Registry Statistics")
@click.option("--json-output", is_flag=True)
def lib_stats(json_output):
result = get_api_result("/lib/stats", cache_valid="1h")
if json_output:
return click.echo(json.dumps(result))
printitem_tpl = "{name:<33} {url}"
printitemdate_tpl = "{name:<33} {date:23} {url}"
def _print_title(title):
click.secho(title.upper(), bold=True)
click.echo("*" * len(title))
def _print_header(with_date=False):
click.echo((printitemdate_tpl if with_date else printitem_tpl).format(
name=click.style(
"Name", fg="cyan"),
date="Date",
url=click.style(
"Url", fg="blue")))
terminal_width, _ = click.get_terminal_size()
click.echo("-" * terminal_width)
def _print_lib_item(item):
click.echo((printitemdate_tpl
if "date" in item else printitem_tpl).format(
name=click.style(
item['name'], fg="cyan"),
date=str(
datetime.strptime(item['date'].replace("Z", "UTC"),
"%Y-%m-%dT%H:%M:%S%Z")
if "date" in item else ""),
url=click.style(
"http://platformio.org/lib/show/%s/%s" % (item[
'id'], quote(item['name'])),
fg="blue")))
def _print_tag_item(name):
click.echo(
printitem_tpl.format(
name=click.style(
name, fg="cyan"),
url=click.style(
"http://platformio.org/lib/search?query=" + quote(
"keyword:%s" % name),
fg="blue")))
for key in ("updated", "added"):
_print_title("Recently " + key)
_print_header(with_date=True)
for item in result.get(key, []):
_print_lib_item(item)
click.echo()
_print_title("Recent keywords")
_print_header(with_date=False)
for item in result.get("lastkeywords"):
_print_tag_item(item)
click.echo()
_print_title("Popular keywords")
_print_header(with_date=False)
for item in result.get("topkeywords"):
_print_tag_item(item)
click.echo()
for key, title in (("dlday", "Today"), ("dlweek", "Week"),
("dlmonth", "Month")):
_print_title("Featured: " + title)
_print_header(with_date=False)
for item in result.get(key, []):
_print_lib_item(item)
click.echo()

View File

@ -141,9 +141,8 @@ def platform_list(json_output):
"url": p.vendor_url, "url": p.vendor_url,
# "packages": p.packages.keys(), # dump all packages # "packages": p.packages.keys(), # dump all packages
"packages": p.get_installed_packages().keys(), "packages": p.get_installed_packages().keys(),
'forDesktop': any([ 'forDesktop':
p.name.startswith(n) for n in ("native", "linux", "windows") any([p.name.startswith(n) for n in ("native", "linux", "windows")])
])
}) })
if json_output: if json_output:

View File

@ -177,9 +177,8 @@ class SvnClient(VCSClientBase):
return self.run_cmd(args) return self.run_cmd(args)
def get_current_revision(self): def get_current_revision(self):
output = self.get_cmd_output([ output = self.get_cmd_output(
"info", "--non-interactive", "--trust-server-cert", "-r", "HEAD" ["info", "--non-interactive", "--trust-server-cert", "-r", "HEAD"])
])
for line in output.split("\n"): for line in output.split("\n"):
line = line.strip() line = line.strip()
if line.startswith("Revision:"): if line.startswith("Revision:"):