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 |
| 7 | from subprocess import call |
| 8 | from xml.dom import minidom |
| 9 | |
| 10 | print('STEP 0: Welcome to the CM Crowdin sync script\n') |
| 11 | |
| 12 | print('STEP 1: Create cm_caf.xml') |
| 13 | |
| 14 | if not os.path.isfile('caf.xml'): |
| 15 | sys.exit('You have no caf.xml. Terminating') |
| 16 | xml = minidom.parse('caf.xml') |
| 17 | items = xml.getElementsByTagName('item') |
| 18 | |
| 19 | cm_caf = [] |
| 20 | |
| 21 | for item in items: |
| 22 | call(['mkdir', '-p', 'tmp/' + item.attributes["path"].value]) |
| 23 | item_aosp = item.getElementsByTagName('aosp') |
| 24 | for aosp_item in item_aosp: |
| 25 | url = aosp_item.firstChild.nodeValue |
| 26 | path_to_base = 'tmp/' + item.attributes["path"].value + '/' + aosp_item.attributes["file"].value |
| 27 | path_to_cm = item.attributes["path"].value + '/' + aosp_item.attributes["file"].value |
| 28 | path = item.attributes["path"].value |
| 29 | urlretrieve(url, path_to_base) |
| 30 | cm_sync.create_cm_caf_xml(path_to_base, path_to_cm, path) |
| 31 | cm_caf.append(path + '/cm_caf.xml') |
| 32 | |
| 33 | print('\nSTEP 2: Upload Crowdin source translations') |
| 34 | |
| 35 | print('\nSTEP 3: Clean up') |
| 36 | for cm_caf_file in cm_caf: |
| 37 | print ('Removing ' + cm_caf_file) |
| 38 | os.remove(cm_caf_file) |
| 39 | |
| 40 | print('\nSTEP 4: Done!') |