587
|
1 |
#============================================================================
|
|
2 |
#Name : scanners.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
|
19 |
|
|
20 |
""" Implementation of the available scanner for """
|
|
21 |
|
|
22 |
import os
|
|
23 |
import fileutils
|
|
24 |
import logging
|
|
25 |
import codecs
|
|
26 |
import pathaddition
|
|
27 |
|
628
|
28 |
import archive.selectors
|
|
29 |
|
587
|
30 |
_logger = logging.getLogger('archive.scanners')
|
|
31 |
_logger_abld = logging.getLogger('archive.scanners.abld')
|
|
32 |
logging.basicConfig()
|
|
33 |
#logger_abld.setLevel(logging.DEBUG)
|
|
34 |
|
|
35 |
class Scanner(fileutils.AbstractScanner):
|
|
36 |
""" Abstract class that represent and input source. """
|
|
37 |
|
|
38 |
def __init__(self, config):
|
|
39 |
fileutils.AbstractScanner.__init__(self)
|
|
40 |
self._config = config
|
|
41 |
self.setup()
|
|
42 |
|
|
43 |
def setup(self):
|
|
44 |
""" Setting up the scanner. """
|
|
45 |
[self.add_include(inc) for inc in self._config.get_list('include', [])]
|
|
46 |
[self.add_exclude(ex) for ex in self._config.get_list('exclude', [])]
|
|
47 |
[self.add_exclude_file(ex) for ex in self._config.get_list('exclude_file', [])]
|
|
48 |
[self.add_exclude_lst(filename) for filename in self._config.get_list('exclude.lst', [])]
|
|
49 |
[self.add_filetype(filetype) for filetype in self._config.get_list('filetype', [])]
|
628
|
50 |
[self.add_selector(archive.selectors.get_selector(selector, self._config)) for selector in self._config.get_list('selector', [])]
|
587
|
51 |
# To support old features.
|
|
52 |
# TODO: inform customers and remove.
|
|
53 |
if 'distribution.policy.s60' in self._config:
|
628
|
54 |
self.add_selector(archive.selectors.get_selector('distribution.policy.s60', self._config))
|
587
|
55 |
|
|
56 |
def add_exclude_lst(self, filename):
|
|
57 |
""" Adding excludes from exclude list. """
|
|
58 |
if not os.path.exists(filename):
|
|
59 |
raise Exception("Could not find '%s'." % filename)
|
|
60 |
root_dir = os.path.normpath(self._config['root.dir'])
|
|
61 |
flh = codecs.open(filename, 'r', 'utf-8')
|
|
62 |
for line in flh:
|
|
63 |
path = os.path.normpath(line.strip())
|
|
64 |
if os.path.splitdrive(root_dir)[0] != "":
|
|
65 |
path = os.path.join(os.path.splitdrive(root_dir)[0], path)
|
|
66 |
if fileutils.destinsrc(root_dir, path):
|
|
67 |
pathrel = pathaddition.relative.abs2rel(path, root_dir)
|
|
68 |
_logger.debug("pathrel: %s" % (pathrel))
|
|
69 |
self.add_exclude(pathrel)
|
|
70 |
else:
|
|
71 |
_logger.warning("path '%s' is not under '%s', ignoring." % (path, root_dir))
|
|
72 |
flh.close()
|
|
73 |
|
|
74 |
def scan(self):
|
|
75 |
""" Generator method that scan the relevant input source.
|
|
76 |
This method need to be overloaded by the specialized class.
|
|
77 |
return fullpath name
|
|
78 |
"""
|
|
79 |
raise NotImplementedError()
|
|
80 |
|
|
81 |
|
|
82 |
class AbldWhatScanner(Scanner):
|
|
83 |
""" Scanning the filesystem. """
|
|
84 |
|
|
85 |
def __init__(self, config):
|
|
86 |
Scanner.__init__(self, config)
|
|
87 |
self.root_dir = unicode(os.path.normpath(self._config['root.dir']))
|
|
88 |
|
|
89 |
def scan(self):
|
|
90 |
"""
|
|
91 |
Abld what commands.
|
|
92 |
include property have not effect on the selection mechanism.
|
|
93 |
"""
|
|
94 |
os.environ["SYMBIANBUILD_DEPENDENCYOFF"] = "1"
|
|
95 |
for path in self._config.get_list('abld.exportpath', []):
|
|
96 |
_logger_abld.debug("abld.exportpath: %s" % path)
|
|
97 |
if os.path.exists(os.path.join(self.root_dir, path, 'bld.inf')):
|
|
98 |
os.chdir(os.path.join(self.root_dir, path))
|
|
99 |
os.popen('bldmake bldfiles -k')
|
|
100 |
for result in self._scan_abld_what("abld export -what -k"):
|
|
101 |
yield result
|
|
102 |
|
|
103 |
for path in self._config.get_list('abld.buildpath', []):
|
|
104 |
_logger_abld.debug("abld.buildpath: %s" % path)
|
|
105 |
if os.path.exists(os.path.join(self.root_dir, path, 'bld.inf')):
|
|
106 |
for type_ in self._config.get_list('abld.type', ['armv5']):
|
|
107 |
os.environ["EPOCROOT"] = self._config.get('abld.epocroot','\\')
|
|
108 |
os.environ["PATH"] = os.environ["EPOCROOT"] + "epoc32\\tools;" + os.environ["EPOCROOT"] + "epoc32\\gcc\\bin;" + os.environ["PATH"]
|
|
109 |
_logger_abld.debug("abld.type: %s" % type_)
|
|
110 |
os.chdir(os.path.join(self.root_dir, path))
|
|
111 |
os.popen("bldmake bldfiles -k")
|
|
112 |
os.popen("abld makefile %s -k" % type_)
|
|
113 |
for result in self._scan_abld_what("abld build -what %s" % type_):
|
|
114 |
yield result
|
|
115 |
|
|
116 |
def _run_cmd(self, cmd):
|
|
117 |
""" Run command."""
|
|
118 |
_logger_abld.debug("command: %s" % cmd)
|
|
119 |
process = os.popen(cmd)
|
|
120 |
abld_output = process.read()
|
|
121 |
err = process.close()
|
|
122 |
return (err, abld_output)
|
|
123 |
|
|
124 |
def _scan_abld_what(self, cmd):
|
|
125 |
""" Abld what output parser."""
|
|
126 |
(_, abld_output) = self._run_cmd(cmd)
|
|
127 |
_logger_abld.debug("abld_output: %s" % abld_output)
|
|
128 |
for what_path in abld_output.split("\n"):
|
|
129 |
what_path = what_path.strip()
|
|
130 |
if (what_path.startswith('\\') or what_path.startswith('/')) and self.is_filetype(what_path) \
|
|
131 |
and not self.is_excluded(what_path) and self.is_selected(what_path):
|
|
132 |
if os.path.exists(what_path):
|
|
133 |
_logger_abld.debug("adding: %s" % what_path)
|
|
134 |
yield what_path
|
|
135 |
else:
|
|
136 |
_logger.error("Could not find '%s'." % what_path)
|
|
137 |
|
|
138 |
|
|
139 |
class FileSystemScanner(fileutils.FileScanner, Scanner):
|
|
140 |
""" Scanning the filesystem. """
|
|
141 |
|
|
142 |
def __init__(self, config):
|
|
143 |
fileutils.FileScanner.__init__(self, unicode(os.path.normpath(config['root.dir'])))
|
|
144 |
Scanner.__init__(self, config)
|
|
145 |
|
|
146 |
def scan(self):
|
|
147 |
"""
|
|
148 |
Implement the scanning of the filesystem.
|
|
149 |
Actually delegate scanning of a directory to Filescanner.
|
|
150 |
"""
|
|
151 |
for path in fileutils.FileScanner.scan(self):
|
|
152 |
yield path
|
|
153 |
|
|
154 |
|
|
155 |
class InputFileScanner(fileutils.FileScanner, Scanner):
|
|
156 |
""" Scanning the filesystem. """
|
|
157 |
|
|
158 |
def __init__(self, config):
|
|
159 |
""" Initialisation. """
|
|
160 |
fileutils.FileScanner.__init__(self, unicode(os.path.normpath(config['root.dir'])))
|
|
161 |
Scanner.__init__(self, config)
|
|
162 |
|
|
163 |
def scan(self):
|
|
164 |
"""
|
|
165 |
::
|
|
166 |
|
|
167 |
<set name="scanners" value="input.file"/>
|
|
168 |
<set name="root.dir" value="${build.drive}"/>
|
|
169 |
<set name="input.files" value="file1.lst,file2.lst,file3.lst"/>
|
|
170 |
<set name="exclude" value="epoc32/**/*.dll"/>
|
|
171 |
"""
|
|
172 |
for input_file in self._config.get_list('input.files', []):
|
|
173 |
_logger.info("Include content from: %s" % input_file)
|
|
174 |
handle = open(input_file, "r")
|
|
175 |
for line in handle.readlines():
|
|
176 |
path = os.path.join(self._config['root.dir'], line.strip())
|
|
177 |
if os.path.exists(path):
|
|
178 |
if self.is_filetype(path) \
|
|
179 |
and not self.is_excluded(path) and self.is_selected(path):
|
|
180 |
yield path
|
|
181 |
else:
|
|
182 |
_logger.info("File not found: %s" % path)
|
|
183 |
handle.close()
|
|
184 |
|
|
185 |
__scanners = {'default': FileSystemScanner,
|
|
186 |
'input.file': InputFileScanner,
|
|
187 |
'abld.what': AbldWhatScanner,
|
|
188 |
}
|
|
189 |
|
|
190 |
def get_scanners(names, config):
|
|
191 |
"""get scanners"""
|
|
192 |
result = []
|
|
193 |
for name in names:
|
|
194 |
if name in __scanners:
|
|
195 |
result.append(__scanners[name](config))
|
|
196 |
else:
|
|
197 |
raise Exception("ERROR: Could not find scanner '%s'." % name)
|
|
198 |
return result
|