configurationengine/source/plugins/symbian/ConeThemePlugin/themeplugin/unzip.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 5 d2c80f5cab53
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
import sys, zipfile, os, os.path
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
def unzip_file_into_dir(file, dir):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
    if (os.path.exists(file) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
        return
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
    if (os.path.exists(dir) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
        os.mkdir(dir, 0777)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
    zfobj = zipfile.ZipFile(file)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
    for name in zfobj.namelist():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
        filePath = dir + name
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
        if name.endswith('/'):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
            os.mkdir(filePath)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
        else:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
            createEmtyResource(filePath)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
            outfile = open(dir+ name, 'wb')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
            outfile.write(zfobj.read(name))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
            outfile.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
def createEmtyResource(path):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
    splitdrive = os.path.splitdrive(path)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    splitPath = os.path.split(splitdrive[1])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
    pathS = os.path.split(splitPath[1])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
    splited = path.split("/")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    tempPath = ""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    for i in range(0,len(splited)-1):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        tempPath = tempPath+splited[i]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        if (os.path.exists(tempPath) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
             os.mkdir(tempPath)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        tempPath = tempPath+os.path.sep
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    if (os.path.exists(path) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        file(path,'wt')