Example #1
0
 def validate_delta_bom_contents(self, delta_bom_log, bom_log, old_bom_log):
     """ To validate delta bom contents with current bom and old bom. """
     delta_bom_log = amara.parse(open(delta_bom_log, 'r'))
     bom_log = amara.parse(open(bom_log, 'r'))
     old_bom_log = amara.parse(open(old_bom_log, 'r'))
     bom_contents_are_valid = None
     if hasattr(delta_bom_log.bomDelta.content, 'folder'):
         for delta_foder in delta_bom_log.bomDelta.content.folder:
             if(getattr(delta_foder, 'status'))=='added':
                 for bom_foder in bom_log.bom.content.project.folder:
                     if(unicode(getattr(bom_foder, 'name')) == unicode(delta_foder)):
                         bom_contents_are_valid = True
                     else:
                         bom_contents_are_valid = False
             if(getattr(delta_foder, 'status'))=='deleted':
                 for old_bom_foder in old_bom_log.bom.content.project.folder:
                     if(unicode(getattr(old_bom_foder, 'name')) == unicode(delta_foder)):
                         bom_contents_are_valid = True
                     else:
                         bom_contents_are_valid = False
                     
     if hasattr(delta_bom_log.bomDelta.content, 'task'):
         for delta_task in delta_bom_log.bomDelta.content.task:
             if(getattr(delta_task, 'status'))=='added':
                 for bom_task in recursive_node_scan(bom_log.bom.content, u'task'):
                     bom_task_id = u"%s: %s" % (bom_task.id, bom_task.synopsis)
                     if(bom_task_id == unicode(delta_task)):
                         bom_contents_are_valid = True
                     else:
                         bom_contents_are_valid = False
             if(getattr(delta_task, 'status'))=='deleted':
                 for old_bom_task in recursive_node_scan(old_bom_log.bom.content, u'task'):
                     old_bom_task_id = u"%s: %s" % (old_bom_task.id, old_bom_task.synopsis)
                     if(old_bom_task_id == unicode(delta_task)):
                         bom_contents_are_valid = True
                     else:
                         bom_contents_are_valid = False
     return bom_contents_are_valid
Example #2
0
    def write(self, path):
        """ Write the BOM delta information to an XML file. """
        bom_log = amara.parse(open(self._bom_log, 'r'))
        doc = amara.create_document(u'bomDelta')
        # pylint: disable-msg=E1101
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildFrom', content=unicode(bom_log.bom.build)))
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildTo', content=unicode(self._bom.config['build.id'])))
        content_node = doc.xml_create_element(u'content')
        doc.bomDelta.xml_append(content_node)
        
        old_baselines = {}
        baselines = {}
        old_folders = {}
        folders = {}
        old_tasks = {}
        tasks = {}
        if hasattr(bom_log.bom.content, 'project'):
            for project in bom_log.bom.content.project:
                if hasattr(project, 'baseline'):
                    for baseline in project.baseline:
                        if not old_baselines.has_key(unicode(baseline)):
                            old_baselines[unicode(baseline)] = {}
                        if hasattr(baseline, 'xml_attributes'):
                            _logger.debug('baseline.xml_attributes: %s' % baseline.xml_attributes)
                            for attr_name, junk_tuple in sorted(baseline.xml_attributes.iteritems()):
                                _logger.debug('attr_name: %s' % attr_name)
                                old_baselines[unicode(baseline)][unicode(attr_name)] = unicode(getattr(baseline, attr_name))
                if hasattr(project, 'folder'):
                    for folder in project.folder:
                        if hasattr(folder, 'name'):
                            for name in folder.name:
                                folder_name = unicode(name)
                                _logger.debug('folder_name: %s' % folder_name)
                            if not old_folders.has_key(unicode(folder_name)):
                                old_folders[unicode(folder_name)] = {}
                            if hasattr(name, 'xml_attributes'):
                                for attr_name, junk_tuple in sorted(name.xml_attributes.iteritems()):
                                    _logger.debug('attr_name: %s' % attr_name)
                                    old_folders[unicode(folder_name)][unicode(attr_name)] = unicode(getattr(name, attr_name))
        for task in recursive_node_scan(bom_log.bom.content, u'task'):
            _logger.debug('task: %s' % task)
            _logger.debug('task: %s' % task.id)
            _logger.debug('task: %s' % task.synopsis)
            task_id = u"%s: %s" % (task.id, task.synopsis)
            if not old_tasks.has_key(task_id):
                old_tasks[task_id] = {}
            if hasattr(task, 'xml_attributes'):
                for attr_name, junk_tuple in sorted(task.xml_attributes.iteritems()):
                    _logger.debug('attr_name: %s' % attr_name)
                    old_tasks[task_id][unicode(attr_name)] = unicode(getattr(task, attr_name))
        for project in self._bom.projects:
            for folder in project.folders:
                folders[unicode(folder.instance + "#" + folder.name + ": " + folder.description)] = {u'overridden':u'true'}
                for task in folder.tasks:
                    _logger.debug("task_bom:'%s'" % unicode(task))
                    tasks[unicode(task)] = {u'overridden':u'false'}
            for task in project.tasks:
                _logger.debug("task_bom:'%s'" % unicode(task))
                tasks[unicode(task)] = {u'overridden':u'true'}

        baselines = self._bom.all_baselines()

        self._write_items_with_attributes(content_node, u'baseline', baselines, old_baselines)
        self._write_items_with_attributes(content_node, u'folder', folders, old_folders)
        self._write_items_with_attributes(content_node, u'task', tasks, old_tasks)
        
        out = open(path, 'w')
        doc.xml(out, indent='yes')
        out.close()