diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..65990248bf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: python +python: + - "3.4" +before_script: + - pip install pygithub + - pip install pygithub3 +script: + - python3 tools/deploy.py +env: + global: + - secure: "KcJQbknBOdC5lA4nFGKPXVRVIGLDXDRzC8XkHuXJCE9pIR/wbxbkvx8fHKcC6SC9eHgzneC3+o4m4+CjIbVvIwDgslRbJ8Y59i90ncONmdoRx1HUYHwuYWVZm9HJFjCsIbrEqhSyyKS+PB3WZVOLbErtNHsgS8f43PTh5Ujg7Vg=" diff --git a/tools/deploy.py b/tools/deploy.py new file mode 100755 index 0000000000..baefbf44e2 --- /dev/null +++ b/tools/deploy.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 + +#################################### +# ACE3 automatic deployment script # +# ================================ # +# This is not meant to be run # +# directly! # +#################################### + +import os +import sys +import shutil +import traceback +import subprocess as sp +from pygithub3 import Github + + +TRANSLATIONISSUE = 367 +TRANSLATIONBODY = """**How to translate ACE3:** +https://github.com/acemod/ACE3/blob/master/documentation/development/how-to-translate-ace3.md + +{} +""" + +REPOUSER = "acemod" +REPONAME = "ACE3" +REPOPATH = "{}/{}".format(REPOUSER,REPONAME) + +USERNAME = "ACE3 Travis" +USEREMAIL = "travis@ace3mod.com" + + +def update_translations(token): + diag = sp.check_output(["python3", "tools/stringtablediag.py", "--markdown"]) + diag = str(diag, "utf-8") + repo = Github(token).get_repo(REPOPATH) + issue = repo.get_issue(TRANSLATIONISSUE) + issue.edit(body=TRANSLATIONBODY.format(diag)) + + +def deploy_documentation(token): + devnull = open(os.devnull, "w") + url = "https://{}@github.com/{}".format(token, REPOPATH) + + sp.check_call(["git", "clone", url, "out", "--depth", "10", "--branch", "gh-pages"], stdout=devnull, stderr=devnull) + os.chdir("out") + + sp.check_call(["git", "config", "user.name", USERNAME]) + sp.check_call(["git", "config", "user.email", USEREMAIL]) + + for root, dirs, files in os.walk("../documentation", topdown=False): + target = root.replace("../documentation", "wiki") + if root == "../documentation": + continue + for name in files: + print("{} => {}".format(os.path.join(root, name), os.path.join(target, name))) + shutil.copyfile(os.path.join(root, name), os.path.join(target, name)) + + sp.check_call(["git", "add", "--all", "."]) + sp.check_call(["git", "commit", "-m", "Automatic gh-pages deployment"]) + sp.check_call(["git", "push", "origin", "gh-pages"], stdout=devnull, stderr=devnull) + + os.chdir("..") + + +def main(): + print("Obtaining token ...") + try: + token = os.environ["GH_TOKEN"] + except: + print("Could not obtain token.") + print(traceback.format_exc()) + return 1 + else: + print("done.") + + print("\nUpdating translation issue ...") + try: + update_translations(token) + except: + print("Failed to update translation issue.") + print(traceback.format_exc()) + return 1 + else: + print("done.") + + print("\nDeploying documentation ...") + try: + deploy_documentation(token) + except: + print("Failed to deploy documentation.") + print(traceback.format_exc()) + return 1 + else: + print("done.") + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/stringtablediag.py b/tools/stringtablediag.py index c4aab0b104..8cd585ac2a 100755 --- a/tools/stringtablediag.py +++ b/tools/stringtablediag.py @@ -57,14 +57,16 @@ def main(): projectpath = os.path.dirname(os.path.dirname(scriptpath)) projectpath = os.path.join(projectpath, "addons") - print("#########################") - print("# Stringtable Diag Tool #") - print("#########################") + if "--markdown" not in sys.argv: + print("#########################") + print("# Stringtable Diag Tool #") + print("#########################") languages = get_all_languages(projectpath) - print("\nLanguages present in the repo:") - print(", ".join(languages)) + if "--markdown" not in sys.argv: + print("\nLanguages present in the repo:") + print(", ".join(languages)) keysum = 0 localizedsum = list(map(lambda x: 0, languages)) @@ -76,31 +78,33 @@ def main(): if keynumber == 0: continue - print("\n# " + module) + if "--markdown" not in sys.argv: + print("\n# " + module) keysum += keynumber for i in range(len(localized)): - print(" %s %s / %i" % ((languages[i]+":").ljust(10), str(localized[i]).ljust(3), keynumber)) + if "--markdown" not in sys.argv: + print(" %s %s / %i" % ((languages[i]+":").ljust(10), str(localized[i]).ljust(3), keynumber)) localizedsum[i] += localized[i] if localized[i] < keynumber: missing[i].append(module) - print("\n###########") - print("# RESULTS #") - print("###########") + if "--markdown" not in sys.argv: + print("\n###########") + print("# RESULTS #") + print("###########") + print("\nTotal number of keys: %i\n" % (keysum)) - print("\nTotal number of keys: %i\n" % (keysum)) + for i in range(len(languages)): + if localizedsum[i] == keysum: + print("%s No missing stringtable entries." % ((languages[i] + ":").ljust(12))) + else: + print("%s %s missing stringtable entry/entries." % ((languages[i] + ":").ljust(12), str(keysum - localizedsum[i]).rjust(4)), end="") + print(" ("+", ".join(missing[i])+")") - for i in range(len(languages)): - if localizedsum[i] == keysum: - print("%s No missing stringtable entries." % ((languages[i] + ":").ljust(12))) - else: - print("%s %s missing stringtable entry/entries." % ((languages[i] + ":").ljust(12), str(keysum - localizedsum[i]).rjust(4)), end="") - print(" ("+", ".join(missing[i])+")") + print("\n\n### MARKDOWN ###\n") - print("\n\n### MARKDOWN ###") - - print("\nTotal number of keys: %i\n" % (keysum)) + print("Total number of keys: %i\n" % (keysum)) print("| Language | Missing Entries | Relevant Modules | % done |") print("|----------|----------------:|------------------|--------|")