build/buildutils/extractJavaLocFiles.py
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 #!/usr/bin/python
       
    17 #
       
    18 # This script creates java specific loc zip files from S60 loc zip files
       
    19 # and also creates a "resources.jar" file where all the java loc files
       
    20 # are collected.
       
    21 #
       
    22 # Usage: extractJavaLocFiles.py <input_dir> <output_dir>
       
    23 #
       
    24 # Script reads S60 loc zip files from <input_dir> directory and writes
       
    25 # java loc zip files and "resources.jar" to <output_dir> directory.
       
    26 #
       
    27 # This script uses external "jar" command for handling zip files and
       
    28 # thus is not optimized for speed.
       
    29 #
       
    30 
       
    31 import os, re, shutil, sys, zipfile
       
    32 import traceback
       
    33 from optparse import OptionParser
       
    34 
       
    35 # Base names for java loc files.
       
    36 JAVA_LOC_FILES = [
       
    37     'javafileconnection',
       
    38     'javainstallation',
       
    39     'javasensor',
       
    40     'javassl',
       
    41     'javausermessages',
       
    42     'javaapplicationsettings',
       
    43     ]
       
    44 
       
    45 # Pattern for loc zip file names.
       
    46 LOC_ZIP_FILE = re.compile("^\d+\.zip$", re.IGNORECASE)
       
    47 
       
    48 # Path for java loc files inside RESOURCES_FILE.
       
    49 RESOURCES_PATH = os.path.join("resources", "com", "nokia", "mj", "impl")
       
    50 
       
    51 def main():
       
    52     parser = OptionParser(
       
    53         usage = "Usage: %prog [args] <input_dir> <output_dir>")
       
    54     (opts, args) = parser.parse_args()
       
    55 
       
    56     try:
       
    57         inputDir = args[0]
       
    58         outputDir = args[1]
       
    59         resourcesFilename = os.path.join(outputDir, args[2])
       
    60 
       
    61         print "Processing loc files from %s to %s" % (inputDir, outputDir)
       
    62         locFileCount = 0;
       
    63         for dirname, _, filenames in os.walk(inputDir):
       
    64             for file in filenames:
       
    65                 inFilename = os.path.join(dirname, file)
       
    66                 if LOC_ZIP_FILE.match(file) and zipfile.is_zipfile(inFilename):
       
    67                     outFilename = os.path.join(outputDir, file.lower())
       
    68                     (fileIndex, fileExt) = os.path.splitext(file)
       
    69                     print "Extracting %s" % inFilename
       
    70                     extractJavaLocFiles(fileIndex, inFilename)
       
    71                     print "Creating %s" % outFilename
       
    72                     os.system("jar cfM " + outFilename + " " + fileIndex)
       
    73                     print "Updating %s" % resourcesFilename
       
    74                     updateResources(fileIndex, resourcesFilename)
       
    75                     # Remove temporary fileIndex directory.
       
    76                     if os.path.isdir(fileIndex):
       
    77                         shutil.rmtree(fileIndex)
       
    78                     locFileCount = locFileCount + 1
       
    79         print "Processed %d loc files" % (locFileCount)
       
    80 
       
    81     except:
       
    82         print "Usage: %s <input_dir> <output_dir>" % sys.argv[0]
       
    83         traceback.print_exc()
       
    84         sys.exit(1)
       
    85 
       
    86 def extractJavaLocFiles(index, inFilename):
       
    87     javaLocFiles = ""
       
    88     for javaLocFile in JAVA_LOC_FILES:
       
    89         javaLocFilename = os.path.join(index, javaLocFile + "_" + index + ".loc")
       
    90         javaLocFiles = javaLocFiles + " " + javaLocFilename
       
    91     os.system("jar xf " + inFilename + javaLocFiles)
       
    92 
       
    93 def updateResources(index, resourcesFilename):
       
    94     resourcesDir = os.path.join(index, RESOURCES_PATH)
       
    95     if not os.path.isdir(resourcesDir):
       
    96         os.makedirs(resourcesDir)
       
    97     for dirname, _, filenames in os.walk(index):
       
    98         for file in filenames:
       
    99             os.rename(os.path.join(dirname, file),
       
   100                       os.path.join(resourcesDir, file))
       
   101     if os.path.isfile(resourcesFilename):
       
   102         os.system("jar ufM " + resourcesFilename + " -C " + index + " .")
       
   103     else:
       
   104         os.system("jar cfM " + resourcesFilename + " -C " + index + " .")
       
   105 
       
   106 if __name__ == "__main__":
       
   107     main()