mirror of
https://github.com/etlegacy/LegacyTransifexBot.git
synced 2024-11-21 20:01:36 +00:00
Fix prfromtransifex.py script.
As expected the script still had a lot of bugs. This fixes various syntax and logical flaws.
This commit is contained in:
parent
c658a41775
commit
b31a39a3e6
2 changed files with 54 additions and 43 deletions
|
@ -3,6 +3,8 @@
|
|||
user = MumbleTransifexBot
|
||||
; Github password of bot
|
||||
password =
|
||||
; Email used for commits
|
||||
email = mumbletransifexbot@mumble.info
|
||||
|
||||
[transifex]
|
||||
; Modes: default fetches all string, reviewed only reviewed ones
|
||||
|
@ -10,7 +12,6 @@ mode = default
|
|||
; Minimum number of percent needed for a translation to be included
|
||||
minpercent = 0
|
||||
|
||||
|
||||
[workingrepo]
|
||||
owner = MumbleTransifexBot
|
||||
repo = mumble
|
||||
|
|
34
prfromtransifex.py
Normal file → Executable file
34
prfromtransifex.py
Normal file → Executable file
|
@ -39,13 +39,14 @@ import ConfigParser
|
|||
from argparse import ArgumentParser
|
||||
from logging import basicConfig, getLogger, DEBUG, INFO, WARNING, ERROR, debug, error, info, warning, exception
|
||||
from github import Github
|
||||
from plumbum.cmd import git, tx, cd
|
||||
from plumbum import ProcessExecutionError
|
||||
from plumbum.cmd import git, tx
|
||||
from plumbum import ProcessExecutionError, local
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
def getExistingPullRequest(g, user, repo):
|
||||
s = g.search("type:pr is:open repo:%(repo)s author:%(user)s" % {'user': user,
|
||||
s = g.search_issues("type:pr is:open repo:%(repo)s author:%(user)s" % {'user': user,
|
||||
'repo': repo})
|
||||
pullrequests = s.get_page(0)
|
||||
total = len(pullrequests)
|
||||
|
@ -95,6 +96,7 @@ if __name__ == "__main__":
|
|||
|
||||
user = cfg.get('github', 'user')
|
||||
password = cfg.get('github', 'password')
|
||||
email = cfg.get('github', 'email')
|
||||
|
||||
mode = cfg.get('transifex', 'mode')
|
||||
minpercent = cfg.get('transifex', 'minpercent')
|
||||
|
@ -118,17 +120,24 @@ if __name__ == "__main__":
|
|||
translationstemplate = cfg.get('misc', 'template')
|
||||
additionaltsfiles = cfg.get('misc', 'additionaltsfiles')
|
||||
|
||||
if args.setup:
|
||||
if args.setup or not os.path.exists(wr_path):
|
||||
info("Setting up git repo")
|
||||
debug(git["clone", wr_url, wr_path]())
|
||||
with local.cwd(wr_path):
|
||||
debug(git["config", "user.name", user]())
|
||||
debug(git["config", "user.email", email]())
|
||||
debug(git["remote", "add", "target", tr_url]())
|
||||
|
||||
info("Done")
|
||||
|
||||
if args.setup:
|
||||
sys.exit(0)
|
||||
|
||||
info("Checking for pending PR")
|
||||
g = Github(user, password)
|
||||
pr = getExistingPullRequest(user = user,
|
||||
repo = tr_repo)
|
||||
pr = getExistingPullRequest(g,
|
||||
user = user,
|
||||
repo = tr_owner + "/" + tr_repo)
|
||||
if pr:
|
||||
info("Already have pending PR %d", pr.number)
|
||||
# As long as we have a pending PR we want to make sure we
|
||||
|
@ -145,22 +154,23 @@ if __name__ == "__main__":
|
|||
remote = "target"
|
||||
branch = tr_branch
|
||||
|
||||
with local.cwd(wr_path):
|
||||
info("Updating remote '%s'", remote)
|
||||
debug(git["fetch", remote]()))
|
||||
info("Resetting to branch '%s'", branch
|
||||
debug(git["fetch", remote]())
|
||||
info("Resetting to branch '%s'", branch)
|
||||
debug(git["reset", remote + "/" + branch, "--hard"]())
|
||||
info("Cleaning repository")
|
||||
debug(git["clean", "-f", "-x", "-d"]())
|
||||
info("Pulling translations")
|
||||
|
||||
txout = tx["pull", "-f", "--mode=" + mode, "--minimum-perc" + minpercent]()
|
||||
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)
|
||||
paths, files = zip(*re.findall(r"^\s->\s[\w_]+:\s([\w/\_]+/([\w_]+\.ts))$", t, flags=re.MULTILINE))
|
||||
paths, files = zip(*re.findall(r"^\s->\s[\w_]+:\s([\w/\_]+/([\w_]+\.ts))$", txout, flags=re.MULTILINE))
|
||||
debug(git["add"](*paths))
|
||||
translations = additionaltsfiles + " ".join(files)"
|
||||
translations = additionaltsfiles + " " + (" ".join(sorted(files)))
|
||||
|
||||
with open(tfilepath, "w") as f:
|
||||
f.write(translationstemplate % {'files': translations})
|
||||
|
@ -168,7 +178,7 @@ if __name__ == "__main__":
|
|||
debug(git["add"](tfilepath))
|
||||
|
||||
debug("Checking for modifications")
|
||||
changed, changedfiles, _ = git["diff", "--cached", "--name-only", "--exit-code"].run()
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue