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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     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/.
     5 import re
     6 import os
     7 import sys
     8 import optparse
    10 def getFile(filename):
    11   fHandle = open(filename, 'r')
    12   data = fHandle.read()
    13   fHandle.close()
    14   return data
    16 def findIDs(data):
    17   start_function = False
    18   reID = re.compile('.*public static final class id {.*')
    19   reEnd = re.compile('.*}.*')
    20   idlist = []
    22   for line in data.split('\n'):
    23     if reEnd.match(line):
    24       start_function = False
    26     if start_function:
    27       id_value = line.split(' ')[-1]
    28       idlist.append(id_value.split(';')[0].split('='))
    30     if reID.match(line):
    31       start_function = True
    33   return idlist
    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()
    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)
    50   if options.inputFile == '':
    51     print "Error: please provide input file: -i <filename>"
    52     sys.exit(1)
    54   if options.outputFile == '':
    55     print "Error: please provide output file: -o <filename>"
    56     sys.exit(1)
    58   data = getFile(os.path.abspath(options.inputFile));
    59   idlist = findIDs(data)
    60   printIDs(os.path.abspath(options.outputFile), idlist)
    62 if __name__ == "__main__":
    63     main()

mercurial