buildframework/helium/tools/iad/packageiad.py
author Shabe Razvi <shaber@symbian.org>
Tue, 13 Jul 2010 18:31:50 +0100
branchhelium-7.0.x
changeset 614 e08bbc2db635
parent 179 d8ac696cc51f
permissions -rw-r--r--
Implement enhancement Bug 3222 - Enable Helium to set diamonds status other than "succeeded" or "failed"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     1
#============================================================================ 
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     2
#Name        : packageiad.py 
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     3
#Part of     : Helium 
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     4
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     6
#All rights reserved.
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     7
#This component and the accompanying materials are made available
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     9
#which accompanies this distribution, and is available
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    11
#
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    12
#Initial Contributors:
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    14
#
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    15
#Contributors:
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    16
#
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    17
#Description:
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    18
#===============================================================================
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    19
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    20
""" packageIAD.py module """
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    21
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    22
import os
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    23
import sys
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    24
import xml.dom.minidom
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    25
import iadinfo
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    26
import zipfile
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    27
import encodings.utf_8
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    28
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    29
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    30
class IADPackager :
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    31
    """ package IAD class "
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    32
    """
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    33
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    34
    def __init__(self) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    35
        """ class init method """
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    36
        self.hasStub = False
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    37
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    38
    def getBldDirs(self, layer, bldDirs) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    39
        """ get the list of build directories """
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    40
        units = layer.getElementsByTagName ("unit")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    41
        for unit in units :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    42
            dir = unit.getAttribute ("bldFile").rstrip ('\\/')
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    43
            i = dir.rfind ("\\")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    44
            if i == - 1 :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    45
                i = dir.rfind ("/")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    46
            bldDirs.append (dir[:i + 1])
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    47
    
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    48
    def getLayer(self, configuration, layers, bldDirs) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    49
        """ get each layer info """
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    50
        layerRef = configuration.getElementsByTagName ("layerRef")[0].getAttribute ("layerName")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    51
        for layer in layers :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    52
            if layer.getAttribute ("name") == layerRef :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    53
                self.getBldDirs (layer, bldDirs)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    54
    
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    55
    def createInfoFiles(self, sisInfo) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    56
        """ create the INfo files depends.xml etc."""
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    57
        depends = xml.dom.minidom.parse ("depends.xml")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    58
        info = xml.dom.minidom.parseString (sisInfo)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    59
        
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    60
        infoFile = file ("sisinfo.xml", "w")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    61
        packageDeps = info.getElementsByTagName("package_dependency")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    62
        for packageDep in packageDeps :
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    63
            pack = depends.createElement ("package")
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    64
            depends.childNodes[1].appendChild (pack)
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    65
            for child in packageDep.childNodes :
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    66
                pack.appendChild (child)
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    67
        infoFile.write (info.toxml ())
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    68
        infoFile.close()
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    69
        depFile = file ("depends.xml", "w")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    70
        depFile.write (depends.toxml ())
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    71
        depFile.close()
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    72
    
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    73
    def createSis(self, packageDir, packageName, makesis) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    74
        """ create the .sis file """
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    75
        sisReader = iadinfo.IADHandler()
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    76
        os.chdir (packageDir)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    77
        sisPackage = packageName + ".sis"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    78
        stubPackage = packageName + "_stub.sis"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    79
        print "Creating", sisPackage
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    80
        cmd = makesis + " package.pkg " + sisPackage
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    81
        os.system (cmd)
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    82
        self.createInfoFiles (sisReader.getInfo(sisPackage))
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    83
        if os.path.exists(stubPackage) :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    84
            print "Creating stub SIS file", stubPackage
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    85
            self.hasStub = True
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    86
            cmd = makesis + " -s package.pkg " + stubPackage
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    87
            os.system (cmd)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    88
        
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    89
    def createPackage(self, topDir, packageName) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
    90
        """ create the Data Package """
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    91
        print "Creating package", packageName
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    92
        os.chdir (topDir)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    93
        zipFile = packageName + ".zip"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    94
        sisFile = packageName + '/' + packageName + ".sis"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    95
        infoFile = packageName + "/sisinfo.xml"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    96
        depFile = packageName + "/depends.xml"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    97
        zip = zipfile.ZipFile (zipFile, "w")
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    98
        zip.write (sisFile, sisFile.encode ("utf-8"))
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    99
        zip.write (infoFile, infoFile.encode ("utf-8"))
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   100
        zip.write (depFile, depFile.encode ("utf-8"))
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   101
        if self.hasStub :
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   102
            stubFile = packageName + '/' + packageName + "_stub.sis"
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   103
            zip.write (stubFile, stubFile.encode ("utf-8"))
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   104
        zip.close()
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   105
        
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   106
    
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   107
    def processSisDir(self, sisDir, makesis) :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   108
        """ handle the directory used to create the .sis file """
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   109
        for root, dirs, _ in os.walk (sisDir):
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   110
            for name in dirs :
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   111
                self.createSis (os.path.join (root, name), name, makesis)
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   112
                self.createPackage (root, name)
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   113
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   114
def main(sysdefFile, sysdefconfigs, bldDrive):
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   115
    """ main to called when imported """
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   116
    makesis = bldDrive + "\\epoc32\\tools\\makesis.exe"
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   117
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   118
    sysdef = xml.dom.minidom.parse (sysdefFile)
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   119
    configurations = sysdef.getElementsByTagName ("configuration")
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   120
    layers = sysdef.getElementsByTagName ("layer")
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   121
    bldDirs = []
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   122
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   123
    packager = IADPackager()
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   124
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   125
    for configuration in configurations :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   126
        if configuration.getAttribute ("name") == sysdefconfigs :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   127
            packager.getLayer (configuration, layers, bldDirs)
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   128
     
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   129
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   130
    for bldDir in bldDirs :
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   131
        packager.processSisDir (bldDrive + bldDir + "sis\\", makesis)
1
be27ed110b50 Bringing in Helium, imaker and cmaker
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   132
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   133
if __name__ == "__main__":
d8ac696cc51f helium_7.0-r14027
wbernard
parents: 1
diff changeset
   134
    main(sys.argv[1], sys.argv[2], sys.argv[3])