Skip to content

Commit

Permalink
Add Translations issue CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpas committed Sep 28, 2017
1 parent 7d69643 commit 7493702
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ language: python
python:
- '3.5'
install: true
before_script:
- if [ -n "${GH_TOKEN}" ] && [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
pip install pygithub;
pip install pygithub3;
fi
script:
- python3 tools/sqf_validator.py
- python3 tools/config_style_checker.py
- if [ -n "${GH_TOKEN}" ] && [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
python3 tools/deploy.py;
fi
env:
global:
- secure: E6FCH4pVIbA+pphLewjqQFO37ZjwNdz4m+dGlHlCutkB6PxY79BzpzfTwQol5jNn9/p4Hy5k+xefFx5eXBEHTxRPy7mAE00bMX1tSMEJZTeonQBIDQ4wYtJMAEmAEj76n+cGZMDxs4a/Q6bMXQlabJ591aoCpkgAi1Kj+UQfqmR0ee9MA43bZxrEiRqHhknyKM3Va6KRvuUOr+vyTuCshndLVk9WxcS7pVfrH43cgCL/swbvUAhZdk6hqzuHtGtSOHgoZU7AdSxxiV9DoBk7iq465LrqxqFC5Tv1WyKdElk5waHLwTPVk6tf9kbL6mpB0CW/vzzJjD/xEeaUajxsAnKP+fWWuCmp9b5n7GWtje+5PI3meott5iTLT5daqJa1R97UtErF/h8ZI+TIjyD0Dh05uG3XK0I+zNBQDJwvOvQxqE975fcPo8XXu6GxDMD6aRHINEpbvfbHQ4XeHTpvA3Zw1ng+3Um75qPhWVTpHEUDvAaqGIdtugzBfj3SyA94kb8Rq4PsKm2HF8poR5mAUCTXutYZiBA1eAr+eVuvjpRZxr2TvMr7gDQs5pHwdQq8Vcaun/VNpA4hCRiVP1bQ/mt3mfWGPQkhijITVbo6mQ9bW5ef78xDkLTv9y5tg67GWSO6gH3OV4MzaKlIcWWqg0Nz05J8kgq8M0S91DS32GE=
notifications:
email:
on_success: never
Expand Down
62 changes: 62 additions & 0 deletions tools/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3

####################################
# CBA 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 = 754
TRANSLATIONBODY = """**[CBA Translation Guide](https://github.com/CBATeam/CBA_A3/wiki/Translation-Guide)**
{}
"""

REPOUSER = "CBATeam"
REPONAME = "CBA_A3"
REPOPATH = "{}/{}".format(REPOUSER,REPONAME)


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 main():
print("Obtaining token ...")
try:
token = os.environ["GH_TOKEN"]
except:
print("Could not obtain token.")
print(traceback.format_exc())
return 1
else:
print("Token sucessfully obtained.")

print("\nUpdating translation issue ...")
try:
update_translations(token)
except:
print("Failed to update translation issue.")
print(traceback.format_exc())
return 1
else:
print("Translation issue successfully updated.")

return 0


if __name__ == "__main__":
sys.exit(main())
124 changes: 124 additions & 0 deletions tools/stringtablediag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env python3

import os
import sys

from xml.dom import minidom

# STRINGTABLE DIAG TOOL
# (~ ACE3 cec16d6)
# Author: KoffeinFlummi
# ---------------------
# Checks for missing translations and all that jazz.

def get_all_languages(projectpath):
""" Checks what languages exist in the repo. """
languages = []

for module in os.listdir(projectpath):
if module[0] == ".":
continue

stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
try:
xmldoc = minidom.parse(stringtablepath)
except:
continue

keys = xmldoc.getElementsByTagName("Key")
for key in keys:
for child in key.childNodes:
try:
if not child.tagName in languages:
languages.append(child.tagName)
except:
continue

return languages

def check_module(projectpath, module, languages):
""" Checks the given module for all the different languages. """
localized = []

stringtablepath = os.path.join(projectpath, module, "stringtable.xml")
try:
xmldoc = minidom.parse(stringtablepath)
except:
return 0, localized

keynumber = len(xmldoc.getElementsByTagName("Key"))

for language in languages:
localized.append(len(xmldoc.getElementsByTagName(language)))

return keynumber, localized

def main():
scriptpath = os.path.realpath(__file__)
projectpath = os.path.dirname(os.path.dirname(scriptpath))
projectpath = os.path.join(projectpath, "addons")

if "--markdown" not in sys.argv:
print("#########################")
print("# Stringtable Diag Tool #")
print("#########################")

languages = get_all_languages(projectpath)

if "--markdown" not in sys.argv:
print("\nLanguages present in the repo:")
print(", ".join(languages))

keysum = 0
localizedsum = list(map(lambda x: 0, languages))
missing = list(map(lambda x: [], languages))

for module in os.listdir(projectpath):
keynumber, localized = check_module(projectpath, module, languages)

if keynumber == 0:
continue

if "--markdown" not in sys.argv:
print("\n# " + module)

keysum += keynumber
for i in range(len(localized)):
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)

if "--markdown" not in sys.argv:
print("\n###########")
print("# RESULTS #")
print("###########")
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])+")")

print("\n\n### MARKDOWN ###\n")

print("Total number of keys: %i\n" % (keysum))

print("| Language | Missing Entries | Relevant Modules | % done |")
print("|----------|----------------:|------------------|--------|")

for i, language in enumerate(languages):
if localizedsum[i] == keysum:
print("| {} | 0 | - | 100% |".format(language))
else:
print("| {} | {} | {} | {}% |".format(
language,
keysum - localizedsum[i],
", ".join(missing[i]),
round(100 * localizedsum[i] / keysum)))

if __name__ == "__main__":
main()

0 comments on commit 7493702

Please sign in to comment.