forked from linuxmint/mint-translations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·80 lines (71 loc) · 2.63 KB
/
update.py
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
#!/usr/bin/python3
import os
import sys
from git import Repo
SKIP = ["linuxmint-installation-guide", "mintubiquity", "slideshow-mint"]
CURR_DIR = os.getcwd()
FOREIGN_DIR = os.path.join(CURR_DIR, "po-export/FOREIGN")
WORKING_DIR = os.path.expanduser("~/Sandbox/translations/")
os.system("mkdir -p '%s'" % WORKING_DIR)
os.system("rm -rf '%s/*'" % WORKING_DIR)
def notify(message, submessage):
print(f"""
========================================
{message}
========================================
{submessage}
""")
def clone_or_reset(repo_name, parent_path):
os.chdir(parent_path)
if os.path.exists(repo_name):
# clean up repository
os.chdir(repo_name)
os.system("git checkout -f")
os.system("git clean -fd")
os.system("git checkout master")
os.system("git pull origin master")
else:
# clone repository from github
os.system("git clone [email protected]:linuxmint/%s.git" % repo_name)
os.chdir(repo_name)
def copy_translations(repo_name):
repo_path = os.path.join(WORKING_DIR, repo_name)
os.chdir(repo_path)
os.system(f"cp -R {FOREIGN_DIR}/{repo_name}/*.po {repo_path}/po/")
repo = Repo(repo_path)
if os.path.exists("po/LINGUAS"):
notify(repo_name.upper(), "Generate po/LINGUAS...")
os.system("rm po/LINGUAS")
for filename in sorted(os.listdir("po")):
if filename.endswith(".po"):
filename = filename.replace(".po", "")
os.system(f"echo {filename} >> po/LINGUAS")
os.system("git add *")
os.system("git commit -m 'l10n: Update translations'")
generate_scripts = []
for filename in os.listdir():
if filename.startswith("generate_"):
generate_scripts.append(filename)
if len(generate_scripts) > 0:
notify(repo_name.upper(), "Generating l10n files...")
os.system("rm -rf ../*.deb")
os.system("dpkg-buildpackage")
os.system("git checkout -f")
os.system("git clean -fd")
os.system("sudo dpkg -i ../*.deb")
for script in generate_scripts:
os.system(f"./{script}")
os.system("git commit -a -m 'l10n: Update files'")
os.system("git dch")
os.system("smerge ./")
os.system("gnome-terminal &")
notify(repo_name.upper(), "Press a key when ready to continue...")
input()
os.system(f"rm -rf '{FOREIGN_DIR}/{repo_name}'")
os.chdir(FOREIGN_DIR)
for project in sorted(os.listdir()):
if project in SKIP:
continue
notify(project.upper(), "Updating translations...")
clone_or_reset(project, WORKING_DIR)
copy_translations(project)