buildframework/helium/sf/python/pythoncore/lib/ats3/parsers.py
author wbernard
Thu, 22 Jul 2010 17:08:43 +0300
branchhelium-9.0
changeset 618 df88fead2976
parent 587 85df38eb4012
permissions -rw-r--r--
helium_9.0.5-4399343f4f50
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        : parsers.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
""" The ATS related parsers """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
# pylint: disable-msg=W0142,W0102
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
# pylint: disable-msg=C0302
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
# pylint: disable-msg=R0201,R0912,R0915,R0911,R0902
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
#W0142 => * and ** were used
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
#W0102 => Dangerous default value [] as argument
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
#C0302 => Too many lines
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
#R* remove during refactoring
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
import re
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
from path import path # pylint: disable-msg=F0401
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
import fnmatch
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
import subprocess
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
import codecs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
import traceback
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
_logger = logging.getLogger('ats-parser')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
import configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
def split_config_to_attributes_and_properties(specfile):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    """Split the specfile to its parts"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    attributes = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    properties = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    builder = configuration.NestedConfigurationBuilder(specfile)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    configs = builder.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    # the supported configs are either attributes or properties
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    # collect each in a dictionary and return them.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    for config in configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        if config.name == 'attributes' :
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
            for attr in config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
                attributes[attr] = config[attr]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        if config.name == 'properties' :
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
            for prop in config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
                properties[prop] = config[prop]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    return (properties, attributes)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
class CppParser(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    Parser for CPP tool output. Returns cleaned output from the execution
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    of CPP with or without parent paths included in the output.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    def __init__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        self.path_to_build = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    def get_cpp_output(self, bld_path = None, output_parameter = "n", imacros = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        To clean out conditionals from the compilation it is necessary to 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        use C preprocessing to clean out those.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        If ('n' - normal) output is chosen, parser returns list of paths
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        If ('e' - extended) output is chosen parser returns list of (path, parent_path) tuples
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        If ('d' - dependency) output is chosen parser returns a dicitionary (can be a nested dictionary) 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
                  of paths dependency (-ies). 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
                  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        'imacros' can also be given as parameters for CPP options.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        if bld file is not given, the function will try to find the file(s) on the given location with extension ".inf"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        temp_path = os.getcwd()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        if "bld.inf" in str(bld_path).lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
            os.chdir(os.path.normpath(os.path.join(bld_path, os.pardir)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
            os.chdir(os.path.normpath(os.path.join(bld_path)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        if imacros is not None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
            includedir = os.path.join(os.path.splitdrive(bld_path)[0] + os.sep, 'epoc32', 'include')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
            command = r"cpp -imacros %s -I %s bld.inf" % (str(imacros), includedir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
            command = u"cpp bld.inf"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        pipe = process.stdout
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        if output_parameter == "d":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
            return self.create_dependency_dictionary(pipe, bld_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        #If not depdendency dictiontionary then create normal or extended list
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        #Creates dictionary for 'n' (normal) and 'e' extended paths
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        clean_path_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        path_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        for line in pipe.readlines():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
            #_logger.debug(line.strip())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
            if re.search(r"\A#\s.*?", line.strip()) or re.search(r"\A#.*?[0-9]", line.strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
                if line.strip() not in path_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
                    path_list.append(line.strip())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        process.wait()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        if process.returncode == 1:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
            _logger.error('CPP failed: ' + command + ' in: ' + os.getcwd())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        pipe.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        os.chdir(temp_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        if output_parameter is "n":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
            for _path in self.clean_cpp_output(bld_path, path_list):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
                clean_path_list.append(_path[0])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        elif output_parameter is "e":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
            clean_path_list = self.clean_cpp_output(bld_path, path_list)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
        clean_path_list = list(set(clean_path_list))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
        bfp = BldFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
        for tsrc in clean_path_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
            mmp_path = bfp.get_test_mmp_files(tsrc[0])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
            if tsrc[0] == tsrc[1]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
                if mmp_path == None or mmp_path == []:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
                    clean_path_list.remove(tsrc)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        return clean_path_list
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
    def create_dependency_dictionary(self, _pipe_, path_to_bld):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        The output from CPP is cleaned in a fashion that the output is
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        a dictionary (or nested dictionary) of paths and their dependencies.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        bld_parser = BldFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        pkg_parser = PkgFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
        mmp_parser = MmpFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        temp_path = os.getcwd()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        parent = os.getcwd()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        self.path_to_build = path_to_bld
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
        test_sets = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
        harness = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
        main_level = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
        test_cases = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
        output_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        for line in _pipe_.readlines():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            if re.match(r"#.*", line.lower()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
                #_logger.debug(line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
                tpat =  re.findall(r'"(.*bld.inf?)"', line.lower())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                if tpat != []:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
                    output_list.append((line, os.path.dirname(os.path.normpath(os.path.join(self.path_to_build, tpat[0])))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
        _pipe_.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
        #Creating dependencies
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        for case in output_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            if re.match(r".*[bld.inf][^0-9]\Z", case[0].lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                if main_level == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
                    main_level = case[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
                parent = case[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
                os.chdir(case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
                test_cases.append((parent, case[1]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
            elif re.match(r".*[1]\Z", case[0].lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
                parent = os.getcwd()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
                os.chdir(case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
                test_cases.append((parent, case[1]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
            elif re.match(r".*[2]\Z", case[0].lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
                if test_cases:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
                    for tcase in test_cases:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
                        if parent in tcase[1]:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                            parent = tcase[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
                            os.chdir(tcase[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
                            break
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
                        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
        for t_case in test_cases:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
            if t_case[0] == t_case[1] and (not bld_parser.get_test_mmp_files(t_case[1])):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
                del t_case
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
            elif t_case[0] in main_level:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
                test_sets[t_case[1]] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
                test_sets[t_case[1]]['content'] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
                test_sets[t_case[1]]['content'][t_case[1]] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
                harness = mmp_parser.get_harness(t_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
                #if harness == "": harness = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
                test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
                test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
                test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
                test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
                for key, value in test_sets.items():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
                    if t_case[0] in value['content'].keys():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
                        harness = mmp_parser.get_harness(t_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
                        if harness is "" or harness in test_sets[key]['content'][t_case[0]]['harness']:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
                            test_sets[key]['content'][t_case[1]] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
                            test_sets[key]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
                            test_sets[key]['content'][t_case[1]]['harness'] = harness
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
                            test_sets[key]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
                            test_sets[key]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
                            test_sets[t_case[1]] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
                            test_sets[t_case[1]]['content'] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
                            test_sets[t_case[1]]['content'][t_case[1]] = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
                            test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
                            test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
                            test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
                            test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        os.chdir(temp_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        if test_sets == {}:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
            for itm in output_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
                _logger.debug(itm)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
            for itm in test_cases:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
                _logger.debug(itm)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
            _logger.error(path_to_bld + ' test_sets are empty')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
        return test_sets
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
    def clean_cpp_output(self, bld_path, path_list):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
        The output from CPP needs to be "cleaned" so that extra chars needs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
        to be removed and also hierarchy which cpp is following is preserved
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
        and returned as an output. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
        pat = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
        value = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
        cleaned_output = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
        if "bld.inf" in bld_path:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
            path_to_parent = os.path.dirname(bld_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
            path_to_parent = bld_path
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
        pat = re.compile(r'\A#\s*?.*?[\"](.*?)[\"].*?')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
        for _path in path_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
            if re.match(r".*[bld.inf]\s*?[^0-9]\Z", _path.lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
                value = pat.match(_path.strip())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
                path_to_tc = os.path.dirname(os.path.normpath(os.path.join((bld_path), value.group(1))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
                cleaned_output.append((path_to_tc, path_to_parent))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
            if re.match(r".*[1]\s*?\Z", _path.lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
                value = pat.match(_path.strip())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
                path_to_tc = os.path.dirname(os.path.normpath(os.path.join(bld_path, value.group(1))))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
                cleaned_output.append((path_to_tc, path_to_parent))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
            if re.match(r".*[2]\s*?\Z", _path.lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
                if cleaned_output:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
                    for cout in cleaned_output:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
                        if path_to_parent.lower() == cout[0].lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
                            path_to_tc = cout[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
            path_to_parent = path_to_tc
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
        return cleaned_output
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
class BldFileParser(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
    Parser for bld.inf files. Returns MACRO values.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
    Parsing Paths can be done using CPP parser  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
    def __init__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
        self.mmp_files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
    #def get_mmp_files():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
    #    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
    #    returns mmp files from PRJ_MMPFILES macro
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
    #   """    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
    def get_test_mmp_files(self, bld_file_path = None, with_full_path = True):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
        returns a list of test mmp files 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
        Usage: if "x:\abc\bldfile", "PRJ_TESTMMPFILES". 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   280
        1. get_test_mmp_files("x:\abc\bldfile") - with full paths e.g. ["x:\abc\abc.mmp"]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
        2. get_test_mmp_files("x:\abc\bldfile", False) - without full paths e.g. ["abc.mmp"]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
        if bld file is not given, the function will try to find the file(s) on the given location with extension ".inf"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   284
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
        if bld_file_path == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
            _logger.warning("Incorrect bld file")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
            return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
            bld_file_path = path(bld_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   291
            if not "bld.inf" in str(bld_file_path).lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
                bld_file_path = os.path.join(os.path.normpath(bld_file_path), "bld.inf")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   294
            if not os.path.exists(bld_file_path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
                _logger.error(r"bld file path does not exist: '%s'" % bld_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
                return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   298
        return self.get_files(path(bld_file_path), "PRJ_TESTMMPFILES", with_full_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
    def get_files(self, bld_inf_path, bld_macro, with_full_path = True):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
        Component's MMP files, as stored in BLD.INF.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   305
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
        bld_inf_path = path(bld_inf_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   307
        bld_inf = bld_inf_path.text()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
        if bld_inf.count(bld_macro) > 1:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
            _logger.error(bld_macro + ' in ' + bld_inf_path + ' more than once')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   310
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
            bld_inf = re.compile(r"%s" % bld_macro).split(bld_inf)[1].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   312
            bld_inf = re.compile(r"PRJ_+\S").split(bld_inf)[0].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   313
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
        except IndexError:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
            try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   316
                bld_inf = re.compile(r"%s" % bld_macro).split(bld_inf)[0].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   317
                bld_inf = re.compile(r"PRJ_+\S").split(bld_inf)[0].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   318
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   319
            except IndexError:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
                _logger.warning("Index Error while parsing bld.inf file")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   322
        comments_free_text = self.ignore_comments_from_input(bld_inf)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   323
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   324
        self.mmp_files = re.findall(r"(\S+?[.]mmp)", comments_free_text, re.IGNORECASE)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   325
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   326
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   327
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   328
        if with_full_path:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   329
            bld_dir = bld_inf_path.dirname()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   330
            return [path.joinpath(bld_dir, mmp).normpath()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   331
                    for mmp in self.mmp_files]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   332
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   333
            return self.mmp_files
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
    def ignore_comments_from_input(self, input_str = ""):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
        Removes comments from the input string. Enables the use of examples
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
        in bld.inf.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   339
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   340
        _input = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   341
        for i in input_str.split("\n"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   342
            _input += "\n" + i.split("//")[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   343
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   344
        if not _input == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   345
            input_str = _input
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   346
        count = input_str.count("/*")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   347
        count2 = input_str.count("*/")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   348
        if (count == count2):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   349
            idx_1 = input_str.find('/*')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   350
            idx_2 = input_str.find('*/') + 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
            while count > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   352
                substr_1 = input_str[:idx_1].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
                substr_2 = input_str[idx_2:].strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   354
                input_str = substr_1 + " " + substr_2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   355
                idx_1 = input_str.find('/*')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
                idx_2 = input_str.find('*/') + 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
                count = input_str.count('/*')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
            return input_str.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   360
            _logger.warning("Comments in bld.inf-file inconsistent. "
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   361
                            "Check comments in bld.inf.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   362
            return input_str.strip()
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
    #def get_exports():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   366
    #    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
    #    returns exports from the macro PRJ_EXPORTS
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   368
    #    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   370
class MmpFileParser(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   371
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   372
    Parser for .mmp files. Returns wanted information from the mmp-file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
    - file type (executable dll, plugin, exe, etc)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   374
    - test harness (STIF, EUNIT) if mmp is related to the test component
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   375
    - file name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
    - libraries listed in the mmp
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   379
    def __init__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   380
        self.mmp_files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   381
        self.path_to_mmp = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   382
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
    def get_target_filetype(self, path_to_mmp = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   384
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
        Filetype given using TARGETTYPE in .mmp file is returned.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   386
        If "c:\path\to\mmp" is a location where mmp file is stored
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   387
        get_target_filetype("c:\path\to\mmp")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   388
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   389
        if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
        return self.read_information_from_mmp(path_to_mmp, 4)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
    def get_target_filename(self, path_to_mmp = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
        Filename given using TARGET in .mmp file is returned
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
        If "c:\path\to\mmp" is a location where mmp file is stored
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
        get_target_filename("c:\path\to\mmp")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
        if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   401
        return self.read_information_from_mmp(path_to_mmp, 3)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
    def get_libraries(self, path_to_mmp = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
        Libraries listed in the MMP file are returned in a list
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   406
        If "c:\path\to\mmp" is a location where mmp file is stored
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
        get_libraries("c:\path\to\mmp")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   409
        if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   410
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
        return self.read_information_from_mmp(path_to_mmp, 5)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
    def get_harness(self, path_to_mmp = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415
        Returns harness of test component
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   416
        If "c:\path\to\mmp" is a location where mmp file is stored
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   417
        get_harness("c:\path\to\mmp")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   418
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   419
        if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   420
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   421
        return self.read_information_from_mmp(path_to_mmp, 6)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   422
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   423
    def get_dll_type(self, path_to_mmp = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   424
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   425
        Returns type of test whether 'executable' or 'dependent' (dependent can be a stub or plugin)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   426
        If "c:\path\to\mmp" is a location where mmp file is stored
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   427
        get_dll_type("c:\path\to\mmp")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   428
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   429
        if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   430
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   431
        return self.read_information_from_mmp(path_to_mmp, 7)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   432
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   433
    def read_information_from_mmp(self, path_to_mmp, flag = 0):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   434
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   435
        Returns wanted information - user can define 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   436
        the wanted information level by setting a flag
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   437
        value following way:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   438
        0 - (targetfilename, filetype, libraries, harness)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   439
        1 - (targetfilename, filetype, libraries)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   440
        2 - (targetfilename, filetype)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   441
        3 - targetfilename
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   442
        4 - filetype
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   443
        5 - libraries
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   444
        6 - harness (in case of test component)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   445
        7 - mmpfilename
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   446
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   447
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   448
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   449
        filename = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   450
        filetype = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   451
        dll_type = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   452
        libraries = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   453
        lst_mmp_paths = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   454
        harness = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   455
        stif = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   456
        eunit = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   457
        stifunit = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   458
        tef = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   459
        self.path_to_mmp = path_to_mmp
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   460
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   461
            if isinstance(path_to_mmp, list):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   462
                lst_mmp_paths = self.path_to_mmp
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   463
            else:    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   464
                self.path_to_mmp = path(self.path_to_mmp)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   465
                if not ".mmp" in str(self.path_to_mmp).lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   466
                    bld_parser = BldFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   467
                    self.mmp_files = bld_parser.get_test_mmp_files(self.path_to_mmp, False)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   468
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   469
                    for mpath in self.mmp_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   470
                        lst_mmp_paths.append(os.path.join(self.path_to_mmp, mpath))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   471
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   472
                    lst_mmp_paths.append(self.path_to_mmp)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   473
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   474
            for mmp in lst_mmp_paths:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   475
                mmp_file = open(mmp, 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   476
                for line in mmp_file:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   477
                    if re.match(r"\A(target\s).*([.]\w+)", line.lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   478
                        found = re.findall(r"\Atarget[\s]*(\w+[.]\w+)", line.lower())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   479
                        if found:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   480
                            filename = found[0]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   481
                    elif re.match(r"\A(targettype\s).*", line.lower().strip()):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   482
                        found = re.findall(r"\Atargettype[\s]*(\w+)", line.lower())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   483
                        if found:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   484
                            filetype = found[0]                       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   485
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   486
                libraries = libraries + re.findall(r"\b(\w+[.]lib)\b", mmp.text().lower())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   487
                if '//rtest' in mmp.text().lower() or '* rtest' in mmp.text().lower() or '// rtest' in mmp.text().lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   488
                    libraries.append('rtest')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   489
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   490
            if libraries:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   491
                if "stiftestinterface.lib" in libraries:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   492
                    stif = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   493
                if "eunit.lib" in libraries or "qttest.lib" in libraries:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   494
                    eunit = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   495
                if "stifunit.lib" in libraries:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   496
                    stifunit = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   497
                elif "testexecuteutils.lib" in libraries or 'testframeworkclient.lib' in libraries or 'rtest' in libraries:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   498
                    tef = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   499
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   500
            if tef:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   501
                harness = "GENERIC"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   502
            elif stif and eunit:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   503
                #_logger.warning("both eunit.lib and stiftestinterface.lib listed in mmp file - choosing STIF.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   504
                harness = "STIF"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   505
            elif stif and not eunit:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   506
                harness = "STIF"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   507
            elif eunit and not stif:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   508
                harness = "EUNIT"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   509
            elif stifunit and not stif and not eunit:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   510
                harness = "STIFUNIT"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   511
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   512
            if harness is "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   513
                dll_type = "dependent"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   514
            elif harness is "EUNIT":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   515
                dll_type = "executable"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   516
            elif harness is "STIF":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   517
                dll_type = "executable"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   518
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   519
        except:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   520
            traceback.print_exc()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   521
        finally:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   522
            if flag == 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   523
                return (filename, filetype, libraries, harness)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   524
            elif flag == 1:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   525
                return (filename, filetype, libraries)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   526
            elif flag == 2:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   527
                return (filename, filetype)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   528
            elif flag == 3:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   529
                return filename
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   530
            elif flag == 4:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   531
                return filetype
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   532
            elif flag == 5:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   533
                return libraries
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   534
            elif flag == 6:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   535
                return harness
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   536
            elif flag == 7:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   537
                return dll_type
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   538
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   539
class PkgFileParser(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   540
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   541
    Parses .pkg files. Returns a list of:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   542
      a. src path of the file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   543
      b. dst path on the phone
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   544
      c. type of the file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   545
    for every file in the pkg file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   546
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   547
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   548
    def __init__(self, platform = None, specific_pkg = None, drive=''):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   549
        self.platform = platform
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   550
        self.build_platform = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   551
        if self.platform is not None and "_" in self.platform:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   552
            plat_tar = re.search(r"(.*)_(.*).pkg", self.platform)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   553
            self.build_platform, self.build_target = plat_tar.groups() 
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   554
        self.drive = drive
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   555
        self._files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   556
        self.pkg_files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   557
        self.pkg_file_path = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   558
        self.exclude = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   559
        self.location = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   560
        self.specific_pkg = specific_pkg
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   561
        if specific_pkg:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   562
            self.platform = specific_pkg + '.pkg'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   563
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   564
    def get_pkg_files(self, location = None, with_full_path = True):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   565
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   566
        Returns list of PKG files on the given location. If True, full path is returned 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   567
        otherwise only filenames. Default is set to True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   568
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   569
        Assume at location "c:\abd\files", two pkg file '1.pkg' and '2.pkg', then the funtion
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   570
        can be called as:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   571
        1. get_pkg_files("c:\abd\files")        - will return a list of pkg files with full paths. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   572
                                                  like ['c:\abd\files\1.pkg', 'c:\abd\files\2.pkg']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   573
        2. get_pkg_files("c:\abd\files", False) - will return a list of pkg files only. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   574
                                                  like ['1.pkg', '2.pkg']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   575
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   576
        self.location = path(location)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   577
        self.pkg_files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   578
        if not self.location.exists():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   579
            return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   580
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   581
        for pths, _, files in os.walk(self.location):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   582
            pfiles = [f for f in files if self.platform != None and f.endswith(self.platform)]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   583
            if self.platform != None and len(pfiles)>0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   584
                if with_full_path:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   585
                    self.pkg_files.append(os.path.join(pths, pfiles[0]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   586
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   587
                    self.pkg_files.append(str(pfiles[0]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   588
            elif self.specific_pkg == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   589
                for name in files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   590
                    if fnmatch.fnmatch(name, "*.pkg"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   591
                        if with_full_path:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   592
                            self.pkg_files.append(os.path.join(pths, name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   593
                        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   594
                            self.pkg_files.append(str(name))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   595
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   596
        return self.pkg_files
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   597
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   598
    def get_data_files(self, location = [], drive = "", exclude = ""):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   599
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   600
        Returns data files, source and destination of the files to be installed 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   601
        on the phone 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   602
        e.g. location = tsrc\testComponent\group
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   603
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   604
        Function can be called in any of the following ways:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   605
        1. get_data_files("c:\abc\abc.pkg")                 - only data files' paths are returnd 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   606
                                                              as they are mention in the pkg file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   607
        2. get_data_files("c:\abc\abc.pkg", "x:")           - Proper data files' paths are returnd 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   608
                                                              with drive letter included 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   609
        3. get_data_files("c:\abc\abc.pkg", "x:", "\.dll")  - Data files' paths are returnd with 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   610
                                                              drive letter included but the dll 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   611
                                                              files will be excluded if found in 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   612
                                                              the pkg file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   613
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   614
        if pkg file is not given, the function will try to find the file(s) on the given location with extension ".pkg"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   615
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   616
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   617
        self.drive = drive
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   618
        self.exclude = exclude
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   619
        self._files = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   620
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   621
        if type(location) is not list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   622
            locations = [location]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   623
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   624
            locations = location
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   625
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   626
        for _file_ in locations:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   627
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   628
            #if location is already a file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   629
            if ".pkg" in str(_file_).lower():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   630
                self._files = _file_
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   631
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   632
                self.location = path(_file_)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   633
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   634
                if not self.location.exists():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   635
                    continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   636
                for p_file in self.get_pkg_files(self.location, True):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   637
                    self._files.append(p_file)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   638
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   639
        return self.read_pkg_file(self._files)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   640
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   641
    def __map_pkg_path(self, pkg_line, pkg_file_path, pkg_file):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   642
        """Parse package file to get the src and dst paths" for installing files"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   643
        mmp_parser = MmpFileParser()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   644
        ext = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   645
        val1 = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   646
        val2 = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   647
        map_src = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   648
        map_dst = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   649
        self.pkg_file_path = pkg_file_path
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   650
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   651
        if not self.exclude == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   652
            if re.search(r'%s' % self.exclude, pkg_line) is not None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   653
                return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   654
        #searches for the file path (src and dst) in the pkg file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   655
        #e.g.: "..\conf\VCXErrors.inc"-"C:\TestFramework\VCXErrors.inc"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   656
        result = re.search(r'^\s*"(.*?)".*?-.*?"(.*?)"', pkg_line)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   657
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   658
        if result is None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   659
            return None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   660
        val1, val2 = result.groups()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   661
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   662
        if val1 != "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   663
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   664
            #replacing delimiters (${platform} and ${target}) in PKG file templates, 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   665
            #for instance, QT tests PKG files have delimeters 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   666
            if "$(platform)" in val1.lower() and self.build_platform is not None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   667
                val1 = val1.lower().replace("$(platform)", self.build_platform)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   668
            if "$(target)" in val1.lower() and self.build_target is not None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   669
                val1 = val1.lower().replace("$(target)", self.build_target)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   670
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   671
            if path.isabs(path(val1).normpath()):
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   672
                map_src = os.path.normpath(os.path.join(self.drive, val1))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   673
            elif re.search(r"\A\w", val1, 1):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   674
                map_src = str(path.joinpath(self.pkg_file_path + os.sep, os.path.normpath(val1)).normpath())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   675
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   676
                map_src = str(path.joinpath(self.pkg_file_path, path(val1)).normpath())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   677
            map_dst = str(path(val2).normpath())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   678
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   679
            map_src, map_dst = val1, val2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   680
        map_src = map_src.strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   681
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   682
        #replaces the characters with the drive letters
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   683
        map_dst = map_dst.replace("!:", "c:")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   684
        map_dst = map_dst.replace("$:", "c:")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   685
        map_dst = re.sub(r'^(\w)', r'\1', map_dst).strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   686
        indx = map_dst.rsplit(".")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   687
        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   688
            ext = indx[1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   689
        except IndexError:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   690
            _logger.warning("Index Error in map_pkg_path()")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   691
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   692
        _test_type_ = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   693
        _target_filename_ = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   694
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   695
        _target_filename_ = mmp_parser.get_target_filename(self.pkg_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   696
        _test_type_ = mmp_parser.get_dll_type(self.pkg_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   697
        _harness_ = mmp_parser.get_harness(self.pkg_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   698
        _libraries_ = mmp_parser.get_libraries(self.pkg_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   699
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   700
        if ext == "ini":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   701
            file_type = "engine_ini"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   702
        elif ext == "cfg":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   703
            file_type = "conf"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   704
        elif ext == "dll":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   705
            #adding type of dll (executable or dependent), if file type is dll
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   706
            if _test_type_ == "dependent":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   707
                file_type = "data" + ":%s" % _test_type_
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   708
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   709
                if "qttest.lib" in _libraries_:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   710
                    file_type = "data" + ":qt:dependent" 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   711
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   712
                    file_type = "testmodule"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   713
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   714
        elif ext == 'exe' and 'rtest' in _libraries_:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   715
            file_type = "testmodule:rtest"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   716
        elif ext == "exe":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   717
            if _test_type_ == "dependent":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   718
                file_type = "data" + ":%s" % _test_type_
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   719
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   720
                if "qttest.lib" in _libraries_:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   721
                    file_type = "testmodule:qt"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   722
                else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   723
                    file_type = "testmodule"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   724
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   725
        elif ext == "sisx":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   726
            file_type = ""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   727
        elif ext == "xml":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   728
            file_type = "trace_init"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   729
        elif ext == "pmd":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   730
            file_type = "pmd"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   731
        elif ext == "script":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   732
            if "testframeworkclient.lib" in _libraries_:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   733
                file_type = "testscript:mtf"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   734
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   735
                file_type = "testscript"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   736
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   737
            file_type = "data"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   738
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   739
        if not map_src or map_src == "." or not map_dst or map_dst == ".":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   740
            return None
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   741
        if not os.path.exists(map_src):
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   742
            _logger.error(map_src + ' not found')
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   743
            return None
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   744
        return path(map_src).normpath(), path(map_dst).normpath(), file_type, pkg_file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   745
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   746
    def read_pkg_file(self, pkg_files):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   747
        """Reads contents of PKG file"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   748
        pkg_paths = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   749
        for pkg_file in pkg_files:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   750
            if not os.path.exists( pkg_file ):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   751
                _logger.error("No PKG -file in path specified")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   752
                continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   753
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   754
                file1 = codecs.open(pkg_file, 'r', 'utf16')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   755
                try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   756
                    lines = file1.readlines()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   757
                except UnicodeError:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   758
                    file1 = open(pkg_file, 'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   759
                    lines = file1.readlines()
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   760
                pkg_file_path = path(os.path.dirname(pkg_file))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   761
                for line in lines:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   762
                    pkg_path = self.__map_pkg_path(line, pkg_file_path, os.path.basename(pkg_file))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   763
                    if pkg_path is None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   764
                        continue
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   765
                    else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   766
                        pkg_paths.append(pkg_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   767
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   768
        return pkg_paths