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
|
628
|
29 |
import amara
|
587
|
30 |
|
|
31 |
_logger = logging.getLogger('atsant')
|
|
32 |
|
|
33 |
class IConfigATS(object):
|
|
34 |
""" Class used to read configuration file iconfig.xml """
|
588
|
35 |
def __init__(self, imagesdir, productname):
|
587
|
36 |
self.imagesdir = imagesdir
|
588
|
37 |
self.productname = productname
|
587
|
38 |
self.config = self.getconfig()
|
|
39 |
|
628
|
40 |
def getconfig(self, type_=None, productname=None):
|
587
|
41 |
"""get configuration"""
|
|
42 |
noncust = None
|
|
43 |
for root, _, files in os.walk(self.imagesdir, topdown=False):
|
|
44 |
for fname in files:
|
|
45 |
if 'iconfig.xml' in fname:
|
|
46 |
filePath = os.path.join(root, fname)
|
|
47 |
configBuilder = configuration.NestedConfigurationBuilder(open(filePath, 'r'))
|
|
48 |
configSet = configBuilder.getConfiguration()
|
|
49 |
for config in configSet.getConfigurations():
|
628
|
50 |
if type_ and productname:
|
|
51 |
if type_ in config.type and config['PRODUCT_NAME'].lower() in productname.lower():
|
587
|
52 |
return config
|
|
53 |
else:
|
|
54 |
noncust = config
|
628
|
55 |
if type_:
|
587
|
56 |
return None
|
|
57 |
if noncust:
|
|
58 |
return noncust
|
|
59 |
raise Exception('iconfig not found in ' + self.imagesdir)
|
|
60 |
|
|
61 |
def getimage(self, name):
|
|
62 |
"""get image"""
|
|
63 |
for root, _, files in os.walk(self.imagesdir, topdown=False):
|
|
64 |
for fname in files:
|
|
65 |
if fname.lower() == name.lower():
|
|
66 |
return os.path.join(root, fname)
|
|
67 |
raise Exception(name + ' not found in ' + self.imagesdir)
|
|
68 |
|
|
69 |
def findimages(self):
|
|
70 |
"""find images"""
|
|
71 |
output = ''
|
628
|
72 |
for imagetype, imagetypename in [('core', 'CORE'), ('langpack', 'ROFS2'), ('cust', 'ROFS3'), ('udaerase', 'UDAERASE'), ('emmc', 'EMMC')]:
|
588
|
73 |
iconfigxml = self.getconfig(imagetype, self.productname)
|
587
|
74 |
if iconfigxml == None:
|
|
75 |
iconfigxml = self.config
|
|
76 |
|
|
77 |
if iconfigxml.has_key(imagetypename + '_FLASH'):
|
|
78 |
(drive, _) = os.path.splitdrive(self.imagesdir)
|
|
79 |
image = os.path.join(drive, iconfigxml[imagetypename + '_FLASH'])
|
|
80 |
if not os.path.exists(image):
|
|
81 |
image = self.getimage(os.path.basename(image))
|
|
82 |
if os.path.exists(image):
|
|
83 |
output = output + image + ','
|
|
84 |
else:
|
|
85 |
raise Exception(image + ' not found')
|
|
86 |
else:
|
|
87 |
if imagetype == 'core':
|
588
|
88 |
raise Exception(imagetypename + '_FLASH not found in iconfig.xml in ' + self.imagesdir)
|
587
|
89 |
print imagetypename + '_FLASH not found in iconfig.xml'
|
|
90 |
return output
|
|
91 |
|
588
|
92 |
def get_boolean(string_val):
|
|
93 |
"""if parameter passed in is not present in the project it will produce 'none'
|
|
94 |
as a result so this will be converted to boolean false as will all values
|
|
95 |
except true."""
|
|
96 |
retVal = False
|
|
97 |
if (string_val == 'true'):
|
|
98 |
retVal = True
|
|
99 |
return retVal
|
|
100 |
|
|
101 |
|
628
|
102 |
def files_to_test(canonicalsysdeffile, excludetestlayers, idobuildfilter, builddrive, createmultipledropfiles, sysdef3=False):
|
587
|
103 |
"""list the files to test"""
|
|
104 |
modules = {}
|
628
|
105 |
if sysdef3 == True:
|
|
106 |
sdf = amara.parse(open(canonicalsysdeffile))
|
|
107 |
for package in sdf.SystemDefinition.systemModel.package:
|
|
108 |
for collection in package.collection:
|
|
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):
|
587
|
132 |
continue
|
628
|
133 |
layer = sdf.layers[layr]
|
|
134 |
for mod in layer.modules:
|
|
135 |
if get_boolean(createmultipledropfiles): #creating single drop file?
|
|
136 |
if single_key not in modules: #have we already added the key to the dictionary?
|
|
137 |
modules[single_key] = [] #no so add it
|
|
138 |
elif mod.name not in modules:
|
|
139 |
modules[mod.name] = []
|
|
140 |
single_key = mod.name #change the key name to write to modules
|
|
141 |
for unit in mod.units:
|
|
142 |
include_unit = True
|
|
143 |
if idobuildfilter != None:
|
|
144 |
if idobuildfilter != "":
|
|
145 |
include_unit = False
|
|
146 |
if hasattr(unit, 'filters'):
|
|
147 |
if len(unit.filters) > 0:
|
|
148 |
for afilter in unit.filters:
|
|
149 |
include_unit = re.search(r"\b%s\b" % afilter, idobuildfilter)
|
|
150 |
elif len(unit.filters) == 0:
|
|
151 |
include_unit = True
|
|
152 |
else:
|
|
153 |
include_unit = False
|
587
|
154 |
else:
|
|
155 |
include_unit = False
|
628
|
156 |
if hasattr(unit, 'filters'):
|
|
157 |
if len(unit.filters) == 0:
|
|
158 |
include_unit = True
|
|
159 |
if include_unit:
|
|
160 |
modules[single_key].append(builddrive + os.sep + unit.path)
|
588
|
161 |
return modules
|
587
|
162 |
|