srcanamdw/codescanner/makeGraphics/EncodedFile.py
changeset 1 22878952f6e2
equal deleted inserted replaced
0:509e4801c378 1:22878952f6e2
       
     1 # #################################################################
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # 
       
     5 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
     6 # 
       
     7 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
       
     8 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
       
     9 # * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
       
    10 # 
       
    11 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
       
    12 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
       
    13 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
       
    14 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
       
    15 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
       
    16 #
       
    17 # #################################################################
       
    18 
       
    19 import base64
       
    20 import zlib
       
    21 import os
       
    22 
       
    23 # #######################################################
       
    24 
       
    25 class CEncodedFile:
       
    26     def Extract( self, aBaseDirectory ):
       
    27         outputFileHandle = open( os.path.join( aBaseDirectory, self.iFilename ), 'wb' )
       
    28         outputFileBinary = zlib.decompress( base64.decodestring( self.iFileBody ) )
       
    29         outputFileHandle.write( outputFileBinary )
       
    30         outputFileHandle.close()
       
    31 
       
    32 	iFilename = ""
       
    33 	iFileBody = ""
       
    34 
       
    35 # #######################################################
       
    36 
       
    37 class CEncodedFileList:
       
    38     def AddEncodedFile( self, aEncodedFile ):
       
    39         # we can't have same different files in here with the same name
       
    40         # relative path bits should be fine
       
    41         self.iEncodedFileList[ aEncodedFile.iFilename.lower() ] = aEncodedFile
       
    42 
       
    43     def ExtractEncodedFile( self, aFilename, aBaseDirectory ):
       
    44         # look for the filename in our list of files
       
    45         filename = aFilename.lower()
       
    46         if( self.iEncodedFileList.has_key( filename ) ):
       
    47                 self.iEncodedFileList[ filename ].Extract( aBaseDirectory )
       
    48                 return
       
    49 
       
    50     def ExtractAllEncodedFiles( self, aBaseDirectory ):
       
    51         # run through associative array and extract everything
       
    52         for filename in self.iEncodedFileList.keys():
       
    53             self.ExtractEncodedFile( filename, aBaseDirectory )
       
    54 
       
    55 
       
    56     # declare iEncodedFileList is an associative array
       
    57     iEncodedFileList = {}
       
    58 
       
    59 # #######################################################
       
    60 
       
    61 # create array of encoded files
       
    62 encodedFileList = CEncodedFileList()
       
    63