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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/fennec-ids-generator.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import re
     1.9 +import os
    1.10 +import sys
    1.11 +import optparse
    1.12 +
    1.13 +def getFile(filename):
    1.14 +  fHandle = open(filename, 'r')
    1.15 +  data = fHandle.read()
    1.16 +  fHandle.close()
    1.17 +  return data
    1.18 +
    1.19 +def findIDs(data):
    1.20 +  start_function = False
    1.21 +  reID = re.compile('.*public static final class id {.*')
    1.22 +  reEnd = re.compile('.*}.*')
    1.23 +  idlist = []
    1.24 +
    1.25 +  for line in data.split('\n'):
    1.26 +    if reEnd.match(line):
    1.27 +      start_function = False
    1.28 +
    1.29 +    if start_function:
    1.30 +      id_value = line.split(' ')[-1]
    1.31 +      idlist.append(id_value.split(';')[0].split('='))
    1.32 +
    1.33 +    if reID.match(line):
    1.34 +      start_function = True
    1.35 +
    1.36 +  return idlist
    1.37 +
    1.38 +
    1.39 +def printIDs(outputFile, idlist):
    1.40 +  fOutput = open(outputFile, 'w')
    1.41 +  for item in idlist:
    1.42 +    fOutput.write("%s=%s\n" % (item[0], item[1]))
    1.43 +  fOutput.close()
    1.44 +
    1.45 +def main(args=sys.argv[1:]):
    1.46 +  parser = optparse.OptionParser()
    1.47 +  parser.add_option('-o', '--output', dest='outputFile', default='',
    1.48 +                    help="output file with the id=value pairs")
    1.49 +  parser.add_option('-i', '--input', dest='inputFile', default='',
    1.50 +                    help="filename of the input R.java file")
    1.51 +  options, args = parser.parse_args(args)
    1.52 +
    1.53 +  if options.inputFile == '':
    1.54 +    print "Error: please provide input file: -i <filename>"
    1.55 +    sys.exit(1)
    1.56 +
    1.57 +  if options.outputFile == '':
    1.58 +    print "Error: please provide output file: -o <filename>"
    1.59 +    sys.exit(1)
    1.60 +
    1.61 +  data = getFile(os.path.abspath(options.inputFile));
    1.62 +  idlist = findIDs(data)
    1.63 +  printIDs(os.path.abspath(options.outputFile), idlist)
    1.64 +
    1.65 +if __name__ == "__main__":
    1.66 +    main()

mercurial