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