scripts/python/sis2rom/sis2rom.py
author victorp@symbian.org
Wed, 03 Feb 2010 17:13:43 +0000
changeset 30 9372f863bb3a
parent 28 ab800b3e45ab
permissions -rw-r--r--
new integration plan update for week05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     1
"""
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     2
Copyright (c) 2006, Jari Sukanen
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     3
All rights reserved.
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     4
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     5
Redistribution and use in source and binary forms, with or 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     6
without modification, are permitted provided that the following 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     7
conditions are met:
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     8
	* Redistributions of source code must retain the above copyright 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
     9
	  notice, this list of conditions and the following disclaimer.
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    10
    * Redistributions in binary form must reproduce the above copyright 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    11
	  notice, this list of conditions and the following disclaimer in 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    12
	  the documentation and/or other materials provided with the 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    13
	  distribution.
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    14
    * Names of the contributors may not be used to endorse or promote 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    15
	  products derived from this software without specific prior written 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    16
	  permission.
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    17
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    19
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    20
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    21
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    22
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    23
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    24
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    25
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    26
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    27
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    28
THE POSSIBILITY OF SUCH DAMAGE.
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    29
"""
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    30
from sis import sisinfo, sisfields
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    31
import optparse
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    32
import sys, os
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    33
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    34
APP_PATH = "epoc32" + os.sep + "apps"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    35
IBY_PATH = "epoc32" + os.sep + "rom" + os.sep + "include"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    36
CRLF = '\r\n'
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    37
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    38
try:
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    39
	os.uname()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    40
	ZIP_CMD = 'zip -r '
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    41
except: # no uname on windows
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    42
	ZIP_CMD = '7z a '
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    43
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    44
PyASN1Availabe = True
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    45
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    46
try :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    47
    from pyasn1.codec.der import decoder
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    48
    from pyasn1.type import univ, base
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    49
except :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    50
    PyASN1Availabe = False
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    51
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    52
def _findItem(item, itemParent, index, objectIdentifier) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    53
	if isinstance(item, base.AbstractSimpleAsn1Item) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    54
		if item == objectIdentifier :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    55
			return itemParent[index+1]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    56
	else :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    57
		for i in range(len(item)) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    58
			found = _findItem(item[i], item, i, objectIdentifier)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    59
			if found : 
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    60
				return found
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    61
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    62
def findItem(decodedCert, objectIdentifier) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    63
	return _findItem(decodedCert, None, 0, objectIdentifier)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    64
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    65
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    66
class CertificateOrganization :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    67
	def __init__(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    68
		pass
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    69
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    70
	def parse(self, decodedCert) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    71
		self.commonName = findItem(decodedCert, (2,5,4,3))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    72
		self.countryCode = findItem(decodedCert, (2,5,4,6))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    73
		self.locality = findItem(decodedCert, (2,5,4,7))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    74
		self.state = findItem(decodedCert, (2,5,4,8))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    75
		self.street = findItem(decodedCert, (2,5,4,9))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    76
		self.organization = findItem(decodedCert, (2,5,4,10))
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    77
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    78
	def readableStr(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    79
		buf = ""
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    80
		if self.commonName :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    81
			buf += self.commonName.prettyPrint() + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    82
		if self.countryCode :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    83
			buf += self.countryCode.prettyPrint() + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    84
		if self.locality :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    85
			buf += self.locality.prettyPrint() + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    86
		if self.state :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    87
			buf += self.state.prettyPrint() + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    88
		if self.street :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    89
			buf += self.street.prettyPrint() + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    90
		if self.organization :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    91
			buf += self.organization.prettyPrint()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    92
		return buf
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    93
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    94
class CertificateInfo :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    95
	def __init__(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    96
		pass
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    97
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    98
	def parse(self, decodedCert) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
    99
		self.issuer = CertificateOrganization()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   100
		self.issuer.parse(decodedCert[0][3])
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   101
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   102
		self.signer = CertificateOrganization()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   103
		self.signer.parse(decodedCert[0][5])
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   104
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   105
	def readableStr(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   106
		buf = "Signer:\n      " + "\n      ".join(self.signer.readableStr().split('\n')) + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   107
		buf += "Issuer:\n      " + "\n      ".join(self.issuer.readableStr().split('\n')) + "\n"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   108
		return buf
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   109
			
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   110
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   111
class Handler :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   112
    def __init__(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   113
		self.files = []
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   114
		self.fileDatas = []
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   115
		self.signatureCertificateChains = []
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   116
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   117
    def handleField(self, field, depth) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   118
		if field.type == sisfields.FileDescriptionField :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   119
			self.files.append(field)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   120
		elif field.type == sisfields.FileDataField :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   121
			self.fileDatas.append(field)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   122
		elif field.type == sisfields.SignatureCertificateChainField  :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   123
			self.signatureCertificateChains.append(field)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   124
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   125
    def print_iby_for_file(self, iby, extracted_file, install_path):
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   126
    	#binarypath="file=ABI_DIR\\BUILD_DIR\\"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   127
    	#datapath="data=DATAZ_\\RESOURCE_FILES_DIR\\"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   128
    	binarypath="file=\\"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   129
    	datapath="data=\\"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   130
    	#privatepath="data=\\epoc32\\data\\z\\"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   131
    	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   132
    	install_path=install_path.replace('c:', 'z:')
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   133
    	#basename = filepath[filepath.rfind('\\')+1:]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   134
    	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   135
    	if extracted_file.endswith('exe') or extracted_file.endswith('dll'):
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   136
    		iby.write( binarypath + extracted_file + '\t\t' + install_path + CRLF)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   137
    	else:
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   138
    		iby.write( datapath + extracted_file + '\t\t' + install_path + CRLF)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   139
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   140
    	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   141
    def execute(self,outputname, iby) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   142
        for f in self.files :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   143
			buf = f.findField(sisfields.StringField)[0].readableStr()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   144
#			caps = f.findField(sisfields.CapabilitiesField)[0]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   145
#			if caps :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   146
#				buf += " [" + " ".join(f.findField(sisfields.CapabilitiesField)[0].readableCaps) + "]"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   147
			
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   148
			install_path=buf
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   149
			parts = f.findField(sisfields.StringField)[0].readableStr().split("\\")
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   150
			#for part in parts:
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   151
			#	print part
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   152
			if len(parts[len(parts) - 1]) > 0 :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   153
				path = os.getcwd() + os.sep + APP_PATH
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   154
				
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   155
				path += os.sep + os.sep.join(parts[1:-1])
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   156
				rel_file = APP_PATH + os.sep + outputname + os.sep + os.sep.join(parts[1:])
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   157
				rel_file = rel_file.replace('/','\\')
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   158
				if not os.path.exists(path) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   159
					os.makedirs(path)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   160
				extracted_file = path + os.sep + parts[len(parts) - 1]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   161
				newFile = file(extracted_file, "wb")
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   162
				newFile.write(self.fileDatas[f.fileIndex].findField(sisfields.CompressedField)[0].data)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   163
				newFile.close()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   164
				self.print_iby_for_file(iby,rel_file, install_path)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   165
			
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   166
class ContentPrinter :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   167
	def __init__(self) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   168
		pass
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   169
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   170
	def handleField(self, field, depth) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   171
		buf = ""
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   172
		for i in range(depth) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   173
			buf += "  "
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   174
		buf += sisfields.FieldNames[field.type] + " "
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   175
		if len(field.readableStr()) > 0 :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   176
			buf += field.readableStr()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   177
		print buf
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   178
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   179
import pdb
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   180
    
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   181
if __name__ == "__main__" :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   182
	if len(sys.argv) == 1:
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   183
		print "usage: %s <sisfile>" % sys.argv[0]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   184
		exit()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   185
		
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   186
	sisname = sys.argv[1]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   187
	sisInfo = sisinfo.SISInfo()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   188
	sisInfo.parse(sisname)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   189
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   190
	handler = Handler()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   191
	sisInfo.traverse(handler)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   192
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   193
	tmp = sisname.lower()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   194
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   195
	if tmp.find(os.sep):
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   196
		tmp = sisname[sisname.rfind(os.sep)+1:]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   197
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   198
	if tmp.find('sisx'):
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   199
		tmp = tmp[0:len(tmp)-4]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   200
	elif tmp.find('sis'):
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   201
		tmp = tmp[0:len(tmp)-3]
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   202
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   203
	iby_path = os.getcwd() + os.sep + IBY_PATH + os.sep
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   204
	iby_file = tmp + ".iby"
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   205
	
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   206
	if not os.path.exists(iby_path) :
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   207
		os.makedirs(iby_path)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   208
					
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   209
	iby = open(iby_path + iby_file,'w')
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   210
	print "Creating IBY file..."
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   211
	iby.write( "#ifndef __%s_IBY__" % tmp.upper() + CRLF)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   212
	iby.write( "#define __%s_IBY__" % tmp.upper() + CRLF)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   213
	print "Extracting SIS..."
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   214
	handler.execute(tmp, iby)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   215
	iby.write( "#endif" + CRLF)
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   216
	iby.close()
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   217
	print "Zipping..."
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   218
	os.system(ZIP_CMD + tmp + '.zip epoc32')
ab800b3e45ab Added sis2rom for Wild Ducks
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
diff changeset
   219
	print "All done. Remember to #include <%s> in your main IBY file" % iby_file