Commit 0550fa72 authored by Oliver Smith's avatar Oliver Smith

new-devices-stats: several improvements (!73)

Several improvements I did while generating the list for the 600 days
blog post:

* Clone pmaports from https, not ssh.
* Do not crash when a device has multiple code names.
* More helpful error message when codename was not found in wiki: the
  error contains a list of all devices that were found.
* Add the "Thanks to: everyone who ported..." line in markdown output
* Embed the current git commit into the markdown output as comment, so
  we don't need to search for it when using the tool again in the next
  blog post.
* Embed the current command into the script.
* When generating markdown output, note which devices have been deleted
  (because that means they were renamed, and the renamed version needs
  to be manually taken off the "new devices" list!).
parent c9b27b0f
......@@ -8,6 +8,7 @@ import requests
import pmos_stats.chart as chart
import argparse
import re
import sys
cli = argparse.ArgumentParser(description="postmarketOS Stats generator")
subparsers = cli.add_subparsers(dest='subcommand')
......@@ -33,9 +34,14 @@ def argument(*name_or_flags, **kwargs):
def init():
if not os.path.isdir('pmaports'):
command = ['git', 'clone', '']
command = ['git', 'clone', '']
def get_current_commit():
command = ['git', 'rev-parse', 'HEAD']
stdout = subprocess.check_output(command)
return stdout.decode("utf-8").rstrip()
def get_commit_per_day(start_ref, end_ref):
command = ['git', 'log', '--reverse', '--ancestry-path', '{}..{}'.format(start_ref, end_ref)]
......@@ -94,9 +100,11 @@ def get_device_wiki_page(device):
clean = raw.encode('ascii', 'ignore').decode()
for row in json.loads(clean):
pagename = row['Page'].replace(' ', '_')
url = '{}'.format(pagename)
wiki_cache[row['Codename']] = url
for codename in row['Codename'].split(","):
codename = codename.strip()
pagename = row['Page'].replace(' ', '_')
url = '{}'.format(pagename)
wiki_cache[codename] = url
if device in ['nokia-n9', 'nokia-n950']:
return ''
......@@ -110,6 +118,13 @@ def get_device_wiki_page(device):
return ''
if device == 'semc-smultron':
return ''
if device not in wiki_cache:
print("ERROR: device " + device + " not found in wiki!")
print("NOTE: devices in wiki_cache: ")
return wiki_cache[device]
......@@ -141,10 +156,24 @@ def new_devices(args):
deleted = a - b
master = get_current_commit()
print("<!-- Generated with: 'pmos-stats " + " ".join(sys.argv[1:]) + "'")
print(" Current master (for next time): " + master + " -->")
for device in sorted(added):
name = get_device_name(device)
url = get_device_wiki_page(device)
print('* [{name} `{code}`]({url})'.format(name=name, code=device, url=url))
print('*Thanks to: everyone who ported these devices, see the'
' contributors section in each device\'s wiki page.*')
if deleted:
print("\nNOTE: the following devices have been deleted (renamed?),"
" don't forget to remove them from the list:")
for device in sorted(deleted):
print("\nSee also:")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment