mobile/android/base/fennec-ids-generator.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ac311b203874
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import re
6 import os
7 import sys
8 import optparse
9
10 def getFile(filename):
11 fHandle = open(filename, 'r')
12 data = fHandle.read()
13 fHandle.close()
14 return data
15
16 def findIDs(data):
17 start_function = False
18 reID = re.compile('.*public static final class id {.*')
19 reEnd = re.compile('.*}.*')
20 idlist = []
21
22 for line in data.split('\n'):
23 if reEnd.match(line):
24 start_function = False
25
26 if start_function:
27 id_value = line.split(' ')[-1]
28 idlist.append(id_value.split(';')[0].split('='))
29
30 if reID.match(line):
31 start_function = True
32
33 return idlist
34
35
36 def printIDs(outputFile, idlist):
37 fOutput = open(outputFile, 'w')
38 for item in idlist:
39 fOutput.write("%s=%s\n" % (item[0], item[1]))
40 fOutput.close()
41
42 def main(args=sys.argv[1:]):
43 parser = optparse.OptionParser()
44 parser.add_option('-o', '--output', dest='outputFile', default='',
45 help="output file with the id=value pairs")
46 parser.add_option('-i', '--input', dest='inputFile', default='',
47 help="filename of the input R.java file")
48 options, args = parser.parse_args(args)
49
50 if options.inputFile == '':
51 print "Error: please provide input file: -i <filename>"
52 sys.exit(1)
53
54 if options.outputFile == '':
55 print "Error: please provide output file: -o <filename>"
56 sys.exit(1)
57
58 data = getFile(os.path.abspath(options.inputFile));
59 idlist = findIDs(data)
60 printIDs(os.path.abspath(options.outputFile), idlist)
61
62 if __name__ == "__main__":
63 main()

mercurial