From 7d4ab39591b7c67c951644017f03bacd4cd30094 Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sat, 16 Aug 2014 06:00:11 +0200 Subject: [PATCH] prfromtransifex.py didn't add new translations to resource files. --- prfromtransifex.ini | 26 ++++++++++++++++++++++---- prfromtransifex.py | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/prfromtransifex.ini b/prfromtransifex.ini index 42933e0..6a5bab2 100644 --- a/prfromtransifex.ini +++ b/prfromtransifex.ini @@ -41,19 +41,37 @@ body = New translation updates available from transifex ; %(minpercent)s See transifex.minpercent above ; %(langcount)d Number of languages matched with given settings commit = Transifex translation update + Mode: %(mode)s Minimum percent translated: %(minpercent)s Matched %(langcount)d languages [misc] -; File to store language bookkeeping data in +; pri file to store language bookkeeping data in ; Will be re-written and commited to the repository ; if changes occur. -file = src/mumble/translations.pri +prifile = src/mumble/translations.pri ; Template to generate file from, available variables $(files)s ; for a space separated list of all files. -template = # Do not change manually +pritemplate = # Do not change manually # Autogenerated by mumble transifex bot TRANSLATIONS = %(files)s + +; qtc file to store language bookkeeping data in +; Will be re-written and commited to the repository +; if changes occur. +qrcfile = src/mumble/mumble_translations.qrc +; Template to generate file from, available variables $(files)s +; for a space separated list of all files. +qrctemplate = + + + %(files)s + + + ; Space separated translation files not retrieved from transifex -additionaltsfiles = mumble_en.ts +additionaltsfiles = mumble_en.ts \ No newline at end of file diff --git a/prfromtransifex.py b/prfromtransifex.py index 389c872..90297b5 100755 --- a/prfromtransifex.py +++ b/prfromtransifex.py @@ -116,8 +116,10 @@ if __name__ == "__main__": pr_body = cfg.get('pullrequest', 'body') pr_commit = cfg.get('pullrequest', 'commit') - translationsfile = cfg.get('misc', 'file') - translationstemplate = cfg.get('misc', 'template') + prifile = cfg.get('misc', 'prifile') + pritemplate = cfg.get('misc', 'pritemplate') + qrcfile = cfg.get('misc', 'qrcfile') + qrctemplate = cfg.get('misc', 'qrctemplate') additionaltsfiles = cfg.get('misc', 'additionaltsfiles') if args.setup or not os.path.exists(wr_path): @@ -161,28 +163,44 @@ if __name__ == "__main__": debug(git["reset", remote + "/" + branch, "--hard"]()) info("Cleaning repository") debug(git["clean", "-f", "-x", "-d"]()) - info("Pulling translations") + info("Pulling translations") txout = tx["pull", "-f", "-a", "--mode=" + mode, "--minimum-perc=" + minpercent]() debug(txout) - tfilepath = os.path.join(wr_path, translationsfile) - info("Updating translations listing file '%s'", tfilepath) + # Add all .ts files tx pull got to repo paths, files = zip(*re.findall(r"^\s->\s[\w_]+:\s([\w/\_]+/([\w_]+\.ts))$", txout, flags=re.MULTILINE)) debug(git["add"](*paths)) - translations = additionaltsfiles + " " + (" ".join(sorted(files))) - with open(tfilepath, "w") as f: - f.write(translationstemplate % {'files': translations}) - - debug(git["add"](tfilepath)) - + # Add additional ts files not in control of transifex (e.g. English source translation) + files = list(files) + files.extend(additionaltsfiles.split(" ")) + files.sort() + + # Write pri file listing ts files for build + prifilepath = os.path.join(wr_path, prifile) + info("Updating translations listing file '%s'", prifilepath) + tsfiles = (" ".join(files)) + with open(prifilepath, "w") as f: + f.write(pritemplate % {'files': tsfiles}) + debug(git["add"](prifilepath)) + + # Write qrc file listing qm files built from ts files for build + qrcfilepath = os.path.join(wr_path, qrcfile) + info("Updating translations listing file '%s'", qrcfilepath) + tstoqm = lambda f: " %s" % re.sub(r"(^.*)\.ts$", r"\1.qm", f) + qmfiles = os.linesep.join([tstoqm(f) for f in files]) + with open(qrcfilepath, "w") as f: + f.write(qrctemplate % {'files': qmfiles}) + debug(git["add"](qrcfilepath)) + + # Check if the repo changed debug("Checking for modifications") changed, changedfiles, _ = git["diff", "--cached", "--name-only", "--exit-code"].run(retcode=(0,1)) if not changed: info("No changes to translations, done") sys.exit(0) - + debug("Changed files: %s", " ".join(os.linesep.split(changedfiles))) info("Things changed & force pushing")