buildframework/helium/sf/python/pythoncore/lib/atsant.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
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
# -*- encoding: latin-1 -*-
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
#Name        : atsant.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
""" get the files needed to test ATS"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import sysdef.api
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import configuration
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    29
import amara
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
_logger = logging.getLogger('atsant')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
class IConfigATS(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    """ Class used to read configuration file iconfig.xml """
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    35
    def __init__(self, imagesdir, productname):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        self.imagesdir = imagesdir
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    37
        self.productname = productname
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        self.config = self.getconfig()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    40
    def getconfig(self, type_=None, productname=None):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        """get configuration"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        noncust = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        for root, _, files in os.walk(self.imagesdir, topdown=False):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
            for fname in files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
                if 'iconfig.xml' in fname:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
                    filePath = os.path.join(root, fname)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
                    configBuilder = configuration.NestedConfigurationBuilder(open(filePath, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
                    configSet = configBuilder.getConfiguration()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
                    for config in configSet.getConfigurations():
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    50
                        if type_ and productname:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    51
                            if type_ in config.type and config['PRODUCT_NAME'].lower() in productname.lower():
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
                                return config
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
                            noncust = config
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    55
        if type_:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
            return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        if noncust:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
            return noncust
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        raise Exception('iconfig not found in ' + self.imagesdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    def getimage(self, name):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        """get image"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        for root, _, files in os.walk(self.imagesdir, topdown=False):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
            for fname in files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
                if fname.lower() == name.lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
                    return os.path.join(root, fname)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        raise Exception(name + ' not found in ' + self.imagesdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    def findimages(self): 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        """find images"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        output = ''
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    72
        for imagetype, imagetypename in [('core', 'CORE'), ('langpack', 'ROFS2'), ('cust', 'ROFS3'), ('udaerase', 'UDAERASE'), ('emmc', 'EMMC')]:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    73
            iconfigxml = self.getconfig(imagetype, self.productname)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
            if iconfigxml == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
                iconfigxml = self.config
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
            if iconfigxml.has_key(imagetypename + '_FLASH'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
                (drive, _) = os.path.splitdrive(self.imagesdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
                image = os.path.join(drive, iconfigxml[imagetypename + '_FLASH'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
                if not os.path.exists(image):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
                    image = self.getimage(os.path.basename(image))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
                if os.path.exists(image):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
                    output = output + image + ','
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
                    raise Exception(image + ' not found')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
                if imagetype == 'core':
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    88
                    raise Exception(imagetypename + '_FLASH not found in iconfig.xml in ' + self.imagesdir)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
                print imagetypename + '_FLASH not found in iconfig.xml'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        return output
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    92
def get_boolean(string_val):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    93
    """if parameter passed in is not present in the project it will produce 'none'
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    94
       as a result so this will be converted to boolean false as will all values
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    95
        except true."""
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    96
    retVal = False
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    97
    if (string_val == 'true'):
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    98
        retVal = True
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    99
    return retVal
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   100
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   101
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   102
def files_to_test(canonicalsysdeffile, excludetestlayers, idobuildfilter, builddrive, createmultipledropfiles, sysdef3=False):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    """list the files to test"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    modules = {}
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   105
    if sysdef3 == True:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
        sdf = amara.parse(open(canonicalsysdeffile))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   107
        for package in sdf.SystemDefinition.systemModel.package:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   108
            for collection in package.collection:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   109
                if hasattr(collection, 'component'): 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   110
                    for component in collection.component:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   111
                        print component.id
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
                        if get_boolean(createmultipledropfiles):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   113
                            group = 'singledropfile'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   114
                        else:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   115
                            group = 'default'
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   116
                        if hasattr(component, 'meta') and hasattr(component.meta, 'group'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   117
                            if not group.lower() == 'singledropfile':
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
                                group = component.meta.group[0].name                            
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   119
                        if hasattr(component, 'unit'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
                            for unit in component.unit:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   121
                                if group not in modules:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   122
                                    modules[group] = []
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
                                modules[group].append(builddrive + os.sep + unit.bldFile)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   124
    else:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
        sdf = sysdef.api.SystemDefinition(canonicalsysdeffile)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   126
        
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
        single_key = 'singledropfile'       #default single drop file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   128
       
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   129
        for layr in sdf.layers:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   130
            if re.match(r".*_test_layer$", layr):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
                if excludetestlayers and re.search(r"\b%s\b" % layr, excludetestlayers):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
                    continue
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   133
                layer = sdf.layers[layr]
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   134
                for mod in layer.modules:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   135
                    if get_boolean(createmultipledropfiles):  #creating single drop file?
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   136
                        if single_key not in modules:       #have we already added the key to the dictionary?
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   137
                            modules[single_key] = []        #no so add it
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   138
                    elif mod.name not in modules:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   139
                        modules[mod.name] = []
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   140
                        single_key = mod.name               #change the key name to write to modules
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   141
                    for unit in mod.units:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   142
                        include_unit = True
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   143
                        if idobuildfilter != None:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   144
                            if idobuildfilter != "":
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   145
                                include_unit = False
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
                                if hasattr(unit, 'filters'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
                                    if len(unit.filters) > 0:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   148
                                        for afilter in unit.filters:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   149
                                            include_unit = re.search(r"\b%s\b" % afilter, idobuildfilter)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   150
                                    elif len(unit.filters) == 0:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   151
                                        include_unit = True
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   152
                                else:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   153
                                    include_unit = False
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
                            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
                                include_unit = False
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   156
                                if hasattr(unit, 'filters'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   157
                                    if len(unit.filters) == 0:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   158
                                        include_unit = True
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   159
                        if include_unit:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   160
                            modules[single_key].append(builddrive + os.sep + unit.path)
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   161
    return modules
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162