Module flash_config
[hide private]
[frames] | no frames]

Source Code for Module flash_config

  1  #============================================================================  
  2  #Name        : flash_config.py  
  3  #Part of     : Helium  
  4   
  5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
  6  #All rights reserved. 
  7  #This component and the accompanying materials are made available 
  8  #under the terms of the License "Eclipse Public License v1.0" 
  9  #which accompanies this distribution, and is available 
 10  #at the URL "http://www.eclipse.org/legal/epl-v10.html". 
 11  # 
 12  #Initial Contributors: 
 13  #Nokia Corporation - initial contribution. 
 14  # 
 15  #Contributors: 
 16  # 
 17  #Description: 
 18  #=============================================================================== 
 19   
 20  """ This modules implements flash configuration writer. 
 21  """ 
 22  import logging 
 23  import os 
 24  import re 
 25  import rom 
 26  import types 
 27  import imaker 
 28   
 29   
 30  # Uncomment this line to enable logging in this module, or configure logging elsewhere 
 31  #logging.basicConfig(level=logging.DEBUG) 
 32  logger = logging.getLogger("flash_config") 
 33   
34 -class ImagePack:
35 """ Local storage of image type 36 """ 37
38 - def __init__(self, config, type):
39 """ init from config 40 """ 41 config['image.type'] = '${image.type.temp}' 42 self._type = type 43 self._id = config[type + '.id'] 44 self._image_name = config[type + '.image.name'] 45 self._image_path = config[type + '.image.path']
46
47 - def set_config(self, config):
48 """ Set the image type in a config 49 """ 50 config[self._type + '.id'] = self._id 51 config[self._type + '.image.name'] = self._image_name 52 config[self._type + '.image.path'] = self._image_path
53
54 - def __repr__(self):
55 """ String representation the class 56 """ 57 return self._id + " " + self._image_name + " " + self._image_path
58
59 -class FlashConfigurationWriter:
60 """ Builder that creates the flash configuration files 61 """
62 - def __init__(self, configs, product):
63 """ FlashConfigurationWriter init 64 """ 65 self._configs = configs 66 self._product = product 67 self._all_languagepacks = {} # pylint recomendation 68 self._all_udas = {} 69 self._all_mms = {} 70 self._all_mcs = {}
71
72 - def _get_all_languagepacks(self):
73 """ Collect all language packs and store them internally 74 """ 75 self._all_languagepacks = {} 76 for config in self._configs.getConfigurations(self._product): 77 if (config.type == "languagepack"): 78 lp = ImagePack(config, 'languagepack') 79 self._all_languagepacks[lp._id] = lp
80
81 - def _get_compatible_languagepacks(self, config):
82 """ Get language packs compatible with a customer variant 83 """ 84 languagepack_list = [] 85 if config.has_key('compatible.languagepack'): 86 lp_list = config['compatible.languagepack'] 87 if not isinstance(lp_list, types.ListType): 88 lp_list = [lp_list] 89 for lp_id in lp_list: 90 if self._all_languagepacks.has_key(lp_id): 91 languagepack_list.append(self._all_languagepacks[lp_id]) 92 else: 93 print "Compatible languagepack " + str(lp_id) + " does not exists" 94 else: 95 languagepack_list = self._all_languagepacks.values() 96 97 return languagepack_list
98
99 - def _get_all_udas(self):
100 """ Collect all udas and store them internally 101 """ 102 self._all_udas = {} 103 for config in self._configs.getConfigurations(self._product): 104 if (config.type == "uda"): 105 lp = ImagePack(config, 'uda') 106 self._all_udas[lp._id] = lp
107
108 - def _get_all_mms(self):
109 """ Collect all mm's and store them internally 110 """ 111 self._all_mms = {} 112 for config in self._configs.getConfigurations(self._product): 113 if (config.type == "massmemory"): 114 lp = ImagePack(config, 'massmemory') 115 self._all_mms[lp._id] = lp
116
117 - def _get_all_mcs(self):
118 """ Collect all mc's and store them internally 119 """ 120 self._all_mcs = {} 121 for config in self._configs.getConfigurations(self._product): 122 if (config.type == "memorycard"): 123 lp = ImagePack(config, 'memorycard') 124 self._all_mcs[lp._id] = lp
125
126 - def _get_compatible_udas(self, config):
127 """ Get uda's compatible with a customer variant 128 """ 129 uda_list = [] 130 if config.has_key('compatible.uda'): 131 lp_list = config['compatible.uda'] 132 if not isinstance(lp_list, types.ListType): 133 lp_list = [lp_list] 134 for lp_id in lp_list: 135 if self._all_udas.has_key(lp_id): 136 uda_list.append(self._all_udas[lp_id]) 137 else: 138 print "Compatible uda " + str(lp_id) + " does not exists" 139 else: 140 return None 141 142 return uda_list
143
144 - def _get_compatible_mms(self, config):
145 """ Get mm's compatible with a customer variant 146 """ 147 mm_list = [] 148 if config.has_key('compatible.massmemory'): 149 lp_list = config['compatible.massmemory'] 150 151 if not isinstance(lp_list, types.ListType): 152 lp_list = [lp_list] 153 for lp_id in lp_list: 154 if self._all_mms.has_key(lp_id): 155 mm_list.append(self._all_mms[lp_id]) 156 else: 157 print "Compatible massmemory " + str(lp_id) + " does not exists" 158 else: 159 return None 160 161 return mm_list
162
163 - def _get_compatible_mcs(self, config):
164 """ Get mc's compatible with a customer variant 165 """ 166 mc_list = [] 167 if config.has_key('compatible.memorycard'): 168 lp_list = config['compatible.memorycard'] 169 if not isinstance(lp_list, types.ListType): 170 lp_list = [lp_list] 171 for lp_id in lp_list: 172 if self._all_mcs.has_key(lp_id): 173 mc_list.append(self._all_mcs[lp_id]) 174 else: 175 print "Compatible memorycard " + str(lp_id) + " does not exists" 176 else: 177 return None 178 179 return mc_list
180
181 - def _write_file(self, config, romtype, uda, mm, mc):
182 """ Write an xml flash configuration file 183 """ 184 185 #data = escapeddict.EscapedDict(config) 186 template = rom.read_file_content(config['flash.config.template']) 187 188 if not uda: 189 #templatexml = amara.parse(template) 190 191 #for image in templatexml.flash_config.image_set.image: 192 # if image.type == u'uda': 193 # templatexml.flash_config.image_set.xml_remove_child(image) 194 195 #template = templatexml.xml(indent=u"yes") 196 #needed to avoid customer complaints about empty lines 197 #template = template.replace('\n\t\t\n', '\n') 198 199 #workaround for makeupct, can't use real xml library 200 template = re.sub(r".*<image type=\"uda\".*/>\n", '', template) 201 202 if not mm: 203 template = re.sub(r".*<image type=\"massmemory\".*/>\n", '', template) 204 if not mc: 205 template = re.sub(r".*<image type=\"memorycard\".*/>\n", '', template) 206 207 if not os.path.exists(config['flash.config.publish.dir']): 208 print "Creating " + config['flash.config.publish.dir'] 209 os.makedirs(config['flash.config.publish.dir']) 210 211 fp = open(os.path.join(config['flash.config.publish.dir'], config['flash.config.name']), 'w') 212 print "Writing file " + fp.name 213 fp.write(rom.escape_string(template, config)) 214 fp.close()
215
216 - def _append_to_makefile(self, config, romtype):
217 template = rom.read_file_content(config['flash.config.makefile.template']) 218 out = config.interpolate(template) + "\n" 219 self._makefile_content += out + "\n" 220 self._targets += rom.get_makefile_target(out) + " "
221
222 - def write(self):
223 """ Go throught the config and creates the flash configuration files 224 """ 225 226 # Pass #1: Store all language packs 227 self._get_all_languagepacks() 228 self._get_all_udas() 229 self._get_all_mcs() 230 self._get_all_mms() 231 self._makefile_content = "" 232 self._targets = "flash_config: " 233 234 # Pass #2: Create all flash config files 235 for config in self._configs.getConfigurations(self._product): 236 if (config.type == "customer") or (config.type == "operator"): 237 image_types = config['image.type'] 238 if not isinstance(config['image.type'], types.ListType): 239 image_types = [config['image.type']] 240 241 for lp in self._get_compatible_languagepacks(config): 242 lp.set_config(config) 243 config['image.type.temp'] = '${image.type}' 244 245 enable_uda = True 246 enable_mm = True 247 enable_mc = True 248 compatible_uda = self._get_compatible_udas(config) 249 compatible_mm = self._get_compatible_mms(config) 250 compatible_mc = self._get_compatible_mcs(config) 251 252 if compatible_uda == None: 253 enable_uda = False 254 compatible_uda = [None] 255 if compatible_mm == None: 256 enable_mm = False 257 compatible_mm = [None] 258 if compatible_mc == None: 259 enable_mc = False 260 compatible_mc = [None] 261 262 for uda in compatible_uda: 263 if uda: 264 uda.set_config(config) 265 for mm in compatible_mm: 266 if mm: 267 mm.set_config(config) 268 for mc in compatible_mc: 269 if mc: 270 mc.set_config(config) 271 for romtype in image_types: 272 config['image.type'] = romtype 273 self._write_file(config, romtype, enable_uda, enable_mm, enable_mc) 274 self._append_to_makefile(config, romtype) 275 276 if self._makefile_content == "": 277 logger.warning("No customer's or operator's found in rom config") 278 279 # Write makefile 280 makefile_filename = "%s/mc_flash_config.mk" % imaker.get_product_dir(self._product) 281 print "Writing makfile " + makefile_filename 282 fp = open(makefile_filename, 'w') 283 fp.write("include $(E32ROMCFG)/helium_features.mk\n") 284 fp.write(self._makefile_content) 285 fp.write(self._targets) 286 fp.close()
287