Debian Codegraph @

po/update.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import pathlib
4 import subprocess
5 import sys
6
7
8 def update(potfile, pofile):
9 header = []
10 with open(pofile, encoding="utf-8") as fp:
11 for l in fp:
12 l = l.strip()
13 if l.startswith("#"):
14 header.append(l)
15 else:
16 break
17
18 updated_trans = pathlib.Path("updates") / pathlib.Path(pofile).name
19
20 print(f"Updating {pofile} with {potfile}...")
21
22 cmd = ["msgmerge", "--no-wrap", "-N", "-s", pofile, potfile, "-o", pofile]
23 if not updated_trans.exists():
24 cmd.append("--for-msgfmt")
25 subprocess.check_call(cmd)
26
27 if updated_trans.exists():
28 print(f"Updating {pofile} with {updated_trans}...")
29 subprocess.check_call(
30 ["msgmerge", "--no-wrap", "--for-msgfmt", "-s", str(updated_trans), pofile, "-o", pofile]
31 )
32
33 print(f"Reappending header to {pofile}...")
34 with open(pofile, encoding="utf-8") as fp:
35 data = fp.read()
36 with open(pofile, "w", encoding="utf-8") as fp:
37 print("\n".join(header), file=fp)
38 fp.write(data)
39
40
41 def update_all(potfile):
42 for f in pathlib.Path().glob("*.po"):
43 update(potfile, str(f))
44
45
46 if __name__ == "__main__":
47 update_all(sys.argv[1])