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 |
|
20 """ packageIAD.py module """ |
|
21 |
|
22 import os |
|
23 import sys |
|
24 import xml.dom.minidom |
|
25 import iadinfo |
|
26 import zipfile |
|
27 import encodings.utf_8 |
|
28 |
|
29 |
|
30 class IADPackager : |
|
31 """ package IAD class " |
|
32 """ |
|
33 |
|
34 def __init__(self) : |
|
35 """ class init method """ |
|
36 self.hasStub = False |
|
37 |
|
38 def getBldDirs(self, layer, bldDirs) : |
|
39 """ get the list of build directories """ |
|
40 units = layer.getElementsByTagName ("unit") |
|
41 for unit in units : |
|
42 dir = unit.getAttribute ("bldFile").rstrip ('\\/') |
|
43 i = dir.rfind ("\\") |
|
44 if i == - 1 : |
|
45 i = dir.rfind ("/") |
|
46 bldDirs.append (dir[:i + 1]) |
|
47 |
|
48 def getLayer(self, configuration, layers, bldDirs) : |
|
49 """ get each layer info """ |
|
50 layerRef = configuration.getElementsByTagName ("layerRef")[0].getAttribute ("layerName") |
|
51 for layer in layers : |
|
52 if layer.getAttribute ("name") == layerRef : |
|
53 self.getBldDirs (layer, bldDirs) |
|
54 |
|
55 def createInfoFiles(self, sisInfo) : |
|
56 """ create the INfo files depends.xml etc.""" |
|
57 depends = xml.dom.minidom.parse ("depends.xml") |
|
58 info = xml.dom.minidom.parseString (sisInfo) |
|
59 |
|
60 infoFile = file ("sisinfo.xml", "w") |
|
61 packageDeps = info.getElementsByTagName("package_dependency") |
|
62 for packageDep in packageDeps : |
|
63 pack = depends.createElement ("package") |
|
64 depends.childNodes[1].appendChild (pack) |
|
65 for child in packageDep.childNodes : |
|
66 pack.appendChild (child) |
|
67 infoFile.write (info.toxml ()) |
|
68 infoFile.close() |
|
69 depFile = file ("depends.xml", "w") |
|
70 depFile.write (depends.toxml ()) |
|
71 depFile.close() |
|
72 |
|
73 def createSis(self, packageDir, packageName, makesis) : |
|
74 """ create the .sis file """ |
|
75 sisReader = iadinfo.IADHandler() |
|
76 os.chdir (packageDir) |
|
77 sisPackage = packageName + ".sis" |
|
78 stubPackage = packageName + "_stub.sis" |
|
79 print "Creating", sisPackage |
|
80 cmd = makesis + " package.pkg " + sisPackage |
|
81 os.system (cmd) |
|
82 self.createInfoFiles (sisReader.getInfo(sisPackage)) |
|
83 if os.path.exists(stubPackage) : |
|
84 print "Creating stub SIS file", stubPackage |
|
85 self.hasStub = True |
|
86 cmd = makesis + " -s package.pkg " + stubPackage |
|
87 os.system (cmd) |
|
88 |
|
89 def createPackage(self, topDir, packageName) : |
|
90 """ create the Data Package """ |
|
91 print "Creating package", packageName |
|
92 os.chdir (topDir) |
|
93 zipFile = packageName + ".zip" |
|
94 sisFile = packageName + '/' + packageName + ".sis" |
|
95 infoFile = packageName + "/sisinfo.xml" |
|
96 depFile = packageName + "/depends.xml" |
|
97 zip = zipfile.ZipFile (zipFile, "w") |
|
98 zip.write (sisFile, sisFile.encode ("utf-8")) |
|
99 zip.write (infoFile, infoFile.encode ("utf-8")) |
|
100 zip.write (depFile, depFile.encode ("utf-8")) |
|
101 if self.hasStub : |
|
102 stubFile = packageName + '/' + packageName + "_stub.sis" |
|
103 zip.write (stubFile, stubFile.encode ("utf-8")) |
|
104 zip.close() |
|
105 |
|
106 |
|
107 def processSisDir(self, sisDir, makesis) : |
|
108 """ handle the directory used to create the .sis file """ |
|
109 for root, dirs, _ in os.walk (sisDir): |
|
110 for name in dirs : |
|
111 self.createSis (os.path.join (root, name), name, makesis) |
|
112 self.createPackage (root, name) |
|
113 |
|
114 def main(sysdefFile, sysdefconfigs, bldDrive): |
|
115 """ main to called when imported """ |
|
116 makesis = bldDrive + "\\epoc32\\tools\\makesis.exe" |
|
117 |
|
118 sysdef = xml.dom.minidom.parse (sysdefFile) |
|
119 configurations = sysdef.getElementsByTagName ("configuration") |
|
120 layers = sysdef.getElementsByTagName ("layer") |
|
121 bldDirs = [] |
|
122 |
|
123 packager = IADPackager() |
|
124 |
|
125 for configuration in configurations : |
|
126 if configuration.getAttribute ("name") == sysdefconfigs : |
|
127 packager.getLayer (configuration, layers, bldDirs) |
|
128 |
|
129 |
|
130 for bldDir in bldDirs : |
|
131 packager.processSisDir (bldDrive + bldDir + "sis\\", makesis) |
|
132 |
|
133 if __name__ == "__main__": |
|
134 main(sys.argv[1], sys.argv[2], sys.argv[3]) |
|