configurationengine/source/plugins/symbian/ConeThemePlugin/themeplugin/unzip.py
author m2lahtel
Thu, 21 Oct 2010 16:36:53 +0300
changeset 5 d2c80f5cab53
parent 0 2e8eeb919028
permissions -rw-r--r--
Updated to version 1.2.14
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
    zfobj = zipfile.ZipFile(file)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
    for name in zfobj.namelist():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
        filePath = dir + name
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
        if name.endswith('/'):
5
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    29
            if not os.path.exists(filePath):
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    30
                createEmtyResource(filePath)
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    31
                #os.mkdir(filePath)
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
        else:
5
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    33
            if not os.path.exists(filePath):
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    34
                createEmtyResource(filePath)
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    35
                outfile = open(dir+ name, 'wb')
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    36
                outfile.write(zfobj.read(name))
d2c80f5cab53 Updated to version 1.2.14
m2lahtel
parents: 0
diff changeset
    37
                outfile.close()
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
def createEmtyResource(path):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
    splitdrive = os.path.splitdrive(path)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
    splitPath = os.path.split(splitdrive[1])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    pathS = os.path.split(splitPath[1])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    splited = path.split("/")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
    tempPath = ""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    for i in range(0,len(splited)-1):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        tempPath = tempPath+splited[i]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        if (os.path.exists(tempPath) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
             os.mkdir(tempPath)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        tempPath = tempPath+os.path.sep
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
    if (os.path.exists(path) is not True):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        file(path,'wt')