blob: 17444a09b7cb39eb74c0f2bef630684f1d5f7fac [file] [log] [blame]
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01001#!/usr/bin/python2
2
3import os.path
4import sys
5import cm_sync
6from urllib import urlretrieve
Marco Brohetf8835802014-02-27 23:19:23 +01007from subprocess import call, check_output
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01008from xml.dom import minidom
Marco Brohetf8835802014-02-27 23:19:23 +01009import mmap
10import git
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010011
12print('STEP 0: Welcome to the CM Crowdin sync script\n')
13
14print('STEP 1: Create cm_caf.xml')
15
16if not os.path.isfile('caf.xml'):
17 sys.exit('You have no caf.xml. Terminating')
18xml = minidom.parse('caf.xml')
19items = xml.getElementsByTagName('item')
20
21cm_caf = []
22
23for 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 Brohetf8835802014-02-27 23:19:23 +010034 print('Created ' + path + '/cm_caf.xml')
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010035
Marco Brohetf8835802014-02-27 23:19:23 +010036#print('\nSTEP 2: Upload Crowdin source translations')
37#print(check_output(["java", "-jar", "crowdin-cli.jar", "upload", "sources"]))
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010038
Marco Brohetf8835802014-02-27 23:19:23 +010039#print('STEP 3: Download Crowdin translations')
40#print(check_output(["java", "-jar", "crowdin-cli.jar", "download"]))
41
42print('STEP 4A: Clean up of empty translations')
43# Search for all XML files
44result = [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']
45for 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
53print('\nSTEP 4B: Clean up of source cm_caf.xmls')
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010054for cm_caf_file in cm_caf:
55 print ('Removing ' + cm_caf_file)
56 os.remove(cm_caf_file)
57
Marco Brohetf8835802014-02-27 23:19:23 +010058print('\nSTEP 5: Push translations to Git')
59path_repo = os.getcwd() + '/packages/apps/Settings'
60repo = git.Repo(path_repo)
61print repo.git.add(path_repo)
62print repo.git.commit(m='Automatic translations import')
63print repo.git.push('ssh://cobjeM@review.cyanogenmod.org:29418/CyanogenMod/android_packages_apps_Settings', 'HEAD:refs/for/cm-11.0')
64
65print('\nSTEP 6: Done!')