configurationengine/source/plugins/symbian/ConeThemePlugin/themeplugin/theme_resource.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    13 #
    13 #
    14 # Description: 
    14 # Description: 
    15 #
    15 #
    16 
    16 
    17 from shutil import copy
    17 from shutil import copy
    18 import os
    18 import os, re
    19 
    19 
    20 class ThemeResource:   
    20 class ThemeResource:   
    21     """
    21     """
    22     This class represents the records about the theme resources which are saved in *.pkg file.
    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"
    23     Every record contains a filename of the resource (for example "themepackage.mbm"
    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         """