- commit
- a861a15633ab711c25d45fd992cb1d64ef2248ff
- parent
- a2da84ff99d3fe40f5978bd11aeece2a98c417a6
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2017-02-07 21:31
add npm support
Diffstat
| M | project_stats.py | 38 | +++++++++++++++++++++++++++++++++++++- |
1 files changed, 37 insertions, 1 deletions
diff --git a/project_stats.py b/project_stats.py
@@ -20,7 +20,7 @@ except ImportError: 20 20 21 21 __version__ = '1.0.0' 22 2223 -1 SOURCES = ['github', 'gitlab', 'local', 'pypi', 'bower', 'travis']-1 23 SOURCES = ['github', 'gitlab', 'local', 'pypi', 'bower', 'npm', 'travis'] 24 24 25 25 KEYS = [ 26 26 'name', @@ -342,6 +342,42 @@ def get_bower(name): 342 342 } 343 343 344 344 -1 345 @async_cached('xi-project-npm', ttl=3600) -1 346 @asyncio.coroutine -1 347 def get_npm(name): -1 348 process = yield from asyncio.create_subprocess_exec( -1 349 'npm', 'view', name, -1 350 'name', -1 351 'version', -1 352 'homepage', -1 353 'description', -1 354 'license', -1 355 'time.created', -1 356 'time.modified', -1 357 stdout=asyncio.subprocess.PIPE, -1 358 stderr=asyncio.subprocess.PIPE) -1 359 stdout, stderr = yield from process.communicate() -1 360 if process.returncode != 0: -1 361 return -1 362 s = stdout.decode('utf8') -1 363 -1 364 data = {} -1 365 for line in s.splitlines(): -1 366 m = re.match("(.*) = '(.*)'", line) -1 367 if m: -1 368 key = m.groups()[0] -1 369 value = m.groups()[1] -1 370 -1 371 if key == 'time.created': -1 372 data['created'] = dt.parse(value) -1 373 elif key == 'time.modified': -1 374 data['updated'] = dt.parse(value) -1 375 else: -1 376 data[key] = value -1 377 -1 378 return data -1 379 -1 380 345 381 @asyncio.coroutine 346 382 def get_travis(url): 347 383 api_url = re.sub(