buildframework/helium/tools/iad/packageiad.py
changeset 307 22ecbfc20eb4
parent 215 b61c19d4168d
parent 217 0f5e3a7fb6af
child 308 7830b8253b5a
equal deleted inserted replaced
215:b61c19d4168d 307:22ecbfc20eb4
     1 #============================================================================ 
       
     2 #Name        : packageiad.py 
       
     3 #Part of     : Helium 
       
     4 
       
     5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     6 #All rights reserved.
       
     7 #This component and the accompanying materials are made available
       
     8 #under the terms of the License "Eclipse Public License v1.0"
       
     9 #which accompanies this distribution, and is available
       
    10 #at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    11 #
       
    12 #Initial Contributors:
       
    13 #Nokia Corporation - initial contribution.
       
    14 #
       
    15 #Contributors:
       
    16 #
       
    17 #Description:
       
    18 #===============================================================================
       
    19 import os
       
    20 import sys
       
    21 import xml.dom.minidom
       
    22 import iadinfo
       
    23 import zipfile
       
    24 import encodings.utf_8
       
    25 
       
    26 class IADPackager :
       
    27 
       
    28     def __init__ (self) :
       
    29         self.hasStub = False
       
    30 
       
    31     def getBldDirs (self, layer, bldDirs) :
       
    32         units = layer.getElementsByTagName ("unit")
       
    33         for unit in units :
       
    34             dir = unit.getAttribute ("bldFile").rstrip ('\\/')
       
    35             i = dir.rfind ("\\")
       
    36             if i == - 1 :
       
    37                 i = dir.rfind ("/")
       
    38             bldDirs.append (dir[:i + 1])
       
    39     
       
    40     def getLayer (self, configuration, layers, bldDirs) :
       
    41         layerRef = configuration.getElementsByTagName ("layerRef")[0].getAttribute ("layerName")
       
    42         for layer in layers :
       
    43             if layer.getAttribute ("name") == layerRef :
       
    44                 self.getBldDirs (layer, bldDirs)
       
    45     
       
    46     def createInfoFiles (self, sisInfo) :
       
    47         depends = xml.dom.minidom.parse ("depends.xml")
       
    48         info = xml.dom.minidom.parseString (sisInfo)
       
    49         
       
    50         infoFile = file ("sisinfo.xml", "w")
       
    51         platDeps = info.getElementsByTagName("platform_dependency")
       
    52         packageDeps = info.getElementsByTagName("package_dependency")
       
    53         for packageDep in packageDeps :
       
    54             p = depends.createElement ("package")
       
    55             depends.childNodes[1].appendChild (p)
       
    56             for child in packageDep.childNodes :
       
    57                 p.appendChild (child)
       
    58         infoFile.write (info.toxml ())
       
    59         infoFile.close()
       
    60         depFile = file ("depends.xml", "w")
       
    61         depFile.write (depends.toxml ())
       
    62         depFile.close()
       
    63     
       
    64     def createSis (self, packageDir, packageName) :
       
    65         sisReader = iadinfo.IADHandler()
       
    66         os.chdir (packageDir)
       
    67         sisPackage = packageName + ".sis"
       
    68         stubPackage = packageName + "_stub.sis"
       
    69         print "Creating", sisPackage
       
    70         cmd = makesis + " package.pkg " + sisPackage
       
    71         os.system (cmd)
       
    72         self.createInfoFiles (sisReader.getInfo (sisPackage))
       
    73         if os.path.exists(stubPackage) :
       
    74             print "Creating stub SIS file", stubPackage
       
    75             self.hasStub = True
       
    76             cmd = makesis + " -s package.pkg " + stubPackage
       
    77             os.system (cmd)
       
    78         
       
    79     def createPackage (self, topDir, packageName) :
       
    80         print "Creating package", packageName
       
    81         os.chdir (topDir)
       
    82         zipFile = packageName + ".zip"
       
    83         sisFile = packageName + '/' + packageName + ".sis"
       
    84         infoFile = packageName + "/sisinfo.xml"
       
    85         depFile = packageName + "/depends.xml"
       
    86         zip = zipfile.ZipFile (zipFile, "w")
       
    87         zip.write (sisFile, sisFile.encode ("utf-8"))
       
    88         zip.write (infoFile, infoFile.encode ("utf-8"))
       
    89         zip.write (depFile, depFile.encode ("utf-8"))
       
    90         if self.hasStub :
       
    91             stubFile = packageName + '/' + packageName + "_stub.sis"
       
    92             zip.write (stubFile, stubFile.encode ("utf-8"))
       
    93         zip.close()
       
    94         
       
    95     
       
    96     def processSisDir (self, sisDir) :
       
    97         for root, dirs, files in os.walk (sisDir):
       
    98             for name in dirs :
       
    99                 self.createSis (os.path.join (root, name), name)
       
   100                 self.createPackage (root, name)
       
   101 
       
   102 makesis = sys.argv[3] + "\\epoc32\\tools\\makesis.exe"
       
   103 signsis = sys.argv[3] + "\\epoc32\\tools\\signsis.exe"
       
   104 
       
   105 sysdef = xml.dom.minidom.parse (sys.argv[1])
       
   106 configurations = sysdef.getElementsByTagName ("configuration")
       
   107 layers = sysdef.getElementsByTagName ("layer")
       
   108 bldDirs = []
       
   109 
       
   110 packager = IADPackager()
       
   111 
       
   112 for configuration in configurations :
       
   113     if configuration.getAttribute ("name") == sys.argv[2] :
       
   114         packager.getLayer (configuration, layers, bldDirs)
       
   115  
       
   116 
       
   117 for bldDir in bldDirs :
       
   118     packager.processSisDir (sys.argv[3] + bldDir + "sis\\")
       
   119