0
|
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 |
from shutil import copy
|
3
|
18 |
import os, re
|
0
|
19 |
|
|
20 |
class ThemeResource:
|
|
21 |
"""
|
|
22 |
This class represents the records about the theme resources which are saved in *.pkg file.
|
|
23 |
Every record contains a filename of the resource (for example "themepackage.mbm"
|
|
24 |
and a path where this resource will be copied in the output directory
|
|
25 |
(for example "!:\private\10207114\import\99d49b086e6097b8\themepackage.mbm")
|
|
26 |
"""
|
|
27 |
|
|
28 |
def __init__(self):
|
|
29 |
self.list_resource=[]
|
|
30 |
|
|
31 |
def parse_pkg_file(self,file_path):
|
|
32 |
"""
|
|
33 |
parses *.pkg file and returns a array of classes ThemeResource
|
|
34 |
The class ThemeResource contains a name of theme resource
|
|
35 |
and a path where this resource will be copied in the output directory
|
|
36 |
"""
|
3
|
37 |
|
|
38 |
resource_pattern = re.compile(r'"(.*)"\s+-\s+"!:\\(.*)"')
|
0
|
39 |
# for every row in pkg file
|
3
|
40 |
for row in open(file_path, 'r'):
|
|
41 |
mo = resource_pattern.match(row)
|
|
42 |
if mo:
|
|
43 |
resource = Resource(mo.group(1), os.path.split(mo.group(2))[0])
|
|
44 |
self.list_resource.append(resource)
|
0
|
45 |
|
|
46 |
def copy_files_from_theme(self, source_path, output_path):
|
|
47 |
"""
|
|
48 |
copies theme resources from source directory to theirs target paths
|
|
49 |
"""
|
|
50 |
for resource in self.list_resource:
|
3
|
51 |
source_file = os.path.join(source_path, resource.get_filename())
|
|
52 |
target_dir = os.path.join(output_path, resource.get_path())
|
|
53 |
self.copy_files(source_file, target_dir)
|
0
|
54 |
|
|
55 |
def copy_files(self, source_path, target_path):
|
|
56 |
"""
|
|
57 |
copy files from source to target. If the target directory doesn't exist then it is created
|
|
58 |
"""
|
|
59 |
if os.path.exists(source_path) != True or os.path.isdir(source_path):
|
|
60 |
return
|
|
61 |
|
|
62 |
if os.path.exists(target_path) != True:
|
|
63 |
os.makedirs(target_path)
|
|
64 |
copy(source_path, target_path)
|
|
65 |
|
|
66 |
def modify_resource_path(self, path):
|
|
67 |
"""
|
|
68 |
Modifies the path of them resource.
|
|
69 |
If the paths contains string "private" or "Data" (it says that the path is target path) then it removes
|
|
70 |
these chars "!:\" from the path of theme resource
|
|
71 |
"""
|
|
72 |
if path.find("private") != -1 or path.find("Data") != -1:
|
|
73 |
if path.startswith("!:\\"):
|
|
74 |
index = path.rfind("\\")
|
|
75 |
path = path[3:index]
|
|
76 |
|
|
77 |
return path
|
|
78 |
|
|
79 |
|
|
80 |
class Resource(object):
|
|
81 |
"""
|
|
82 |
This class represents a record about the theme resource. It contains a filename of the resource
|
|
83 |
(for example "themepackage.mbm" and a path where this resource will be copied in the output directory
|
|
84 |
(for example "!:\private\10207114\import\99d49b086e6097b8\themepackage.mbm")
|
|
85 |
"""
|
|
86 |
|
|
87 |
def __init__(self, filename,path):
|
|
88 |
# the name of theme resource
|
|
89 |
self.filename = filename
|
|
90 |
# the path of theme resource
|
|
91 |
self.path = path
|
|
92 |
|
|
93 |
def get_filename(self):
|
|
94 |
return self.filename
|
|
95 |
|
|
96 |
def get_path(self):
|
|
97 |
return self.path
|
|
98 |
|
|
99 |
def set_path(self,path):
|
|
100 |
self.path = path
|
|
101 |
|
|
102 |
def set_filename(self,filename):
|
|
103 |
self.filename = filename |