587
|
1 |
# -*- encoding: latin-1 -*-
|
|
2 |
|
|
3 |
#============================================================================
|
|
4 |
#Name : atsant.py
|
|
5 |
#Part of : Helium
|
|
6 |
|
|
7 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
8 |
#All rights reserved.
|
|
9 |
#This component and the accompanying materials are made available
|
|
10 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
11 |
#which accompanies this distribution, and is available
|
|
12 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
13 |
#
|
|
14 |
#Initial Contributors:
|
|
15 |
#Nokia Corporation - initial contribution.
|
|
16 |
#
|
|
17 |
#Contributors:
|
|
18 |
#
|
|
19 |
#Description:
|
|
20 |
#===============================================================================
|
|
21 |
|
|
22 |
""" get the files needed to test ATS"""
|
|
23 |
|
|
24 |
import re
|
|
25 |
import sysdef.api
|
|
26 |
import os
|
|
27 |
import logging
|
|
28 |
import configuration
|
|
29 |
|
|
30 |
_logger = logging.getLogger('atsant')
|
|
31 |
|
|
32 |
class IConfigATS(object):
|
|
33 |
""" Class used to read configuration file iconfig.xml """
|
618
|
34 |
def __init__(self, imagesdir, productname):
|
587
|
35 |
self.imagesdir = imagesdir
|
618
|
36 |
self.productname = productname
|
587
|
37 |
self.config = self.getconfig()
|
|
38 |
|
618
|
39 |
def getconfig(self, type=None, productname=None):
|
587
|
40 |
"""get configuration"""
|
|
41 |
noncust = None
|
|
42 |
for root, _, files in os.walk(self.imagesdir, topdown=False):
|
|
43 |
for fname in files:
|
|
44 |
if 'iconfig.xml' in fname:
|
|
45 |
filePath = os.path.join(root, fname)
|
|
46 |
configBuilder = configuration.NestedConfigurationBuilder(open(filePath, 'r'))
|
|
47 |
configSet = configBuilder.getConfiguration()
|
|
48 |
for config in configSet.getConfigurations():
|
618
|
49 |
if type and productname:
|
|
50 |
if type in config.type and config['PRODUCT_NAME'] in productname:
|
587
|
51 |
return config
|
|
52 |
else:
|
|
53 |
noncust = config
|
|
54 |
if type:
|
|
55 |
return None
|
|
56 |
if noncust:
|
|
57 |
return noncust
|
|
58 |
raise Exception('iconfig not found in ' + self.imagesdir)
|
|
59 |
|
|
60 |
def getimage(self, name):
|
|
61 |
"""get image"""
|
|
62 |
for root, _, files in os.walk(self.imagesdir, topdown=False):
|
|
63 |
for fname in files:
|
|
64 |
if fname.lower() == name.lower():
|
|
65 |
return os.path.join(root, fname)
|
|
66 |
raise Exception(name + ' not found in ' + self.imagesdir)
|
|
67 |
|
|
68 |
def findimages(self):
|
|
69 |
"""find images"""
|
|
70 |
output = ''
|
|
71 |
for imagetype, imagetypename in [('core', 'CORE'), ('langpack', 'ROFS2'), ('cust', 'ROFS3'), ('udaerase', 'UDAERASE')]:
|
618
|
72 |
iconfigxml = self.getconfig(imagetype, self.productname)
|
587
|
73 |
if iconfigxml == None:
|
|
74 |
iconfigxml = self.config
|
|
75 |
|
|
76 |
if iconfigxml.has_key(imagetypename + '_FLASH'):
|
|
77 |
(drive, _) = os.path.splitdrive(self.imagesdir)
|
|
78 |
image = os.path.join(drive, iconfigxml[imagetypename + '_FLASH'])
|
|
79 |
if not os.path.exists(image):
|
|
80 |
image = self.getimage(os.path.basename(image))
|
|
81 |
if os.path.exists(image):
|
|
82 |
output = output + image + ','
|
|
83 |
else:
|
|
84 |
raise Exception(image + ' not found')
|
|
85 |
else:
|
|
86 |
if imagetype == 'core':
|
618
|
87 |
raise Exception(imagetypename + '_FLASH not found in iconfig.xml in ' + self.imagesdir)
|
587
|
88 |
print imagetypename + '_FLASH not found in iconfig.xml'
|
|
89 |
return output
|
|
90 |
|
|
91 |
def files_to_test(canonicalsysdeffile, excludetestlayers, idobuildfilter, builddrive):
|
|
92 |
"""list the files to test"""
|
|
93 |
sdf = sysdef.api.SystemDefinition(canonicalsysdeffile)
|
|
94 |
|
|
95 |
modules = {}
|
|
96 |
for layr in sdf.layers:
|
|
97 |
if re.match(r".*_test_layer$", layr):
|
|
98 |
# pylint: disable-msg=W0704
|
|
99 |
try:
|
|
100 |
if re.search(r"\b%s\b" % layr, excludetestlayers):
|
|
101 |
continue
|
|
102 |
except TypeError: #needed to catch exceptions and not have them printed
|
|
103 |
pass
|
|
104 |
# pylint: enable-msg=W0704
|
|
105 |
|
|
106 |
layer = sdf.layers[layr]
|
|
107 |
for mod in layer.modules:
|
|
108 |
if mod.name not in modules:
|
|
109 |
modules[mod.name] = []
|
|
110 |
for unit in mod.units:
|
|
111 |
include_unit = True
|
|
112 |
if idobuildfilter != None:
|
|
113 |
if idobuildfilter != "":
|
|
114 |
include_unit = False
|
|
115 |
if hasattr(unit, 'filters'):
|
|
116 |
if len(unit.filters) > 0:
|
|
117 |
for afilter in unit.filters:
|
|
118 |
if re.search(r"\b%s\b" % afilter, idobuildfilter):
|
|
119 |
include_unit = True
|
|
120 |
else:
|
|
121 |
include_unit = False
|
|
122 |
elif len(unit.filters) == 0:
|
|
123 |
include_unit = True
|
|
124 |
else:
|
|
125 |
include_unit = False
|
|
126 |
else:
|
|
127 |
include_unit = False
|
|
128 |
if hasattr(unit, 'filters'):
|
|
129 |
if len(unit.filters) == 0:
|
|
130 |
include_unit = True
|
|
131 |
if include_unit:
|
|
132 |
modules[mod.name].append(os.path.join(builddrive + os.sep, unit.path))
|
|
133 |
|
|
134 |
return modules
|