buildframework/helium/sf/python/blockspackager/lib/packager/datasources/cone.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 645 b8d81fa19e7d
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
645
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     1
#============================================================================ 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     2
#Name        : conftool.py 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     4
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     6
#All rights reserved.
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    11
#
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    12
#Initial Contributors:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    14
#
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    15
#Contributors:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    16
#
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    17
#Description:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    18
#===============================================================================
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    19
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    20
from packager.datasources.api import DataSource, DATASOURCES
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    21
from Blocks.Packaging.BuildData import PlainBuildData
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    22
import logging
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    23
import re 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    24
import os
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    25
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    26
logger = logging.getLogger('packager.datasources.conftool')
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    27
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    28
class ConEDataSource(DataSource):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    29
    """ Extract information from ConE logs """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    30
    def __init__(self, epocroot, data=None):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    31
        DataSource.__init__(self, epocroot, data)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    32
    
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    33
    def getTargetFiles(self):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    34
        """ Get the generated files from the log output. """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    35
        result = []
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    36
        txtFile = open(self._data['filename'], 'r')
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    37
        matcher = re.compile(r"^\s*Generating file '(.+)'\.\.\.\s*$")
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    38
        for line in txtFile:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    39
            res = matcher.match(line)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    40
            if res:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    41
                result.append(os.path.normpath(os.path.join(self.epocroot, 
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    42
                                                            res.group(1))))
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    43
        txtFile.close()
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    44
        return result
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    45
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    46
    def getComponents(self):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    47
        """ Get the components list from the cli input. """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    48
        if 'name' not in self._data:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    49
            raise Exception("The name property has not be defined.")
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    50
        if 'version' not in self._data:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    51
            raise Exception("The version property has not be defined.")
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    52
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    53
        if 'filename' not in self._data:
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    54
            raise Exception("The input conftool log file is not defined")
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    55
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    56
        #todo: add the source iby / path for conftool input
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    57
        build_data = PlainBuildData()
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    58
        build_data.setComponentName(self._data['name'])
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    59
        build_data.setComponentVersion(self._data['version'])
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    60
        build_data.setSourceRoot(self.epocroot)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    61
        build_data.setTargetRoot(self.epocroot)
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    62
        build_data.addTargetFiles([path[len(self.epocroot):].lstrip(os.sep) for path in self.getTargetFiles()])
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    63
        return [build_data]
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    64
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    65
    def getHelp(self):
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    66
        """ Returns the help. """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    67
        return """
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    68
name            Defines the name of the component
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    69
version         Defines the version of the component
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    70
filename        Defines the log file name of ctool
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    71
"""
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    72
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    73
        
b8d81fa19e7d helium_12.0.0-63b64366f9cf
wbernard
parents:
diff changeset
    74
DATASOURCES['cone'] = ConEDataSource