File: update.py

package info (click to toggle)
fontforge 1%3A20230101~dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 63,260 kB
  • sloc: ansic: 462,618; python: 6,916; cpp: 214; objc: 122; sh: 101; makefile: 55; xml: 11
file content (47 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

import pathlib
import subprocess
import sys


def update(potfile, pofile):
    header = []
    with open(pofile, encoding="utf-8") as fp:
        for l in fp:
            l = l.strip()
            if l.startswith("#"):
                header.append(l)
            else:
                break

    updated_trans = pathlib.Path("updates") / pathlib.Path(pofile).name

    print(f"Updating {pofile} with {potfile}...")

    cmd = ["msgmerge", "-N", "-s", pofile, potfile, "-o", pofile]
    if not updated_trans.exists():
        cmd.append("--for-msgfmt")
    subprocess.check_call(cmd)

    if updated_trans.exists():
        print(f"Updating {pofile} with {updated_trans}...")
        subprocess.check_call(
            ["msgmerge", "--for-msgfmt", "-s", str(updated_trans), pofile, "-o", pofile]
        )

    print(f"Reappending header to {pofile}...")
    with open(pofile, encoding="utf-8") as fp:
        data = fp.read()
    with open(pofile, "w", encoding="utf-8") as fp:
        print("\n".join(header), file=fp)
        fp.write(data)


def update_all(potfile):
    for f in pathlib.Path().glob("*.po"):
        update(potfile, str(f))


if __name__ == "__main__":
    update_all(sys.argv[1])