blob: 623211413cceb30c745eba9d87649c8ac9742601 [file] [log] [blame]
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01001#!/usr/bin/python2
Marco Brohet4683bee2014-02-28 01:06:03 +01002#
3# create_cm_caf_xml.py
4#
5# Generates cm_caf.xml based on the strings that were added to
6# CM's *.xml compared to AOSP's *.xml
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01007
Marco Brohetcf4069b2014-02-28 18:48:17 +01008import git
9import os
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010010from xml.dom import minidom
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010011
12def create_cm_caf_xml(strings_base, strings_cm, path):
13 # Load AOSP file and resources
14 xml_base = minidom.parse(strings_base)
15 list_base_string = xml_base.getElementsByTagName('string')
16 list_base_string_array = xml_base.getElementsByTagName('string-array')
17 list_base_plurals = xml_base.getElementsByTagName('plurals')
18
19 # Load CM file and resources
20 xml_cm = minidom.parse(strings_cm)
21 list_cm_string = xml_cm.getElementsByTagName('string')
22 list_cm_string_array = xml_cm.getElementsByTagName('string-array')
23 list_cm_plurals = xml_cm.getElementsByTagName('plurals')
24
25 # All names from CM
26 names_cm_string = []
27 names_cm_string_array = []
28 names_cm_plurals = []
29 # All names from AOSP
30 names_base_string = []
31 names_base_string_array = []
32 names_base_plurals = []
33
34 # Get all names from CM
35 for s in list_cm_string :
36 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
37 names_cm_string.append(s.attributes['name'].value)
38 for s in list_cm_string_array :
39 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
40 names_cm_string-array.append(s.attributes['name'].value)
41 for s in list_cm_plurals :
42 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
43 names_cm_plurals.append(s.attributes['name'].value)
44
45 # Get all names from AOSP
46 for s in list_base_string :
47 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
48 names_base_string.append(s.attributes['name'].value)
49 for s in list_base_string_array :
50 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
51 names_base_string_array.append(s.attributes['name'].value)
52 for s in list_base_plurals :
53 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
54 names_base_plurals.append(s.attributes['name'].value)
55
56 # Search for different names. If so, output the full line
57 t = 5
58
59 for z in names_cm_string:
60 if not z in names_base_string:
61 if t == 5:
62 f = open(path + '/cm_caf.xml','w')
63 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
64 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
65 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010066 f.write(list_cm_string[names_cm_string.index(z)].toxml() + '\n')
67 for z in names_cm_string_array:
68 if not z in names_base_string_array:
69 if t == 5:
70 f = open(path + '/cm_caf.xml','w')
71 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
72 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
73 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010074 f.write(list_cm_string_array[names_cm_string_array.index(z)].toxml() + '\n')
75 for z in names_cm_plurals:
76 if not z in names_base_plurals:
77 if t == 5:
78 f = open(path + '/cm_caf.xml','w')
79 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
80 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
81 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010082 f.write(list_cm_plurals[names_cm_plurals.index(z)].toxml() + '\n')
83
84 if t == 4:
85 f.write('</resources>')
86 f.close()
Marco Brohetcf4069b2014-02-28 18:48:17 +010087
88def push_as_commit(path, name):
89 path = os.getcwd() + '/' + path
90 repo = git.Repo(path)
91 repo.git.add(path)
92 try:
93 repo.git.commit(m='Crowdin translation import')
94 repo.git.push('ssh://cobjeM@review.cyanogenmod.org:29418/' + name, 'HEAD:refs/for/cm-11.0')
95 print 'Succesfully pushed commit for' + name
96 except:
97 print 'No commit pushed (probably empty?) for ' + name