buildframework/helium/sf/python/pythoncore/lib/atsant.py
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    24 import re
    24 import re
    25 import sysdef.api
    25 import sysdef.api
    26 import os
    26 import os
    27 import logging
    27 import logging
    28 import configuration
    28 import configuration
       
    29 import amara
    29 
    30 
    30 _logger = logging.getLogger('atsant')
    31 _logger = logging.getLogger('atsant')
    31 
    32 
    32 class IConfigATS(object):
    33 class IConfigATS(object):
    33     """ Class used to read configuration file iconfig.xml """
    34     """ Class used to read configuration file iconfig.xml """
    34     def __init__(self, imagesdir, productname):
    35     def __init__(self, imagesdir, productname):
    35         self.imagesdir = imagesdir
    36         self.imagesdir = imagesdir
    36         self.productname = productname
    37         self.productname = productname
    37         self.config = self.getconfig()
    38         self.config = self.getconfig()
    38         
    39         
    39     def getconfig(self, type=None, productname=None):
    40     def getconfig(self, type_=None, productname=None):
    40         """get configuration"""
    41         """get configuration"""
    41         noncust = None
    42         noncust = None
    42         for root, _, files in os.walk(self.imagesdir, topdown=False):
    43         for root, _, files in os.walk(self.imagesdir, topdown=False):
    43             for fname in files:
    44             for fname in files:
    44                 if 'iconfig.xml' in fname:
    45                 if 'iconfig.xml' in fname:
    45                     filePath = os.path.join(root, fname)
    46                     filePath = os.path.join(root, fname)
    46                     configBuilder = configuration.NestedConfigurationBuilder(open(filePath, 'r'))
    47                     configBuilder = configuration.NestedConfigurationBuilder(open(filePath, 'r'))
    47                     configSet = configBuilder.getConfiguration()
    48                     configSet = configBuilder.getConfiguration()
    48                     for config in configSet.getConfigurations():
    49                     for config in configSet.getConfigurations():
    49                         if type and productname:
    50                         if type_ and productname:
    50                             if type in config.type and config['PRODUCT_NAME'] in productname:
    51                             if type_ in config.type and config['PRODUCT_NAME'].lower() in productname.lower():
    51                                 return config
    52                                 return config
    52                         else:
    53                         else:
    53                             noncust = config
    54                             noncust = config
    54         if type:
    55         if type_:
    55             return None
    56             return None
    56         if noncust:
    57         if noncust:
    57             return noncust
    58             return noncust
    58         raise Exception('iconfig not found in ' + self.imagesdir)
    59         raise Exception('iconfig not found in ' + self.imagesdir)
    59     
    60     
    66         raise Exception(name + ' not found in ' + self.imagesdir)
    67         raise Exception(name + ' not found in ' + self.imagesdir)
    67     
    68     
    68     def findimages(self): 
    69     def findimages(self): 
    69         """find images"""
    70         """find images"""
    70         output = ''
    71         output = ''
    71         for imagetype, imagetypename in [('core', 'CORE'), ('langpack', 'ROFS2'), ('cust', 'ROFS3'), ('udaerase', 'UDAERASE')]:
    72         for imagetype, imagetypename in [('core', 'CORE'), ('langpack', 'ROFS2'), ('cust', 'ROFS3'), ('udaerase', 'UDAERASE'), ('emmc', 'EMMC')]:
    72             iconfigxml = self.getconfig(imagetype, self.productname)
    73             iconfigxml = self.getconfig(imagetype, self.productname)
    73             if iconfigxml == None:
    74             if iconfigxml == None:
    74                 iconfigxml = self.config
    75                 iconfigxml = self.config
    75 
    76 
    76             if iconfigxml.has_key(imagetypename + '_FLASH'):
    77             if iconfigxml.has_key(imagetypename + '_FLASH'):
    96     if (string_val == 'true'):
    97     if (string_val == 'true'):
    97         retVal = True
    98         retVal = True
    98     return retVal
    99     return retVal
    99 
   100 
   100 
   101 
   101 def files_to_test(canonicalsysdeffile, excludetestlayers, idobuildfilter, builddrive, createmultipledropfiles):
   102 def files_to_test(canonicalsysdeffile, excludetestlayers, idobuildfilter, builddrive, createmultipledropfiles, sysdef3=False):
   102     """list the files to test"""
   103     """list the files to test"""
   103     sdf = sysdef.api.SystemDefinition(canonicalsysdeffile)
       
   104     
       
   105     single_key = 'singledropfile'       #default single drop file name
       
   106     modules = {}
   104     modules = {}
   107     for layr in sdf.layers:
   105     if sysdef3 == True:
   108         if re.match(r".*_test_layer$", layr):
   106         sdf = amara.parse(open(canonicalsysdeffile))
   109 # pylint: disable-msg=W0704
   107         for package in sdf.SystemDefinition.systemModel.package:
   110             try:
   108             for collection in package.collection:
   111                 if re.search(r"\b%s\b" % layr, excludetestlayers):
   109                 if hasattr(collection, 'component'): 
       
   110                     for component in collection.component:
       
   111                         print component.id
       
   112                         if get_boolean(createmultipledropfiles):
       
   113                             group = 'singledropfile'
       
   114                         else:
       
   115                             group = 'default'
       
   116                         if hasattr(component, 'meta') and hasattr(component.meta, 'group'):
       
   117                             if not group.lower() == 'singledropfile':
       
   118                                 group = component.meta.group[0].name                            
       
   119                         if hasattr(component, 'unit'):
       
   120                             for unit in component.unit:
       
   121                                 if group not in modules:
       
   122                                     modules[group] = []
       
   123                                 modules[group].append(builddrive + os.sep + unit.bldFile)
       
   124     else:
       
   125         sdf = sysdef.api.SystemDefinition(canonicalsysdeffile)
       
   126         
       
   127         single_key = 'singledropfile'       #default single drop file name
       
   128        
       
   129         for layr in sdf.layers:
       
   130             if re.match(r".*_test_layer$", layr):
       
   131                 if excludetestlayers and re.search(r"\b%s\b" % layr, excludetestlayers):
   112                     continue
   132                     continue
   113             except TypeError:       #needed to catch exceptions and not have them printed
   133                 layer = sdf.layers[layr]
   114                 pass
   134                 for mod in layer.modules:
   115 # pylint: enable-msg=W0704
   135                     if get_boolean(createmultipledropfiles):  #creating single drop file?
   116 
   136                         if single_key not in modules:       #have we already added the key to the dictionary?
   117             layer = sdf.layers[layr]
   137                             modules[single_key] = []        #no so add it
   118             for mod in layer.modules:
   138                     elif mod.name not in modules:
   119                 if get_boolean(createmultipledropfiles):  #creating single drop file?
   139                         modules[mod.name] = []
   120                     if single_key not in modules:       #have we already added the key to the dictionary?
   140                         single_key = mod.name               #change the key name to write to modules
   121                         modules[single_key] = []        #no so add it
   141                     for unit in mod.units:
   122                 elif mod.name not in modules:
   142                         include_unit = True
   123                     modules[mod.name] = []
   143                         if idobuildfilter != None:
   124                     single_key = mod.name               #change the key name to write to modules
   144                             if idobuildfilter != "":
   125                 for unit in mod.units:
   145                                 include_unit = False
   126                     include_unit = True
   146                                 if hasattr(unit, 'filters'):
   127                     if idobuildfilter != None:
   147                                     if len(unit.filters) > 0:
   128                         if idobuildfilter != "":
   148                                         for afilter in unit.filters:
   129                             include_unit = False
   149                                             include_unit = re.search(r"\b%s\b" % afilter, idobuildfilter)
   130                             if hasattr(unit, 'filters'):
   150                                     elif len(unit.filters) == 0:
   131                                 if len(unit.filters) > 0:
   151                                         include_unit = True
   132                                     for afilter in unit.filters:
   152                                 else:
   133                                         if re.search(r"\b%s\b" % afilter, idobuildfilter):
   153                                     include_unit = False
   134                                             include_unit = True
       
   135                                         else:
       
   136                                             include_unit = False
       
   137                                 elif len(unit.filters) == 0:
       
   138                                     include_unit = True
       
   139                             else:
   154                             else:
   140                                 include_unit = False
   155                                 include_unit = False
   141                         else:
   156                                 if hasattr(unit, 'filters'):
   142                             include_unit = False
   157                                     if len(unit.filters) == 0:
   143                             if hasattr(unit, 'filters'):
   158                                         include_unit = True
   144                                 if len(unit.filters) == 0:
   159                         if include_unit:
   145                                     include_unit = True
   160                             modules[single_key].append(builddrive + os.sep + unit.path)
   146                     if include_unit:
       
   147                         modules[single_key].append(os.path.join(builddrive + os.sep, unit.path))
       
   148     return modules
   161     return modules
   149 
   162