blob: 20477f6f2a722b66e04f98e3be5516724e14bb1b (
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
|
#!/usr/bin/env python
import json
import urllib.request
import re
from pyalpm import vercmp
from functools import cmp_to_key
github_repo = "yairm210/Unciv"
from_pattern = r'(.*)-patch(\d+)'
to_pattern = r'\1.\2'
prefix = ''
def custom_preproc(vers):
# Sometimes, vers contains a `-XXX` suffix
# that is not covered by `from_pattern`.
if "-" in vers:
vers = vers.replace('-', '.')
if len(vers.split('.')) == 3:
return vers + '.REL'
else:
return vers
def remove_prefix(s, prefix):
if s.startswith(prefix):
return s[len(prefix):]
else:
return s
# Check github tags
# Replace by regex before sorting. This is not currently supported by nvchecker
req = urllib.request.Request('https://api.github.com/repos/{}/tags'.format(github_repo))
body = None
with urllib.request.urlopen(req) as res:
body = json.load(res)
versions = [ custom_preproc(remove_prefix(re.sub(from_pattern, to_pattern, it['name']), prefix)) for it in body ]
versions.sort(key=cmp_to_key(vercmp))
print(versions[-1])
|