32 """ |
32 """ |
33 parses *.pkg file and returns a array of classes ThemeResource |
33 parses *.pkg file and returns a array of classes ThemeResource |
34 The class ThemeResource contains a name of theme resource |
34 The class ThemeResource contains a name of theme resource |
35 and a path where this resource will be copied in the output directory |
35 and a path where this resource will be copied in the output directory |
36 """ |
36 """ |
37 pkg_file=file(file_path,'r') |
37 |
38 is_found_else=False |
38 resource_pattern = re.compile(r'"(.*)"\s+-\s+"!:\\(.*)"') |
39 row = "" |
|
40 # for every row in pkg file |
39 # for every row in pkg file |
41 for row in pkg_file: |
40 for row in open(file_path, 'r'): |
42 #if it finds tag "ELSE" then it begins load the records about the theme resources |
41 mo = resource_pattern.match(row) |
43 if row.startswith("ELSE"): |
42 if mo: |
44 is_found_else = True |
43 resource = Resource(mo.group(1), os.path.split(mo.group(2))[0]) |
45 |
44 self.list_resource.append(resource) |
46 if(is_found_else): |
|
47 parts_of_row = row.split("\"") |
|
48 #the loading record has to have 5 parts separated "\" |
|
49 if len(parts_of_row) == 5: |
|
50 #gets the path of the theme resource |
|
51 path = parts_of_row[3] |
|
52 #removes these chars "!:\" from the path of theme resource |
|
53 path = self.modify_resource_path(path) |
|
54 #parts_of_row[1 is the filename of the theme resource |
|
55 resource = Resource(parts_of_row[1], path) |
|
56 self.list_resource.append(resource) |
|
57 |
|
58 pkg_file.close() |
|
59 |
45 |
60 def copy_files_from_theme(self, source_path, output_path): |
46 def copy_files_from_theme(self, source_path, output_path): |
61 """ |
47 """ |
62 copies theme resources from source directory to theirs target paths |
48 copies theme resources from source directory to theirs target paths |
63 """ |
49 """ |
64 for resource in self.list_resource: |
50 for resource in self.list_resource: |
65 source_file = os.path.join(source_path, resource.get_filename()) |
51 source_file = os.path.join(source_path, resource.get_filename()) |
66 target_dir = os.path.join(output_path, resource.get_path()) |
52 target_dir = os.path.join(output_path, resource.get_path()) |
67 self.copy_files(source_file, target_dir) |
53 self.copy_files(source_file, target_dir) |
68 |
54 |
69 def copy_files(self, source_path, target_path): |
55 def copy_files(self, source_path, target_path): |
70 """ |
56 """ |
71 copy files from source to target. If the target directory doesn't exist then it is created |
57 copy files from source to target. If the target directory doesn't exist then it is created |
72 """ |
58 """ |