Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | |
| 3 | import os.path |
| 4 | import sys |
| 5 | import cm_sync |
| 6 | from urllib import urlretrieve |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 7 | from subprocess import call, check_output |
Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 8 | from xml.dom import minidom |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 9 | import mmap |
| 10 | import git |
Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 11 | |
| 12 | print('STEP 0: Welcome to the CM Crowdin sync script\n') |
| 13 | |
| 14 | print('STEP 1: Create cm_caf.xml') |
| 15 | |
| 16 | if not os.path.isfile('caf.xml'): |
| 17 | sys.exit('You have no caf.xml. Terminating') |
| 18 | xml = minidom.parse('caf.xml') |
| 19 | items = xml.getElementsByTagName('item') |
| 20 | |
| 21 | cm_caf = [] |
| 22 | |
| 23 | for item in items: |
| 24 | call(['mkdir', '-p', 'tmp/' + item.attributes["path"].value]) |
| 25 | item_aosp = item.getElementsByTagName('aosp') |
| 26 | for aosp_item in item_aosp: |
| 27 | url = aosp_item.firstChild.nodeValue |
| 28 | path_to_base = 'tmp/' + item.attributes["path"].value + '/' + aosp_item.attributes["file"].value |
| 29 | path_to_cm = item.attributes["path"].value + '/' + aosp_item.attributes["file"].value |
| 30 | path = item.attributes["path"].value |
| 31 | urlretrieve(url, path_to_base) |
| 32 | cm_sync.create_cm_caf_xml(path_to_base, path_to_cm, path) |
| 33 | cm_caf.append(path + '/cm_caf.xml') |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 34 | print('Created ' + path + '/cm_caf.xml') |
Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 35 | |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 36 | #print('\nSTEP 2: Upload Crowdin source translations') |
| 37 | #print(check_output(["java", "-jar", "crowdin-cli.jar", "upload", "sources"])) |
Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 38 | |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 39 | #print('STEP 3: Download Crowdin translations') |
| 40 | #print(check_output(["java", "-jar", "crowdin-cli.jar", "download"])) |
| 41 | |
| 42 | print('STEP 4A: Clean up of empty translations') |
| 43 | # Search for all XML files |
| 44 | result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(os.getcwd()) for f in filenames if os.path.splitext(f)[1] == '.xml'] |
| 45 | for xml_file in result: |
| 46 | if '<resources/>' in open(xml_file).read(): |
| 47 | print ('Removing ' + xml_file) |
| 48 | os.remove(xml_file) |
| 49 | if '<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>' in open(xml_file).read(): |
| 50 | print ('Removing ' + xml_file) |
| 51 | os.remove(xml_file) |
| 52 | |
| 53 | print('\nSTEP 4B: Clean up of source cm_caf.xmls') |
Marco Brohet | f9d4a5b | 2014-02-27 15:02:24 +0100 | [diff] [blame] | 54 | for cm_caf_file in cm_caf: |
| 55 | print ('Removing ' + cm_caf_file) |
| 56 | os.remove(cm_caf_file) |
| 57 | |
Marco Brohet | f883580 | 2014-02-27 23:19:23 +0100 | [diff] [blame^] | 58 | print('\nSTEP 5: Push translations to Git') |
| 59 | path_repo = os.getcwd() + '/packages/apps/Settings' |
| 60 | repo = git.Repo(path_repo) |
| 61 | print repo.git.add(path_repo) |
| 62 | print repo.git.commit(m='Automatic translations import') |
| 63 | print repo.git.push('ssh://cobjeM@review.cyanogenmod.org:29418/CyanogenMod/android_packages_apps_Settings', 'HEAD:refs/for/cm-11.0') |
| 64 | |
| 65 | print('\nSTEP 6: Done!') |