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
61
62
63
64
65
66
67
68
|
#!/usr/bin/env python3
# This simple script is collecting details about the packages in Alpine Linux.
#
# This script can be used to do stuff for the Trivia page.
# http://wiki.alpinelinux.org/wiki/Trivia
#
# Licensed under GPLv2
#
# Copyright (c) 2012-2018 Fabian Affolter <fabian at affolter-engineering.ch>
import os
import sys
import tarfile
import requests
def grab(url):
"""Collect the data."""
response = requests.get(url, timeout=30)
with open('APKINDEX.tar.gz', 'wb') as archive:
archive.write(response.content)
archive.close()
tar = tarfile.open('APKINDEX.tar.gz')
tar.extract('APKINDEX', path=".")
tar.close()
countStd = 0
countDev = 0
countDoc = 0
countLib = 0
countCom = 0
total = 0
fobj = open('APKINDEX', 'r')
for line in fobj:
if line.startswith('P'):
if line[len(line)-4:len(line)-1] == 'dev':
countDev = countDev + 1
elif line[len(line)-4:len(line)-1] == 'doc':
countDoc = countDoc + 1
elif line[len(line)-5:len(line)-1] == 'libs':
countLib = countLib + 1
else:
countStd = countStd + 1
fobj.close()
total = countStd + countDev + countDoc + countLib
numbers = (countStd, countDev, countDoc, countLib, total)
return numbers
def clean():
"""Clean up after a run."""
os.remove('APKINDEX.tar.gz')
os.remove('APKINDEX')
def main(argv):
"""The main part of the script."""
url = 'http://nl.alpinelinux.org/alpine/v{}/main/x86_64/APKINDEX.tar.gz'.format(argv)
numbers = grab(url)
print("| '''{}'''\n| {}\n| {}\n| {}\n| {}\n| {}\n|-".format(
argv, numbers[4], numbers[0], numbers[1], numbers[2], numbers[3]))
clean()
if __name__ == "__main__":
main(sys.argv[1])
|