Browse Source

Cleanup: move Translations file handling to separate function.

Also rename variable and remove commented devel code.
wip/archive
Mark Hindley 3 years ago
parent
commit
64ee267601
  1. 30
      amprolla_merge_translations.py

30
amprolla_merge_translations.py

@ -19,28 +19,30 @@ from lib.log import die, info
from lib.parse import parse_packages
from amprolla_merge import prepare_merge_dict
def parse_translations_file(filename):
"""
Decompresses and parses a Translations file and returns a dict
"""
tfile = bz2_open(filename).read()
tfile = tfile.decode('utf-8')
return parse_packages(tfile)
def merge_translations(filelist):
"""
Merges a list of Translation files and returns a dict of the merged files
"""
merged_trnsl = {}
for i in filelist[::-1]: # Slice list in reverse repo_order so Devuan is merged last.
if i is None:
for f in filelist[::-1]: # Slice list in reverse repo_order so Devuan is merged last.
if f is None:
continue
elif isfile(i):
tfile = bz2_open(i).read()
tfile = tfile.decode('utf-8')
trnsl = parse_packages(tfile)
elif isfile(f):
trnsl = parse_translations_file(f)
merged_trnsl.update(trnsl)
elif merged_trnsl and i == filelist[0]:
elif merged_trnsl and f == filelist[0]:
# In the absence of Devuan translations for forked packages, just
# remove upstream ones in case they are incorrect.
en_trnsl = join(dirname(i),'Translation-en.bz2')
tfile = bz2_open(en_trnsl).read()
tfile = tfile.decode('utf-8')
trnsl = parse_packages(tfile)
print("%s not found: removing upstream translations of forked packages" % i)
trnsl = parse_translations_file(join(dirname(f),'Translation-en.bz2'))
print("%s not found: removing upstream translations of forked packages" % f)
for k in trnsl.keys():
merged_trnsl.pop(k, None)
@ -102,10 +104,6 @@ def main():
for i in i18n:
transl.append('{}/i18n/Translation-{}.bz2'.format(component, i))
# Loop for devel
# for file in transl:
# main_merge(file)
# exit
mrgpool = Pool(cpunm)
mrgpool.map(main_merge, transl)
mrgpool.close()

Loading…
Cancel
Save