buildframework/helium/sf/python/pythoncore/lib/build/model.py
changeset 628 7c4a911dc066
parent 587 85df38eb4012
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    28 from xmlhelper import recursive_node_scan
    28 from xmlhelper import recursive_node_scan
    29 import symrec
    29 import symrec
    30 
    30 
    31 # Uncomment this line to enable logging in this module, or configure logging elsewhere
    31 # Uncomment this line to enable logging in this module, or configure logging elsewhere
    32 _logger = logging.getLogger("bom")
    32 _logger = logging.getLogger("bom")
    33 #_logger.setLevel(logging.DEBUG)
    33 _logger.setLevel(logging.INFO)
    34 logging.basicConfig(level=logging.DEBUG)
    34 #logging.basicConfig(level=logging.DEBUG)
    35 
    35 
    36 
    36 
    37 class SessionCreator(object):
    37 class SessionCreator(object):
    38     """ Session Creator object. """
    38     """ Session Creator object. """
    39     def __init__(self, username=None, password=None, provider=None):
    39     def __init__(self, username=None, password=None, provider=None):
    61         :param ccm_project: The Synergy project used for reading the BOM.
    61         :param ccm_project: The Synergy project used for reading the BOM.
    62         """
    62         """
    63         self.config = config
    63         self.config = config
    64         self.build = ""
    64         self.build = ""
    65         self._projects = []
    65         self._projects = []
    66         self._icd_icfs = []
    66         self.icd_icfs = []
    67         self._flags = []
    67         self._flags = []
    68         
    68         
    69         self._capture_icd_icfs()
    69         self._capture_icd_icfs()
    70         self._capture_flags()
    70         self._capture_flags()
    71         
    71         
    93                                         for file_ in files:
    93                                         for file_ in files:
    94                                             for exclude in excludes:
    94                                             for exclude in excludes:
    95                                                 if file_.endswith(exclude):
    95                                                 if file_.endswith(exclude):
    96                                                     excluded = True
    96                                                     excluded = True
    97                                             if file_.endswith('.zip') and not excluded:
    97                                             if file_.endswith('.zip') and not excluded:
    98                                                 self._icd_icfs.append(file_)
    98                                                 self.icd_icfs.append(file_)
    99                                                 self._icd_icfs.sort(key=str)
    99                                                 self.icd_icfs.sort(key=str)
   100         
   100         
   101     def _capture_flags(self):
   101     def _capture_flags(self):
   102         """capture flags"""
   102         """capture flags"""
   103         pass
   103         pass
   104         
   104         
   412         return self_task[:self_task.find(':')]
   412         return self_task[:self_task.find(':')]
   413         
   413         
   414     def __str__(self):
   414     def __str__(self):
   415         """ String representation. """
   415         """ String representation. """
   416         return str(self.ccm_task)
   416         return str(self.ccm_task)
   417         
       
   418         
       
   419 class ICD_ICF(object):
       
   420     """ A ICD or ICF patch zip file provided by Symbian. """
       
   421     pass
       
   422 
       
   423 
       
   424 class Flag(object):
       
   425     """ A compilation flag. """
       
   426     pass
       
   427     
   417     
   428 
   418 
   429 class BOMDeltaXMLWriter(object):
   419 class BOMDeltaXMLWriter(object):
   430     """ This class is used to generate an xml file containing the differences of 
   420     """ This class is used to generate an xml file containing the differences of 
   431         old and new Bill of materials.
   421         old and new Bill of materials.
   437     
   427     
   438     def write(self, path):
   428     def write(self, path):
   439         """ Write the BOM delta information to an XML file. """
   429         """ Write the BOM delta information to an XML file. """
   440         bom_log = amara.parse(open(self._bom_log, 'r'))
   430         bom_log = amara.parse(open(self._bom_log, 'r'))
   441         doc = amara.create_document(u'bomDelta')
   431         doc = amara.create_document(u'bomDelta')
   442         # pylint: disable-msg=E1101
   432         # pylint: disable=E1101
   443         doc.bomDelta.xml_append(doc.xml_create_element(u'buildFrom', content=unicode(bom_log.bom.build)))
   433         doc.bomDelta.xml_append(doc.xml_create_element(u'buildFrom', content=unicode(bom_log.bom.build)))
   444         doc.bomDelta.xml_append(doc.xml_create_element(u'buildTo', content=unicode(self._bom.config['build.id'])))
   434         doc.bomDelta.xml_append(doc.xml_create_element(u'buildTo', content=unicode(self._bom.config['build.id'])))
   445         content_node = doc.xml_create_element(u'content')
   435         content_node = doc.xml_create_element(u'content')
   446         doc.bomDelta.xml_append(content_node)
   436         doc.bomDelta.xml_append(content_node)
   447         
   437         
   599         self._bom = bom
   589         self._bom = bom
   600         
   590         
   601     def write(self, path):
   591     def write(self, path):
   602         """ Write the BOM information to an XML file. """
   592         """ Write the BOM information to an XML file. """
   603         doc = amara.create_document(u'bom')
   593         doc = amara.create_document(u'bom')
   604         # pylint: disable-msg=E1101
   594         # pylint: disable=E1101
   605         doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode(self._bom.config['build.id'])))
   595         doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode(self._bom.config['build.id'])))
   606         doc.bom.xml_append(doc.xml_create_element(u'content'))
   596         doc.bom.xml_append(doc.xml_create_element(u'content'))
   607         for project in self._bom.projects:
   597         for project in self._bom.projects:
   608             project_node = doc.xml_create_element(u'project')
   598             project_node = doc.xml_create_element(u'project')
   609             project_node.xml_append(doc.xml_create_element(u'name', content=unicode(project)))
   599             project_node.xml_append(doc.xml_create_element(u'name', content=unicode(project)))
   637                 fix = task.has_fixed()
   627                 fix = task.has_fixed()
   638                 if fix != None:
   628                 if fix != None:
   639                     fix_node = doc.xml_create_element(u'fix', content=(unicode(task)), attributes = {u'type': unicode(fix.__class__.__name__)})
   629                     fix_node = doc.xml_create_element(u'fix', content=(unicode(task)), attributes = {u'type': unicode(fix.__class__.__name__)})
   640                     project_node.xml_append(fix_node)
   630                     project_node.xml_append(fix_node)
   641 
   631 
   642         if self._bom._icd_icfs != []:
   632         if self._bom.icd_icfs != []:
   643             # Add ICD info to BOM
   633             # Add ICD info to BOM
   644             doc.bom.content.xml_append(doc.xml_create_element(u'input'))
   634             doc.bom.content.xml_append(doc.xml_create_element(u'input'))
   645     
   635     
   646             # Add default values to unused fields so icds are visible in the BOM
   636             # Add default values to unused fields so icds are visible in the BOM
   647             empty_bom_str = u'N/A'
   637             empty_bom_str = u'N/A'
   651             doc.bom.content.input.xml_append(doc.xml_create_element(u'week', content=(unicode(empty_bom_tm))))
   641             doc.bom.content.input.xml_append(doc.xml_create_element(u'week', content=(unicode(empty_bom_tm))))
   652             doc.bom.content.input.xml_append(doc.xml_create_element(u'version', content=(unicode(empty_bom_str))))
   642             doc.bom.content.input.xml_append(doc.xml_create_element(u'version', content=(unicode(empty_bom_str))))
   653     
   643     
   654             doc.bom.content.input.xml_append(doc.xml_create_element(u'icds'))
   644             doc.bom.content.input.xml_append(doc.xml_create_element(u'icds'))
   655 
   645 
   656         # pylint: disable-msg=R0914
   646         # pylint: disable=R0914
   657         for i, icd in enumerate(self._bom._icd_icfs):
   647         for i, icd in enumerate(self._bom.icd_icfs):
   658             doc.bom.content.input.icds.xml_append(doc.xml_create_element(u'icd'))
   648             doc.bom.content.input.icds.xml_append(doc.xml_create_element(u'icd'))
   659             doc.bom.content.input.icds.icd[i].xml_append(doc.xml_create_element(u'name', content=(unicode(icd))))
   649             doc.bom.content.input.icds.icd[i].xml_append(doc.xml_create_element(u'name', content=(unicode(icd))))
   660         #If currentRelease.xml exists then send s60 <input> tag to diamonds
   650         #If currentRelease.xml exists then send s60 <input> tag to diamonds
   661         current_release_xml_path = self._bom.config['currentRelease.xml']
   651         current_release_xml_path = self._bom.config['currentRelease.xml']
       
   652         # data from the metadata will go first as they must be safer than the one
       
   653         # given by the user 
   662         if current_release_xml_path is not None and os.path.exists(current_release_xml_path):
   654         if current_release_xml_path is not None and os.path.exists(current_release_xml_path):
   663             metadata = symrec.ReleaseMetadata(current_release_xml_path)
   655             metadata = symrec.ReleaseMetadata(current_release_xml_path)
   664             service = metadata.service
   656             service = metadata.service
   665             product = metadata.product
   657             product = metadata.product
   666             release = metadata.release
   658             release = metadata.release
   667             # Get name, year, week and version from baseline configuration
   659             # Get name, year, week and version from baseline configuration
   668             s60_input_node = doc.xml_create_element(u'input')
   660             s60_input_node = doc.xml_create_element(u'input')
   669             s60_version = self._bom.config['s60_version']
   661             s60_type = u's60'
   670             s60_release = self._bom.config['s60_release']
   662             s60_year = u'0'
   671             if s60_version != None:
   663             s60_week = u'0'
   672                 s60_year = s60_version[0:4]
   664             s60_release = u''
   673                 s60_week = s60_version[4:]
   665             # Using regular expression in first place
       
   666             regexp = r'(?P<TYPE>.*)_(?P<YEAR>\d{4})(?P<WEEK>\d{2})_(?P<REVISION>.*)'            
       
   667             if self._bom.config['release_regexp']:
       
   668                 if '?P<TYPE>' not in self._bom.config['release_regexp']:
       
   669                     _logger.error('Missing TYPE in: %s' % str(self._bom.config['release_regexp']))
       
   670                     _logger.info('Using default regular expression: %s' % regexp)
       
   671                 elif '?P<YEAR>' not in self._bom.config['release_regexp']:
       
   672                     _logger.error('Missing YEAR in: %s' % str(self._bom.config['release_regexp']))
       
   673                     _logger.info('Using default regular expression: %s' % regexp)
       
   674                 elif '?P<WEEK>' not in self._bom.config['release_regexp']:
       
   675                     _logger.error('Missing WEEK in: %s' % str(self._bom.config['release_regexp']))
       
   676                     _logger.info('Using default regular expression: %s' % regexp)
       
   677                 elif '?P<REVISION>' not in self._bom.config['release_regexp']:
       
   678                     _logger.error('Missing REVISION in: %s' % str(self._bom.config['release_regexp']))
       
   679                     _logger.info('Using default regular expression: %s' % regexp)
       
   680                 else:
       
   681                     _logger.info('Using custom regular expression to capture the baseline release information: %s'
       
   682                                   % str(self._bom.config['release_regexp']))
       
   683                     regexp = self._bom.config['release_regexp']                
       
   684             res = re.match(regexp, release)            
       
   685             if res != None:
       
   686                 s60_type = res.group('TYPE')
       
   687                 s60_release = res.group('TYPE') + '_' + res.group('REVISION')
       
   688                 s60_year = res.group('YEAR')
       
   689                 s60_week = res.group('WEEK')
   674             else:
   690             else:
   675                 s60_year = u'0'
   691                 _logger.warning("Regular expression '%s' is not matching '%s'." % (regexp, release))
   676                 s60_week = u'0'
   692                 if self._bom.config['s60_version'] != None:
   677                 if s60_version == None:
   693                     # last resorts if it doesn't matches
   678                     res = re.match(r'(.*)_(\d{4})(\d{2})_(.*)', release)
   694                     _logger.warning("Falling back on s60.version and s60.release to determine input.")
   679                     if res != None:
   695                     s60_version = self._bom.config['s60_version']
   680                         s60_release = res.group(1) + '_' + res.group(4)
   696                     s60_year = s60_version[0:4]
   681                         s60_year = res.group(2)
   697                     s60_week = s60_version[4:]
   682                         s60_week = res.group(3)
   698                     if self._bom.config['s60_release']:
   683             s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode("s60"))))
   699                         s60_release = self._bom.config['s60_release']
       
   700 
       
   701             s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode(s60_type))))
   684             s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
   702             s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
   685             s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
   703             s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
   686             s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))
   704             s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))
   687 
   705 
   688             s60_input_source = s60_input_node.xml_create_element(u'source')
   706             s60_input_source = s60_input_node.xml_create_element(u'source')
   689             s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("grace"))))
   707             s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("hydra"))))
   690             s60_input_source.xml_append(doc.xml_create_element(u'service', content=(unicode(service))))
   708             s60_input_source.xml_append(doc.xml_create_element(u'service', content=(unicode(service))))
   691             s60_input_source.xml_append(doc.xml_create_element(u'product', content=(unicode(product))))
   709             s60_input_source.xml_append(doc.xml_create_element(u'product', content=(unicode(product))))
   692             s60_input_source.xml_append(doc.xml_create_element(u'release', content=(unicode(release))))
   710             s60_input_source.xml_append(doc.xml_create_element(u'release', content=(unicode(release))))
   693             s60_input_node.xml_append(s60_input_source)
   711             s60_input_node.xml_append(s60_input_source)
   694             doc.bom.content.xml_append(s60_input_node)
   712             doc.bom.content.xml_append(s60_input_node)
       
   713         elif self._bom.config['s60_version'] and self._bom.config['s60_release']:
       
   714             _logger.info("currentRelease.xml not defined, falling back on s60.version and s60.release to determine input.")
       
   715             s60_type = u's60'
       
   716             s60_version = self._bom.config['s60_version']
       
   717             s60_year = u'0'
       
   718             s60_week = u'0'
       
   719             if len(s60_version) > 6:
       
   720                 s60_year = s60_version[0:4]
       
   721                 s60_week = s60_version[4:]
       
   722             s60_release = self._bom.config['s60_release']
       
   723             s60_input_node = doc.xml_create_element(u'input')
       
   724             s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode(s60_type))))
       
   725             s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
       
   726             s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
       
   727             s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))
       
   728 
       
   729             s60_input_source = s60_input_node.xml_create_element(u'source')
       
   730             s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("unknown"))))
       
   731             s60_input_node.xml_append(s60_input_source)
       
   732             doc.bom.content.xml_append(s60_input_node)
       
   733             
       
   734             
   695         out = open(path, 'w')
   735         out = open(path, 'w')
   696         doc.xml(out, indent='yes')
   736         doc.xml(out, indent='yes')
   697         out.close()
   737         out.close()
   698         
   738         
   699     def parse_status_log(self, log):
   739     def parse_status_log(self, log):