summaryrefslogtreecommitdiff
path: root/scripts/outdated.py
blob: a6dd3ef3e7e3560f2a4f3637d7eca19fa2345e47 (plain)
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
import collections
import json
import os
import subprocess
import sys
import urllib.request

names = {
	'awk': 'nawk',
	'bc': 'bc-gh',
	'hostap': 'wpa-supplicant',
	'lpeg': 'lua:lpeg',
	'lua': 'lua52',
	'python': 'python3',
	'st': 'st-term',
	'terminus-font': 'fonts:terminus',
	'the_silver_searcher': 'the-silver-searcher',
	'tz': 'tzdata',
}
skip = set([
	'adobe-source-fonts',
	'cproc',
	'libutp',
	'mc',
	'openbsd',
	'qbe',
	'sbase',
	'sdhcp',
	'skeleton',
	'st',
	'swc',
	'ubase',
	'velox',
	'wld',
])

p = subprocess.Popen(['git', '-C', 'pkg', 'ls-tree', 'HEAD'], stdout=subprocess.PIPE)
for line in p.stdout:
	fields = line.decode().split()
	if fields[1] != 'tree' or fields[3] in skip:
		continue
	name = fields[3]
	with open('pkg/{}/ver'.format(name), 'r') as f:
		oldver = f.read().rsplit(maxsplit=1)[0]
	proj = names.get(name, name)
	with urllib.request.urlopen('https://repology.org/api/v1/project/{}'.format(proj)) as response:
		pkgs = json.loads(response.read())
	newest = collections.Counter()
	for pkg in pkgs:
		if pkg['status'] == 'newest':
			newest[pkg['version']] += 1
	if not newest:
		print('could not find newest version of {}'.format(proj), file=sys.stderr)
		continue
	newver = newest.most_common(1)[0][0]
	if oldver != newver:
		print('{:20} {:16} => {:16}'.format(name, oldver, newver))
if p.wait():
	raise CalledProcessError(p.retcode, p.args)