-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregenerate-sources
executable file
·81 lines (67 loc) · 2.62 KB
/
regenerate-sources
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
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2020 Pier Luigi Fiorini <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import glob
import os
import json
import subprocess
import shlex
import shutil
import sys
def run(cmd, **kwargs):
out = []
for c in cmd:
out.append(shlex.quote(c))
print('+ ' + repr(' '.join(out))[1:-1])
return subprocess.run(cmd, **kwargs)
def remove_line(filename, pattern):
tmp_filename = filename + '.tmp'
cat = subprocess.Popen(['cat', filename], stdout=subprocess.PIPE)
with open(tmp_filename, 'w') as f:
egrep = subprocess.Popen(['egrep', '-v', pattern], stdin=cat.stdout, stdout=f)
egrep.communicate()
shutil.move(tmp_filename, filename)
def main():
github_workspace = os.environ['GITHUB_WORKSPACE']
sources_path = os.environ.get('INPUT_SOURCES_PATH') or os.path.join(github_workspace, '.tx', 'sources.json')
os.chdir(github_workspace)
with open(sources_path, 'r') as f:
sources = json.load(f)
for entry in sources:
process_entry(entry)
def process_entry(entry):
for key in ('type', 'output_path'):
if key not in entry:
print('Entry doesn\'t have "%s": skipping' % key, file=sys.stderr)
return
if entry['type'] == 'ts':
if 'directory' not in entry:
print('Entry doesn\'t have "directory": skipping', file=sys.stderr)
return
elif entry['type'] in ('desktop', 'metainfo'):
for key in ('source_file', 'file_filter'):
if key not in entry:
print('Entry doesn\'t have "%s": skipping' % key, file=sys.stderr)
return
else:
# This is an entry that we don't care about
return
if entry['type'] == 'ts':
directory = entry['directory']
output_path = entry['output_path']
run(['lupdate-qt6', directory, '-ts', '-no-obsolete', output_path], check=True)
run(['git', 'add', output_path], check=True)
elif entry['type'] == 'desktop':
source_file = entry['source_file']
output_path = entry['output_path']
run(['desktop-to-pot', source_file, output_path], check=True)
run(['git', 'add', output_path], check=True)
elif entry['type'] == 'metainfo':
source_file = entry['source_file']
output_path = entry['output_path']
run(['itstool', '-i', '/usr/share/translation-action/as-metainfo.its', '-o', output_path, source_file], check=True)
remove_line(output_path, '^"POT-Creation-Date')
run(['git', 'add', output_path], check=True)
if __name__ == '__main__':
main()