8
8
import semver
9
9
import subprocess
10
10
11
+ from typing import List , Dict
12
+
11
13
# $1: package name $2: version string
12
14
matching_patt = r'(.*?)-(\d.*?).zh_CN'
13
15
po_dl_url = 'https://translationproject.org/PO-files/{lang}/{fn}'
14
16
po_name = '{pkg}-{ver}.{lang}.po'
15
17
domain_url = 'https://translationproject.org/domain/index.html'
16
18
17
19
18
- def collect_local_info (dirname ):
20
+ def collect_local_info (dirname : str ):
19
21
files = []
20
22
for f in os .listdir (dirname ):
21
23
if not os .path .isfile (os .path .join (dirname , f )):
@@ -32,11 +34,11 @@ def collect_local_info(dirname):
32
34
return files
33
35
34
36
35
- def collect_remote_info ():
37
+ def collect_remote_info () -> Dict [ str , str ] :
36
38
parser = html5lib .HTMLParser (tree = html5lib .getTreeBuilder ("dom" ))
37
39
domain_data = requests .get (domain_url )
38
- domain_data = parser .parse (domain_data .text )
39
- nodes = domain_data .getElementsByTagName ('tbody' )[0 ]
40
+ parsed = parser .parse (domain_data .text )
41
+ nodes = parsed .getElementsByTagName ('tbody' )[0 ]
40
42
nodes = nodes .childNodes
41
43
head = True
42
44
remote_data = {}
@@ -57,8 +59,12 @@ def download_po(pkg, ver, lang, folder='.'):
57
59
po_file = po_name .format (pkg = pkg , ver = ver , lang = lang )
58
60
po_url = po_dl_url .format (lang = lang , fn = po_file )
59
61
logging .warning ('Downloading %s...' % po_file )
62
+ resp = requests .get (po_url )
63
+ if resp .status_code not in range (200 , 300 ):
64
+ logging .error ('Download error: %s' % resp .status_code )
65
+ return
60
66
with open (os .path .join (folder , po_file ), 'wt' ) as f :
61
- f .write (requests . get ( po_url ) .text )
67
+ f .write (resp .text )
62
68
63
69
64
70
def main ():
@@ -73,10 +79,12 @@ def main():
73
79
remote_ver = remote .get (f [0 ])
74
80
if not remote_ver :
75
81
logging .error ('Local file %s not found in remote data' % f [0 ])
82
+ continue
76
83
if f [1 ] == remote_ver :
77
84
continue
78
85
try :
79
86
if semver .compare (f [1 ], remote_ver ) >= 0 :
87
+ logging .info ('Local file %s is up to date' % f [0 ])
80
88
continue
81
89
except ValueError :
82
90
pass
0 commit comments