buildframework/helium/sf/python/pythoncore/lib/build/model.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : model.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
""" Models the concepts and objects that exist in a software build. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import amara
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import ccm
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
from xmlhelper import recursive_node_scan
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import symrec
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
# Uncomment this line to enable logging in this module, or configure logging elsewhere
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
_logger = logging.getLogger("bom")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    33
_logger.setLevel(logging.INFO)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    34
#logging.basicConfig(level=logging.DEBUG)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
class SessionCreator(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    """ Session Creator object. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
    def __init__(self, username=None, password=None, provider=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        """ Init the SessionCreator object."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        self.__provider = provider
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        self.__username = username
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        self.__password = password
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    def session(self, database):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        """ Get a session for a database. If no session exists just create a new one."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        _logger.info("Creating session for %s" % database)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        return self.__provider.get(username=self.__username, password=self.__password, database=database)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    def close(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        """close session"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        self.__provider = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
class BOM(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    """ The Bill of Materials for a build. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
    def __init__(self, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        """ Initialization.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        :param config: The build configuration properties.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        :param ccm_project: The Synergy project used for reading the BOM.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        self.config = config
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        self.build = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        self._projects = []
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    66
        self.icd_icfs = []
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        self._flags = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        self._capture_icd_icfs()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        self._capture_flags()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    def _capture_icd_icfs(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        """capture ICD and ICFS"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        prep_xml_path = self.config['prep.xml']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        if prep_xml_path is not None and os.path.exists(prep_xml_path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
            prep_doc = amara.parse(open(prep_xml_path,'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
            if hasattr(prep_doc.prepSpec, u'source'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
                for source in prep_doc.prepSpec.source:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
                    if hasattr(source, u'unzipicds'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
                        for  unzipicds in source.unzipicds:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
                            if hasattr(unzipicds, u'location'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
                                for location in unzipicds.location:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
                                    excludes = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
                                    excluded = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
                                    if hasattr(location, 'exclude'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
                                        for exclude in location.exclude:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
                                            _logger.debug('Exclude added: %s' % str(exclude.name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
                                            excludes.append(str(exclude.name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
                                            excluded = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
                                    path = str(location.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
                                    if os.path.exists(path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
                                        files = os.listdir(str(location.name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
                                        for file_ in files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
                                            for exclude in excludes:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
                                                if file_.endswith(exclude):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
                                                    excluded = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
                                            if file_.endswith('.zip') and not excluded:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    98
                                                self.icd_icfs.append(file_)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    99
                                                self.icd_icfs.sort(key=str)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    def _capture_flags(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        """capture flags"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    def _getprojects(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        """get projects"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        return self._projects
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
    projects = property(_getprojects)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
    def all_baselines(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
        """get all baselines"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        baselines = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        for project in self._projects:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
            for baseline, baseline_attrs in project.baselines.iteritems():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
                baselines[baseline] = baseline_attrs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        return baselines
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
    def all_tasks(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        """get all tasks"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        tasks = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        for project in self._projects:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
            tasks.extend(project.all_tasks())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
        tasks.sort(key=str)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        return tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
        return str(self._projects)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
class SimpleProject(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
    """ This class represents a simple ccm project """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
    def __init__(self, tasks):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
        self.tasks = tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
        self.folders = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
class SimpleBOM(BOM):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    """ This class represents a simple Bill of Materials for a build. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        The SimpleBOM is used to load the existing Bill of materials 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
    def __init__(self, config, bomxml):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        BOM.__init__(self, config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        self._baselines = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        bom = amara.parse(open(bomxml))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        for p_proj in bom.bom.content.project:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
            tasks = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
            self._baselines[str(p_proj.baseline)] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
            for t_proj in p_proj.task:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
                tasks.append(str(t_proj.id) + ': ' + str(t_proj.synopsis))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
            self._projects.append(SimpleProject(tasks))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
    def all_baselines(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        """get all baselines"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        return self._baselines
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
class SynergyBOM(BOM):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
    """ This class opens a user session to fetch the project details and creates the Bill of Materials """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
    def __init__(self, config, ccm_project=None, username=None, password=None, provider=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        BOM.__init__(self, config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
        self._sessioncreator = SessionCreator(username=username, password=password, provider=provider)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
        self.ccm_project = ccm_project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
        if self.ccm_project != None: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
            self._projects = [Project(ccm_project, config)]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
        self._capture_projects()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
    def __find_project(self, project, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
        """find project"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        if (os.path.exists(os.path.join(config['dir'], project.name, "project.version"))):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            return project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
        path = os.path.join(config['dir'], project.name, project.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
        if (not os.path.exists(path)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
            return project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
            result = project.session.get_workarea_info(path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
            return result['project']           
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        except ccm.CCMException:            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
            return project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
    def _capture_projects(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
        """ grab data from new format of delivery.xml"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
        configBuilder = configuration.NestedConfigurationBuilder(open(self.config['delivery'], 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
        for config in configBuilder.getConfiguration().getConfigurations():            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
            _logger.debug('Importing project %s from delivery config.' % str(config.name))            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
            ccm_project = self._sessioncreator.session(config['database']).create(config.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
            project = Project(self.__find_project(ccm_project, config), config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
            self._projects.append(project)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    def close(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
        """close session creator"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
        self._sessioncreator.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
class Project(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
    """ An SCM project.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    An input to the build area, typically copied from an SCM work area.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    def __init__(self, ccm_project, config, action=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
        self._ccm_project = ccm_project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
        self._baselines = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
        #TODO : could querying release attribute return the ccm object? Or add a release attribute to Project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        # class
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
        release = self._ccm_project['release']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
        _logger.debug("Project release: '%s'" % release)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
        self._ccm_release = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
        if release != '':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
            self._ccm_project.session.create(release)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        # capturing the frozen baseline.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
        _logger.debug('Capture baselines')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
        project_status = self._ccm_project['status']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        bproject = self._get_toplevel_baselines(self._ccm_project).pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        if bproject != None:        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
            self._baselines[unicode(bproject)] = {u'overridden':u'true'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
            # This section finds the baselines of all of the checked out projects
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
            if project_status == "prep" or project_status == "working" or project_status == "shared":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
                for subproject in self._ccm_project.subprojects:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
                    overridden = u'false'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
                    subprojbaseline = subproject.baseline
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
                    if config.has_key('subbaselines'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
                        for subbaseline in config['subbaselines']:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
                            if str(subbaseline) == str(subprojbaseline):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
                                overridden = u'true'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
                    if subprojbaseline != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
                        self._baselines[unicode(subprojbaseline)] = {u'overridden': overridden}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
            # When a project is a snapshot, the baselines are the projects themselves
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
                for subproject in bproject.subprojects:            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
                    self._baselines[unicode(subproject)] = {u'overridden':u'false'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        self._tasks = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
        self._folders = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
        # Get Synergy reconfigure properties for folders and tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
        if action == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
            self._import_baseline_config()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
            # Get tasks from Synergy if using reconfigure template
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
            if config.get_boolean("use.reconfigure.template", False):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
                self._tasks = self._ccm_project.tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
                self._folders = self._ccm_project.folders
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
                        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
        # Or get folders and tasks defined in configuration file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
        elif action != None and action.nodeName == "checkout":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
            if not config.get_boolean("use.reconfigure.template", False):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
                for task_node in action.xml_xpath(u'./task[@id]'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
                    for task in [x.strip() for x in task_node.id.split(',')]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
                        self._tasks.append(ccm_project.session.create("Task %s" % task))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
                for folder_node in action.xml_xpath(u'./folder[@id]'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
                    for folder in [x.strip() for x in folder_node.id.split(',')]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
                        self._folders.append(ccm_project.session.create("Folder %s" % folder))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
                self._tasks = self._ccm_project.tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
                self._folders = self._ccm_project.folders
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
            self._import_baseline_config()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
    def _import_baseline_config(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
        """ Import the baseline folders and tasks. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
        baselines = self._get_toplevel_baselines(self._ccm_project)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
        baselines.pop()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
        for baseline in baselines:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
            for task in baseline.tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
                if task not in self._tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
                    self._tasks.append(task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
            for folder in baseline.folders:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
                if folder not in self._folders:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
                    self._folders.append(folder)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
    def _get_toplevel_baselines(self, project):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
        """get top level baselines"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
        if project == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
            return []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
        project_status = project['status']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
        if project_status == "prep" or project_status == "working" or project_status == "shared":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
            result = [project]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
            baseline = project.baseline
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
            if baseline != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
                result.extend(self._get_toplevel_baselines(baseline))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
            return result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
            return [project]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
    def _getbaselines(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
        """get baselines"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
        return self._baselines
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
    baselines = property(_getbaselines)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
    def _getfolders(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
        """get folders"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
        return self._folders
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
    folders = property(_getfolders)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
    def all_tasks(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
        """ Get all the tasks (individual and folder based). """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   298
        tasks = [Task(ccm_task) for ccm_task in self._tasks]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
        for folder in self._folders:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
            [tasks.append(Task(ccm_task)) for ccm_task in folder.tasks]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
        tasks.sort(key=str)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
        return tasks
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
    def _gettasks(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   305
        """get Tasks"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
        return [Task(ccm_task) for ccm_task in self._tasks]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   307
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
    tasks = property(_gettasks)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
    def _getsupplier(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
        """get supplier"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   312
        if self._ccm_release != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   313
            component = self._ccm_release.component
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
            comparisons = {'MC': '^mc',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
                           'S60': 'S60',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   316
                           'SPP/NCP': '^spp_config|spp_psw|spp_tools|ncp_sw$',
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   317
                           'IBUSAL': '^IBUSAL'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   318
            for supplier, regexp in comparisons.iteritems():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   319
                if re.search(regexp, component) != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
                    return supplier
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
        return "Unknown"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   322
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   323
    supplier = property(_getsupplier)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   324
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   325
    def __repr__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   326
        """ Object representation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   327
        return str(self._ccm_project)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   328
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   329
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   330
        """ String representation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   331
        return str(self._ccm_project)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   332
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   333
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
class Fix(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
    """ A generic fix. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
    def __init__(self, description):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
        self._description = description
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   339
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   340
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   341
        """ String representation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   342
        return str(self._description)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   343
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   344
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   345
class TSWError(Fix):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   346
    """ A TSW database error. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   347
    regex = '([A-Z]{4}-[A-Z0-9]{6})'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   348
    groupname = 'TSW Errors'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   349
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   350
    def __init__(self, description):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   352
        Fix.__init__(self, description)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   354
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   355
class PCPError(Fix):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
    """ A PCP database error. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
    regex = '([A-Z]{2}-[0-9]{11})'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
    groupname = 'PCP Errors'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   360
    def __init__(self, description):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   361
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   362
        Fix.__init__(self, description)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   363
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   364
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   365
class TAChange(Fix):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   366
    """ A Type Approval change. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
    regex = '^_TA:(\s*)(.*?)(\s*)$'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   368
    groupname = 'TA Changes'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   370
    def __init__(self, description):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   371
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   372
        Fix.__init__(self, description)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   374
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   375
class Task(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
    """ A task or unit of change from the SCM system. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
    fix_types = [TSWError, PCPError, TAChange]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   379
    def __init__(self, ccm_task):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   380
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   381
        self.ccm_task = ccm_task
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   382
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
    def __getitem__(self, name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   384
        """ Dictionary of tasks support. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
        return self.ccm_task[name]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   386
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   387
    def has_fixed(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   388
        """ Returns an object representing what this task fixed, if anything. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   389
        text = str(self.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
        fix_object = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
        for fix_type in self.fix_types:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
            match = re.search(fix_type.regex, str(self.ccm_task))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
            if match != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
                fix_object = fix_type(text)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
                break
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
        return fix_object
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
    def __cmp__(self, other):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
        """ Compare tasks based on their task number only. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
        self_task = str(self.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   401
        other_task = str(other.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
        return cmp(self_task[:self_task.find(':')], other_task[:other_task.find(':')])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
    def __hash__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
        """ Hash support. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   406
        self_task = str(self.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
        return hash(self_task[:self_task.find(':')])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   409
    def __repr__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   410
        """ Object representation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
        self_task = repr(self.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
        return self_task[:self_task.find(':')]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415
        """ String representation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   416
        return str(self.ccm_task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   417
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   418
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   419
class BOMDeltaXMLWriter(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   420
    """ This class is used to generate an xml file containing the differences of 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   421
        old and new Bill of materials.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   422
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   423
    def __init__(self, bom, bom_log):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   424
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   425
        self._bom = bom
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   426
        self._bom_log = bom_log
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   427
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   428
    def write(self, path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   429
        """ Write the BOM delta information to an XML file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   430
        bom_log = amara.parse(open(self._bom_log, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   431
        doc = amara.create_document(u'bomDelta')
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   432
        # pylint: disable=E1101
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   433
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildFrom', content=unicode(bom_log.bom.build)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   434
        doc.bomDelta.xml_append(doc.xml_create_element(u'buildTo', content=unicode(self._bom.config['build.id'])))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   435
        content_node = doc.xml_create_element(u'content')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   436
        doc.bomDelta.xml_append(content_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   437
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   438
        old_baselines = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   439
        baselines = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   440
        old_folders = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   441
        folders = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   442
        old_tasks = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   443
        tasks = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   444
        if hasattr(bom_log.bom.content, 'project'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   445
            for project in bom_log.bom.content.project:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   446
                if hasattr(project, 'baseline'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   447
                    for baseline in project.baseline:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   448
                        if not old_baselines.has_key(unicode(baseline)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   449
                            old_baselines[unicode(baseline)] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   450
                        if hasattr(baseline, 'xml_attributes'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   451
                            _logger.debug('baseline.xml_attributes: %s' % baseline.xml_attributes)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   452
                            for attr_name, _ in sorted(baseline.xml_attributes.iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   453
                                _logger.debug('attr_name: %s' % attr_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   454
                                old_baselines[unicode(baseline)][unicode(attr_name)] = unicode(getattr(baseline, attr_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   455
                if hasattr(project, 'folder'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   456
                    for folder in project.folder:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   457
                        if hasattr(folder, 'name'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   458
                            for name in folder.name:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   459
                                folder_name = unicode(name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   460
                                _logger.debug('folder_name: %s' % folder_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   461
                            if not old_folders.has_key(unicode(folder_name)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   462
                                old_folders[unicode(folder_name)] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   463
                            if hasattr(name, 'xml_attributes'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   464
                                for attr_name, _ in sorted(name.xml_attributes.iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   465
                                    _logger.debug('attr_name: %s' % attr_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   466
                                    old_folders[unicode(folder_name)][unicode(attr_name)] = unicode(getattr(name, attr_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   467
        for task in recursive_node_scan(bom_log.bom.content, u'task'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   468
            _logger.debug('task: %s' % task)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   469
            _logger.debug('task: %s' % task.id)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   470
            _logger.debug('task: %s' % task.synopsis)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   471
            task_id = u"%s: %s" % (task.id, task.synopsis)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   472
            if not old_tasks.has_key(task_id):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   473
                old_tasks[task_id] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   474
            if hasattr(task, 'xml_attributes'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   475
                for attr_name, _ in sorted(task.xml_attributes.iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   476
                    _logger.debug('attr_name: %s' % attr_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   477
                    old_tasks[task_id][unicode(attr_name)] = unicode(getattr(task, attr_name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   478
        for project in self._bom.projects:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   479
            for folder in project.folders:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   480
                folders[unicode(folder.instance + "#" + folder.name + ": " + folder.description)] = {u'overridden':u'true'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   481
                for task in folder.tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   482
                    _logger.debug("task_bom:'%s'" % unicode(task))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   483
                    tasks[unicode(task)] = {u'overridden':u'false'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   484
            for task in project.tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   485
                _logger.debug("task_bom:'%s'" % unicode(task))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   486
                tasks[unicode(task)] = {u'overridden':u'true'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   487
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   488
        baselines = self._bom.all_baselines()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   489
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   490
        self._write_items_with_attributes(content_node, u'baseline', baselines, old_baselines)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   491
        self._write_items_with_attributes(content_node, u'folder', folders, old_folders)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   492
        self._write_items_with_attributes(content_node, u'task', tasks, old_tasks)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   493
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   494
        out = open(path, 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   495
        doc.xml(out, indent='yes')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   496
        out.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   497
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   498
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   499
    def validate_delta_bom_contents(self, delta_bom_log, bom_log, old_bom_log):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   500
        """ To validate delta bom contents with current bom and old bom. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   501
        delta_bom_log = amara.parse(open(delta_bom_log, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   502
        bom_log = amara.parse(open(bom_log, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   503
        old_bom_log = amara.parse(open(old_bom_log, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   504
        bom_contents_are_valid = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   505
        if hasattr(delta_bom_log.bomDelta.content, 'folder'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   506
            for delta_foder in delta_bom_log.bomDelta.content.folder:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   507
                if(getattr(delta_foder, 'status'))=='added':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   508
                    for bom_foder in bom_log.bom.content.project.folder:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   509
                        if(unicode(getattr(bom_foder, 'name')) == unicode(delta_foder)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   510
                            bom_contents_are_valid = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   511
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   512
                            bom_contents_are_valid = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   513
                if(getattr(delta_foder, 'status'))=='deleted':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   514
                    for old_bom_foder in old_bom_log.bom.content.project.folder:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   515
                        if(unicode(getattr(old_bom_foder, 'name')) == unicode(delta_foder)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   516
                            bom_contents_are_valid = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   517
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   518
                            bom_contents_are_valid = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   519
                        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   520
        if hasattr(delta_bom_log.bomDelta.content, 'task'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   521
            for delta_task in delta_bom_log.bomDelta.content.task:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   522
                if(getattr(delta_task, 'status'))=='added':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   523
                    for bom_task in recursive_node_scan(bom_log.bom.content, u'task'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   524
                        bom_task_id = u"%s: %s" % (bom_task.id, bom_task.synopsis)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   525
                        if(bom_task_id == unicode(delta_task)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   526
                            bom_contents_are_valid = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   527
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   528
                            bom_contents_are_valid = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   529
                if(getattr(delta_task, 'status'))=='deleted':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   530
                    for old_bom_task in recursive_node_scan(old_bom_log.bom.content, u'task'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   531
                        old_bom_task_id = u"%s: %s" % (old_bom_task.id, old_bom_task.synopsis)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   532
                        if(old_bom_task_id == unicode(delta_task)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   533
                            bom_contents_are_valid = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   534
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   535
                            bom_contents_are_valid = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   536
        return bom_contents_are_valid
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   537
     
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   538
    def _write_items(self, node, item_name, items, older_items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   539
        """write items"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   540
        items = frozenset(items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   541
        older_items = frozenset(older_items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   542
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   543
        items_added = list(items.difference(older_items))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   544
        items_added.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   545
        for item in items_added:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   546
            node.xml_append(node.xml_create_element(item_name, \
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   547
                            attributes={u'status': u'added'}, content=unicode(item)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   548
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   549
        items_deleted = list(older_items.difference(items))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   550
        items_deleted.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   551
        for item in items_deleted:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   552
            node.xml_append(node.xml_create_element(item_name, \
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   553
                            attributes={u'status': u'deleted'}, content=unicode(item)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   554
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   555
    def _write_items_with_attributes(self, node, item_name, items, older_items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   556
        """ This method takes dictionaries as input to pass along attributes"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   557
        fr_items = frozenset(items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   558
        fr_older_items = frozenset(older_items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   559
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   560
        items_added = list(fr_items.difference(fr_older_items))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   561
        items_added.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   562
        for item in items_added:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   563
            item_attributes = {u'status': u'added'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   564
            for attr_name, attr_value in sorted(items[item].iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   565
                _logger.debug('item: %s' % item)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   566
                _logger.debug('attr_name: %s' % attr_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   567
                _logger.debug('attr_value: %s' % attr_value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   568
                item_attributes[attr_name] = attr_value
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   569
            node.xml_append(node.xml_create_element(item_name, \
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   570
                            attributes=item_attributes, content=unicode(item)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   571
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   572
        items_deleted = list(fr_older_items.difference(fr_items))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   573
        items_deleted.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   574
        for item in items_deleted:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   575
            item_attributes = {u'status': u'deleted'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   576
            for attr_name, attr_value in sorted(older_items[item].iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   577
                _logger.debug('item: %s' % item)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   578
                _logger.debug('attr_name: %s' % attr_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   579
                _logger.debug('attr_value: %s' % attr_value)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   580
                item_attributes[attr_name] = attr_value
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   581
            node.xml_append(node.xml_create_element(item_name, \
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   582
                            attributes=item_attributes, content=unicode(item)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   583
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   584
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   585
class BOMXMLWriter(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   586
    """ This class is used to generate an xml file containing the BOM information """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   587
    def __init__(self, bom):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   588
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   589
        self._bom = bom
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   590
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   591
    def write(self, path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   592
        """ Write the BOM information to an XML file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   593
        doc = amara.create_document(u'bom')
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   594
        # pylint: disable=E1101
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   595
        doc.bom.xml_append(doc.xml_create_element(u'build', content=unicode(self._bom.config['build.id'])))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   596
        doc.bom.xml_append(doc.xml_create_element(u'content'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   597
        for project in self._bom.projects:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   598
            project_node = doc.xml_create_element(u'project')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   599
            project_node.xml_append(doc.xml_create_element(u'name', content=unicode(project)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   600
            project_node.xml_append(doc.xml_create_element(u'database', content=unicode(self._bom.config['ccm.database'])))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   601
            doc.bom.content.xml_append(project_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   602
            _logger.debug('baselines dictionary: %s' % project.baselines)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   603
            for baseline, baseline_attrs in sorted(project.baselines.iteritems()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   604
                _logger.debug('baseline: %s' % baseline)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   605
                _logger.debug('baseline_attrs: %s' % baseline_attrs)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   606
                project_node.xml_append(doc.xml_create_element(u'baseline', content=unicode(baseline), attributes=baseline_attrs))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   607
            for folder in project.folders:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   608
                folder_node = doc.xml_create_element(u'folder')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   609
                folder_node.xml_append(doc.xml_create_element(u'name', content=unicode(folder.instance + "#" + folder.name + ": " + folder.description), \
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   610
                            attributes={u'overridden':u'true'}))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   611
                project_node.xml_append(folder_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   612
                for task in folder.tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   613
                    task_node = doc.xml_create_element(u'task', attributes={u'overridden':u'false'})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   614
                    task_node.xml_append(doc.xml_create_element(u'id', content=(unicode(task['displayname']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   615
                    task_node.xml_append(doc.xml_create_element(u'synopsis', content=(unicode(task['task_synopsis']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   616
                    task_node.xml_append(doc.xml_create_element(u'owner', content=(unicode(task['owner']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   617
                    #task_node.xml_append(doc.xml_create_element(u'completed', content=(unicode(self.parse_status_log(task['status_log'])))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   618
                    folder_node.xml_append(task_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   619
            for task in project.tasks:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   620
                task_node = doc.xml_create_element(u'task', attributes={u'overridden':u'true'})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   621
                task_node.xml_append(doc.xml_create_element(u'id', content=(unicode(task['displayname']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   622
                task_node.xml_append(doc.xml_create_element(u'synopsis', content=(unicode(task['task_synopsis']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   623
                task_node.xml_append(doc.xml_create_element(u'owner', content=(unicode(task['owner']))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   624
                #task_node.xml_append(doc.xml_create_element(u'completed', content=(unicode(self.parse_status_log(task['status_log'])))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   625
                project_node.xml_append(task_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   626
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   627
                fix = task.has_fixed()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   628
                if fix != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   629
                    fix_node = doc.xml_create_element(u'fix', content=(unicode(task)), attributes = {u'type': unicode(fix.__class__.__name__)})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   630
                    project_node.xml_append(fix_node)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   631
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   632
        if self._bom.icd_icfs != []:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   633
            # Add ICD info to BOM
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   634
            doc.bom.content.xml_append(doc.xml_create_element(u'input'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   635
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   636
            # Add default values to unused fields so icds are visible in the BOM
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   637
            empty_bom_str = u'N/A'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   638
            empty_bom_tm = u'0'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   639
            doc.bom.content.input.xml_append(doc.xml_create_element(u'name', content=(unicode(empty_bom_str))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   640
            doc.bom.content.input.xml_append(doc.xml_create_element(u'year', content=(unicode(empty_bom_tm))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   641
            doc.bom.content.input.xml_append(doc.xml_create_element(u'week', content=(unicode(empty_bom_tm))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   642
            doc.bom.content.input.xml_append(doc.xml_create_element(u'version', content=(unicode(empty_bom_str))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   643
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   644
            doc.bom.content.input.xml_append(doc.xml_create_element(u'icds'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   645
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   646
        # pylint: disable=R0914
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   647
        for i, icd in enumerate(self._bom.icd_icfs):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   648
            doc.bom.content.input.icds.xml_append(doc.xml_create_element(u'icd'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   649
            doc.bom.content.input.icds.icd[i].xml_append(doc.xml_create_element(u'name', content=(unicode(icd))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   650
        #If currentRelease.xml exists then send s60 <input> tag to diamonds
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   651
        current_release_xml_path = self._bom.config['currentRelease.xml']
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   652
        # data from the metadata will go first as they must be safer than the one
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   653
        # given by the user 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   654
        if current_release_xml_path is not None and os.path.exists(current_release_xml_path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   655
            metadata = symrec.ReleaseMetadata(current_release_xml_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   656
            service = metadata.service
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   657
            product = metadata.product
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   658
            release = metadata.release
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   659
            # Get name, year, week and version from baseline configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   660
            s60_input_node = doc.xml_create_element(u'input')
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   661
            s60_type = u's60'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   662
            s60_year = u'0'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   663
            s60_week = u'0'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   664
            s60_release = u''
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   665
            # Using regular expression in first place
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   666
            regexp = r'(?P<TYPE>.*)_(?P<YEAR>\d{4})(?P<WEEK>\d{2})_(?P<REVISION>.*)'            
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   667
            if self._bom.config['release_regexp']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   668
                if '?P<TYPE>' not in self._bom.config['release_regexp']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   669
                    _logger.error('Missing TYPE in: %s' % str(self._bom.config['release_regexp']))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   670
                    _logger.info('Using default regular expression: %s' % regexp)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   671
                elif '?P<YEAR>' not in self._bom.config['release_regexp']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   672
                    _logger.error('Missing YEAR in: %s' % str(self._bom.config['release_regexp']))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   673
                    _logger.info('Using default regular expression: %s' % regexp)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   674
                elif '?P<WEEK>' not in self._bom.config['release_regexp']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   675
                    _logger.error('Missing WEEK in: %s' % str(self._bom.config['release_regexp']))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   676
                    _logger.info('Using default regular expression: %s' % regexp)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   677
                elif '?P<REVISION>' not in self._bom.config['release_regexp']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   678
                    _logger.error('Missing REVISION in: %s' % str(self._bom.config['release_regexp']))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   679
                    _logger.info('Using default regular expression: %s' % regexp)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   680
                else:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   681
                    _logger.info('Using custom regular expression to capture the baseline release information: %s'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   682
                                  % str(self._bom.config['release_regexp']))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   683
                    regexp = self._bom.config['release_regexp']                
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   684
            res = re.match(regexp, release)            
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   685
            if res != None:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   686
                s60_type = res.group('TYPE')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   687
                s60_release = res.group('TYPE') + '_' + res.group('REVISION')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   688
                s60_year = res.group('YEAR')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   689
                s60_week = res.group('WEEK')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   690
            else:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   691
                _logger.warning("Regular expression '%s' is not matching '%s'." % (regexp, release))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   692
                if self._bom.config['s60_version'] != None:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   693
                    # last resorts if it doesn't matches
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   694
                    _logger.warning("Falling back on s60.version and s60.release to determine input.")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   695
                    s60_version = self._bom.config['s60_version']
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   696
                    s60_year = s60_version[0:4]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   697
                    s60_week = s60_version[4:]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   698
                    if self._bom.config['s60_release']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   699
                        s60_release = self._bom.config['s60_release']
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   700
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   701
            s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode(s60_type))))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   702
            s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   703
            s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   704
            s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   705
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   706
            s60_input_source = s60_input_node.xml_create_element(u'source')
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   707
            s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("hydra"))))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   708
            s60_input_source.xml_append(doc.xml_create_element(u'service', content=(unicode(service))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   709
            s60_input_source.xml_append(doc.xml_create_element(u'product', content=(unicode(product))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   710
            s60_input_source.xml_append(doc.xml_create_element(u'release', content=(unicode(release))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   711
            s60_input_node.xml_append(s60_input_source)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   712
            doc.bom.content.xml_append(s60_input_node)
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   713
        elif self._bom.config['s60_version'] and self._bom.config['s60_release']:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   714
            _logger.info("currentRelease.xml not defined, falling back on s60.version and s60.release to determine input.")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   715
            s60_type = u's60'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   716
            s60_version = self._bom.config['s60_version']
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   717
            s60_year = u'0'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   718
            s60_week = u'0'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   719
            if len(s60_version) > 6:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   720
                s60_year = s60_version[0:4]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   721
                s60_week = s60_version[4:]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   722
            s60_release = self._bom.config['s60_release']
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   723
            s60_input_node = doc.xml_create_element(u'input')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   724
            s60_input_node.xml_append(doc.xml_create_element(u'name', content=(unicode(s60_type))))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   725
            s60_input_node.xml_append(doc.xml_create_element(u'year', content=(unicode(s60_year))))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   726
            s60_input_node.xml_append(doc.xml_create_element(u'week', content=(unicode(s60_week))))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   727
            s60_input_node.xml_append(doc.xml_create_element(u'version', content=(unicode(s60_release))))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   728
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   729
            s60_input_source = s60_input_node.xml_create_element(u'source')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   730
            s60_input_source.xml_append(doc.xml_create_element(u'type', content=(unicode("unknown"))))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   731
            s60_input_node.xml_append(s60_input_source)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   732
            doc.bom.content.xml_append(s60_input_node)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   733
            
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   734
            
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   735
        out = open(path, 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   736
        doc.xml(out, indent='yes')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   737
        out.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   738
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   739
    def parse_status_log(self, log):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   740
        """parse status log"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   741
        _log_array = log.split('\r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   742
        if(len(_log_array) == 3 and log.find('completed') > 0):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   743
            _completed_line = _log_array[2]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   744
            return _completed_line[:_completed_line.rfind(':')].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   745
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   746
            return u'None'