-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppa-metrics.py
executable file
·60 lines (53 loc) · 2.79 KB
/
ppa-metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# Refernce
# * https://api.launchpad.net/+apidoc/devel.html#binary_package_publishing_history
# * https://help.launchpad.net/API/launchpadlib
#
# apt install python3-launchpadlib python3-matplotlib
import argparse
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import operator
import os
import sys
from dateutil import parser
from launchpadlib.launchpad import Launchpad
if __name__ == "__main__":
cli = argparse.ArgumentParser()
cli.add_argument('--architecture', dest='architecture', nargs='?', default='amd64', help="Build architecture. (i386, amd64, armhf)")
cli.add_argument('--graphs', dest='graphs', action='store_true', help="Enable creation daily download graphs for each package in the PPA.")
cli.add_argument('--owner', dest='owner', help="PPA Owner. The acount/group that owns the PPA.", required=True)
cli.add_argument('--ppa', dest='ppa', help="PPA Name. The name of PPA to query.", required=True)
cli.add_argument('--release', dest='release', help="Ubuntu Release. (xenial, bionic)", required=True)
cli.set_defaults(graphs=False)
args = cli.parse_args()
CACHE = os.path.join(os.environ.get('HOME'), '.launchpadlib', 'cache')
API_URL = 'https://api.launchpad.net/devel/ubuntu/' + args.release + '/' + args.architecture
lp = Launchpad.login_anonymously('ppastat', 'production', CACHE)
ppa = lp.people[args.owner].getPPAByName(name=args.ppa)
published_packages = ppa.getPublishedBinaries(status='Published', distro_arch_series=API_URL)
debs = []
for package in published_packages:
download_count = package.getDownloadCount()
if download_count:
print('Processing ' + package.binary_package_name)
debs.append([download_count,'%s %s' % (package.binary_package_name,package.binary_package_version)])
if args.graphs:
print('Plotting ' + package.binary_package_name)
daily_stats = sorted(package.getDailyDownloadTotals().items(), key=operator.itemgetter(0))
for daily_stat in daily_stats:
#date = daily_stat[0]
datetime = parser.parse(daily_stat[0])
#datenum = dates.date2num(datetime)
#print(datetime)
#print(datenum)
downloads = daily_stat[1]
plt.xlabel('Date')
plt.ylabel('Downloads')
plt.plot(datetime,int(downloads))
# beautify the x-labels
plt.gcf().autofmt_xdate()
plt.savefig(package.binary_package_name + '-' + args.release + '.png')
debs_sorted = sorted(debs,key=lambda download_count: download_count[0],reverse=True)
for deb in debs_sorted:
print('%s:%s' % (deb[0], deb[1]))