0
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
##############################################################################
|
|
5 |
# module_repo.py - Ensymble command line tool, py2sis command
|
|
6 |
# Copyright (c) 2009 Nokia Corporation
|
|
7 |
#
|
|
8 |
# This file is part of Ensymble developer utilities for Symbian OS(TM).
|
|
9 |
#
|
|
10 |
# Ensymble is free software; you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation; either version 2 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# Ensymble is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with Ensymble; if not, write to the Free Software
|
|
22 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
23 |
##############################################################################
|
|
24 |
|
|
25 |
import sys
|
|
26 |
import os
|
|
27 |
import shutil
|
|
28 |
import modulefinder
|
|
29 |
|
|
30 |
module_repo_dir = os.path.abspath('module-repo')
|
|
31 |
std_modules_dir = os.path.join(module_repo_dir, 'standard-modules')
|
|
32 |
dev_modules_dir = os.path.join(module_repo_dir, 'dev-modules')
|
|
33 |
|
|
34 |
standard_module_dependency = {}
|
|
35 |
prefix = ""
|
|
36 |
debug_log = None
|
|
37 |
|
|
38 |
# PyS60 supported modules, part of PyS60 base runtime
|
|
39 |
std_base_module = 'base'
|
|
40 |
# PyS60 supported modules, not part of base runtime
|
|
41 |
std_repo_module = 'repo'
|
|
42 |
# Standard Python modules, not supported by PyS60
|
|
43 |
std_excluded_module = 'excluded'
|
|
44 |
# Modules added externally
|
|
45 |
dev_repo_module = 'dev'
|
|
46 |
# Unknown modules
|
|
47 |
unknown_module = 'unknown'
|
|
48 |
|
|
49 |
resolved_modules = {std_repo_module: [],
|
|
50 |
dev_repo_module: []}
|
|
51 |
|
|
52 |
debug = False
|
|
53 |
ignore_missing_deps = False
|
|
54 |
error_count = 0
|
|
55 |
|
|
56 |
module_lookup_file = os.path.abspath(os.path.join("module-repo", "dev-modules",
|
|
57 |
"module_search_path.cfg"))
|
|
58 |
appdir = ''
|
|
59 |
extrasdir = ''
|
|
60 |
pys60_extension_modules = ['appuifw',
|
|
61 |
'e32calendar',
|
|
62 |
'camera',
|
|
63 |
'contacts',
|
|
64 |
'e32',
|
|
65 |
'e32db',
|
|
66 |
'glcanvas',
|
|
67 |
'gles',
|
|
68 |
'globalui',
|
|
69 |
'gps',
|
|
70 |
'graphics',
|
|
71 |
'inbox',
|
|
72 |
'keycapture',
|
|
73 |
'location',
|
|
74 |
'logs',
|
|
75 |
'messaging',
|
|
76 |
'audio',
|
|
77 |
'sensor',
|
|
78 |
'btsocket',
|
|
79 |
'sysinfo',
|
|
80 |
'telephone',
|
|
81 |
'topwindow',
|
|
82 |
'scriptext']
|
|
83 |
|
|
84 |
|
|
85 |
def debug_print(msg, print_anyways=False):
|
|
86 |
if debug or print_anyways:
|
|
87 |
print str(msg)
|
|
88 |
debug_log.write(str(msg) + '\n')
|
|
89 |
|
|
90 |
|
|
91 |
def get_module_type(module):
|
|
92 |
try:
|
|
93 |
# Check if it has a entry in standard modules dependency list
|
|
94 |
return standard_module_dependency[module]['type']
|
|
95 |
except:
|
|
96 |
try:
|
|
97 |
# Get the base module, by splitting on '.'
|
|
98 |
module = module.split('.')[0]
|
|
99 |
except:
|
|
100 |
pass
|
|
101 |
else:
|
|
102 |
try:
|
|
103 |
return standard_module_dependency[module]['type']
|
|
104 |
except:
|
|
105 |
pass
|
|
106 |
|
|
107 |
# Is it a dev module ?
|
|
108 |
module_path = os.path.join(dev_modules_dir, module)
|
|
109 |
if os.path.isdir(module_path):
|
|
110 |
return dev_repo_module
|
|
111 |
|
|
112 |
# unknown module
|
|
113 |
return unknown_module
|
|
114 |
|
|
115 |
|
|
116 |
def get_dev_modules():
|
|
117 |
dev_modules = []
|
|
118 |
for mod in os.listdir(dev_modules_dir):
|
|
119 |
if os.path.isdir(os.path.join(dev_modules_dir, mod)):
|
|
120 |
dev_modules.append(mod)
|
|
121 |
return dev_modules
|
|
122 |
|
|
123 |
|
|
124 |
def find_in_all_devmodules(module):
|
|
125 |
dev_modules = get_dev_modules()
|
|
126 |
|
|
127 |
mod_pyd_name = prefix + module + '.pyd'
|
|
128 |
found_dev_mod = ''
|
|
129 |
for dep_mod in dev_modules:
|
|
130 |
mod_path = os.path.join(dev_modules_dir, dep_mod)
|
|
131 |
if os.path.isfile(os.path.join(mod_path, module + '.py')) or\
|
|
132 |
os.path.isfile(os.path.join(mod_path, module + '.pyc')) or\
|
|
133 |
os.path.isfile(os.path.join(mod_path, module + '.pyo')) or\
|
|
134 |
os.path.isfile(os.path.join(mod_path, mod_pyd_name)) or\
|
|
135 |
os.path.isdir(os.path.join(mod_path, module)):
|
|
136 |
found_dev_mod = dep_mod
|
|
137 |
break
|
|
138 |
return found_dev_mod
|
|
139 |
|
|
140 |
|
|
141 |
def add_to_resolved_std_repo(modules):
|
|
142 |
for mod in modules:
|
|
143 |
module_type = get_module_type(mod)
|
|
144 |
if module_type == std_base_module or \
|
|
145 |
module_type == std_excluded_module:
|
|
146 |
debug_print('Excluding: ' + mod +' module_type:' + \
|
|
147 |
module_type)
|
|
148 |
elif mod not in resolved_modules[std_repo_module]:
|
|
149 |
debug_print('* Including: ' + mod +' module_type:' + module_type)
|
|
150 |
resolved_modules[std_repo_module].append(mod)
|
|
151 |
|
|
152 |
|
|
153 |
def resolve_unresolved_dep(unresolved_dep_mods):
|
|
154 |
|
|
155 |
global resolved_modules
|
|
156 |
global error_count
|
|
157 |
processed_modules = []
|
|
158 |
|
|
159 |
debug_print('In resolve_unresolved_dep now:' + str(unresolved_dep_mods))
|
|
160 |
while(len(unresolved_dep_mods)):
|
|
161 |
current_module = unresolved_dep_mods.pop()
|
|
162 |
module_type = get_module_type(current_module)
|
|
163 |
debug_print('mod: %s : type: %s' %(current_module, module_type))
|
|
164 |
|
|
165 |
processed_modules.append(current_module)
|
|
166 |
|
|
167 |
if module_type == unknown_module:
|
|
168 |
# Unknown module, search in dev modules
|
|
169 |
dev_mod = find_in_all_devmodules(current_module)
|
|
170 |
if dev_mod != '' and dev_mod not in processed_modules and \
|
|
171 |
dev_mod not in unresolved_dep_mods:
|
|
172 |
debug_print("Found '%s' in '%s'" % (current_module, dev_mod))
|
|
173 |
unresolved_dep_mods.append(dev_mod)
|
|
174 |
continue
|
|
175 |
elif module_type == std_base_module or \
|
|
176 |
module_type == std_excluded_module:
|
|
177 |
debug_print('excluding: ' + current_module + \
|
|
178 |
' module type: ' + module_type)
|
|
179 |
continue
|
|
180 |
elif module_type == std_repo_module:
|
|
181 |
add_to_resolved_std_repo([current_module])
|
|
182 |
add_to_resolved_std_repo(standard_module_dependency[\
|
|
183 |
current_module]['deps'])
|
|
184 |
continue
|
|
185 |
|
|
186 |
# If we are here then, it should be a dev-module
|
|
187 |
try:
|
|
188 |
module_dir = current_module.split('.')[0]
|
|
189 |
except:
|
|
190 |
module_dir = current_module
|
|
191 |
|
|
192 |
module_path = os.path.join(dev_modules_dir, module_dir)
|
|
193 |
mod_config_file = os.path.join(module_path, 'module_config.cfg')
|
|
194 |
try:
|
|
195 |
module_config = eval(open(mod_config_file, 'rU').read())
|
|
196 |
except:
|
|
197 |
raise RuntimeError('Error reading config file of dev-module: '
|
|
198 |
+ current_module)
|
|
199 |
if module_config['type'] == 'base':
|
|
200 |
debug_print('excluding: ' + current_module + \
|
|
201 |
' module type: ' + module_config['type'])
|
|
202 |
continue
|
|
203 |
|
|
204 |
# Read the module_config file of this module and validate the
|
|
205 |
# mentioned dependencies.
|
|
206 |
mod_deps_config = module_config['deps']
|
|
207 |
for mod in mod_deps_config:
|
|
208 |
mod_type = get_module_type(mod)
|
|
209 |
if mod_type == unknown_module:
|
|
210 |
debug_print("Unknown dependency: '%s' in '%s'" %\
|
|
211 |
(mod, mod_config_file))
|
|
212 |
if mod_type == std_base_module:
|
|
213 |
mod_deps_config.remove(mod)
|
|
214 |
debug_print('removed ' + mod)
|
|
215 |
continue
|
|
216 |
if mod_type == std_repo_module:
|
|
217 |
add_to_resolved_std_repo([current_module])
|
|
218 |
add_to_resolved_std_repo(standard_module_dependency[\
|
|
219 |
current_module]['deps'])
|
|
220 |
mod_deps_config.remove(mod)
|
|
221 |
debug_print('removed ' + mod)
|
|
222 |
continue
|
|
223 |
# Now scan the module to auto-find the dependencies
|
|
224 |
module_resolved_deps, module_unresolved_deps = \
|
|
225 |
find_dep_modules(module_path)
|
|
226 |
add_to_resolved_std_repo(module_resolved_deps)
|
|
227 |
|
|
228 |
# The unresolved dependencies should be present in the current
|
|
229 |
# dev-modules or in one of the modules in its deps list.
|
|
230 |
for mod in module_unresolved_deps:
|
|
231 |
if get_module_type(mod) == unknown_module:
|
|
232 |
found_mod = find_in_all_devmodules(mod)
|
|
233 |
if found_mod == '':
|
|
234 |
if ignore_missing_deps:
|
|
235 |
# If this flag is set then print the missing
|
|
236 |
# dependencies as warnings else print them as errors
|
|
237 |
debug_print(("WARNING: Dependent module '%s' not " +\
|
|
238 |
"found") % mod, print_anyways=True)
|
|
239 |
continue
|
|
240 |
else:
|
|
241 |
error_count += 1
|
|
242 |
debug_print("ERROR: Dependent module '%s' not found" %
|
|
243 |
mod, print_anyways=True)
|
|
244 |
continue
|
|
245 |
else:
|
|
246 |
debug_print("Found '%s' in '%s'" %(mod, found_mod))
|
|
247 |
mod_deps_config.append(found_mod)
|
|
248 |
elif mod not in resolved_modules[std_repo_module] and \
|
|
249 |
mod not in resolved_modules[dev_repo_module] and \
|
|
250 |
mod not in processed_modules:
|
|
251 |
unresolved_dep_mods.append(mod)
|
|
252 |
|
|
253 |
for m in mod_deps_config:
|
|
254 |
if m not in resolved_modules[std_repo_module] and \
|
|
255 |
m not in resolved_modules[dev_repo_module] and \
|
|
256 |
m not in processed_modules:
|
|
257 |
unresolved_dep_mods.append(m)
|
|
258 |
|
|
259 |
debug_print('including:' + str(current_module))
|
|
260 |
if current_module not in resolved_modules[dev_repo_module]:
|
|
261 |
resolved_modules[dev_repo_module].append(current_module)
|
|
262 |
|
|
263 |
|
|
264 |
def get_py_files(arg, dirname, files):
|
|
265 |
for f in files:
|
|
266 |
entry = os.path.join(dirname, f)
|
|
267 |
if os.path.isdir(entry) or not f.endswith('.py'):
|
|
268 |
continue
|
|
269 |
arg.append(entry)
|
|
270 |
|
|
271 |
|
|
272 |
def find_dep_modules(src):
|
|
273 |
dep_mods = []
|
|
274 |
unresolved_dep_mods = []
|
|
275 |
py_files = []
|
|
276 |
|
|
277 |
if os.path.isdir(src):
|
|
278 |
os.path.walk(src, get_py_files, py_files)
|
|
279 |
else:
|
|
280 |
py_files.append(src)
|
|
281 |
|
|
282 |
for f in py_files:
|
|
283 |
mf = modulefinder.ModuleFinder(path=[std_modules_dir])
|
|
284 |
mf.run_script(f)
|
|
285 |
mod_list = []
|
|
286 |
for mod in mf.modules.iteritems():
|
|
287 |
mod_list.append(mod[0])
|
|
288 |
|
|
289 |
dep_mods = list(set(dep_mods + mod_list))
|
|
290 |
unresolved_dep_mods = list(set(unresolved_dep_mods + mf.any_missing()))
|
|
291 |
|
|
292 |
return (dep_mods, unresolved_dep_mods)
|
|
293 |
|
|
294 |
|
|
295 |
def init_module_repo():
|
|
296 |
global standard_module_dependency
|
|
297 |
global prefix
|
|
298 |
|
|
299 |
std_deps_file = os.path.join(std_modules_dir, 'module_dependency.cfg')
|
|
300 |
|
|
301 |
try:
|
|
302 |
standard_module_dependency = eval(open(std_deps_file, 'rU').read())
|
|
303 |
except:
|
|
304 |
raise RuntimeError('Reading of module-repo config file failed:',
|
|
305 |
std_deps_file)
|
|
306 |
try:
|
|
307 |
prefix = open(os.path.join("templates", "prefix_data.txt"), "rU").read()
|
|
308 |
except:
|
|
309 |
raise RuntimeError('Getting prefix failed')
|
|
310 |
|
|
311 |
|
|
312 |
def get_dependency_list(src, extra_modules):
|
|
313 |
'''Process the source and return list of complete set of dependencies.'''
|
|
314 |
|
|
315 |
init_module_repo()
|
|
316 |
|
|
317 |
try:
|
|
318 |
extra_modules = extra_modules.split(',')
|
|
319 |
except:
|
|
320 |
extra_modules = []
|
|
321 |
|
|
322 |
dep_mods, unresolved_dep_mods = find_dep_modules(src)
|
|
323 |
add_to_resolved_std_repo(dep_mods)
|
|
324 |
resolve_unresolved_dep(list(set(unresolved_dep_mods + extra_modules)))
|
|
325 |
|
|
326 |
debug_print("Final dependency list: " + str(resolved_modules))
|
|
327 |
return resolved_modules
|
|
328 |
|
|
329 |
|
|
330 |
def copy_dep_file(dep_file, appdir):
|
|
331 |
global extrasdir
|
|
332 |
if dep_file.endswith('.pyd'):
|
|
333 |
# Move the pyds to extrasdir\sys\bin. If the
|
|
334 |
# application does not have extrasdir, then create it
|
|
335 |
# and set the 'extrasdir' ensymble option.
|
|
336 |
if extrasdir is None:
|
|
337 |
extrasdir_path = os.path.join(appdir,
|
|
338 |
"extras_dir", "sys", "bin")
|
|
339 |
if not os.path.exists(extrasdir_path):
|
|
340 |
os.makedirs(extrasdir_path)
|
|
341 |
extrasdir = 'extras_dir'
|
|
342 |
else:
|
|
343 |
extrasdir_path = os.path.join(appdir, extrasdir,
|
|
344 |
"sys", "bin")
|
|
345 |
if not os.path.exists(extrasdir_path):
|
|
346 |
os.makedirs(extrasdir_path)
|
|
347 |
debug_print("Copying '%s' to '%s' " % (dep_file, extrasdir_path))
|
|
348 |
shutil.copy(dep_file, extrasdir_path)
|
|
349 |
else:
|
|
350 |
# It is not a pyd. Copy to application private dir.
|
|
351 |
if os.path.basename(dep_file) != 'module_config.cfg':
|
|
352 |
debug_print("Copying '%s' to '%s' " % (dep_file, appdir))
|
|
353 |
shutil.copy(dep_file, appdir)
|
|
354 |
|
|
355 |
|
|
356 |
def process_dependent_modules(dep_module_paths):
|
|
357 |
|
|
358 |
def split_and_strip(dep_module_path, repo_dir):
|
|
359 |
return dep_module_path.split(repo_dir)[-1].lstrip(os.sep)
|
|
360 |
|
|
361 |
all_dep_mod_paths = []
|
|
362 |
all_dep_mod_paths.extend(dep_module_paths['std'])
|
|
363 |
all_dep_mod_paths.extend(dep_module_paths['dev'])
|
|
364 |
|
|
365 |
for dep_module_path in all_dep_mod_paths:
|
|
366 |
# relative_dir_path will have the path after the module-repo dir -
|
|
367 |
# xxx\\module-repo\\standard-modules\\<relative_dir_path>\\<files> or
|
|
368 |
# xxx\\module-repo\\dev-modules\\<module>\\<relative_dir_path>\\<files>
|
|
369 |
if dep_module_path in dep_module_paths['std']:
|
|
370 |
module_repo_dir = std_modules_dir
|
|
371 |
relative_dir_path = os.path.dirname(
|
|
372 |
split_and_strip(dep_module_path, module_repo_dir))
|
|
373 |
else:
|
|
374 |
module_repo_dir = dev_modules_dir
|
|
375 |
relative_dir_path = \
|
|
376 |
split_and_strip(dep_module_path, module_repo_dir)
|
|
377 |
# Remove the topmost dir as this directory is just a container for
|
|
378 |
# dev modules and it should not be created on the phone
|
|
379 |
relative_dir_path = os.path.dirname(
|
|
380 |
relative_dir_path.split(os.sep, 1)[-1])
|
|
381 |
|
|
382 |
debug_print("Relative dir path :" + relative_dir_path)
|
|
383 |
# Create the directory hierarchy rooted at appdir, if it doesn't exist.
|
|
384 |
if not os.path.exists(os.path.join(appdir, relative_dir_path)):
|
|
385 |
debug_print("Create dir" + os.path.join(appdir, relative_dir_path))
|
|
386 |
os.makedirs(os.path.join(appdir, relative_dir_path))
|
|
387 |
|
|
388 |
# If the module is a directory, then we loop through all the files at
|
|
389 |
# the top level of that directory and then call copy_dep_file to handle
|
|
390 |
# the copying of PYDs and .py files.
|
|
391 |
if os.path.isdir(dep_module_path):
|
|
392 |
debug_print("Dep module '%s' is a Directory" % dep_module_path)
|
|
393 |
|
|
394 |
# if the path contains 'standard-modules' then we directly copy the
|
|
395 |
# directory to appdir, else we parse the directory for PYDs and sub
|
|
396 |
# directories and then copy them to different directories.
|
|
397 |
if dep_module_path in dep_module_paths['std']:
|
|
398 |
dest_path = os.path.join(appdir, relative_dir_path,
|
|
399 |
os.path.basename(dep_module_path))
|
|
400 |
if os.path.exists(dest_path):
|
|
401 |
debug_print("Deleting directory: " + dest_path)
|
|
402 |
shutil.rmtree(dest_path)
|
|
403 |
debug_print("Copying directory as-is -'%s' to '%s'" % \
|
|
404 |
(dep_module_path, dest_path))
|
|
405 |
shutil.copytree(dep_module_path, dest_path)
|
|
406 |
else:
|
|
407 |
for dep_filename in os.listdir(dep_module_path):
|
|
408 |
dep_file_path = os.path.join(dep_module_path, dep_filename)
|
|
409 |
if os.path.isdir(dep_file_path):
|
|
410 |
# Copy the module's sub-directory as-is
|
|
411 |
dest_path = os.path.join(appdir,
|
|
412 |
relative_dir_path, dep_filename)
|
|
413 |
if os.path.exists(dest_path):
|
|
414 |
debug_print("Deleting directory: " + dest_path)
|
|
415 |
shutil.rmtree(dest_path)
|
|
416 |
debug_print("Copying directory as-is -'%s' to '%s'" % \
|
|
417 |
(dep_file_path, dest_path))
|
|
418 |
shutil.copytree(dep_file_path, dest_path)
|
|
419 |
else:
|
|
420 |
# PYDs should go to extrasdir rooted at appdir, whereas
|
|
421 |
# .py should go to appdir + relative_dir_path
|
|
422 |
if not dep_file_path.endswith('.pyd'):
|
|
423 |
copy_dep_file(dep_file_path, os.path.join(appdir,
|
|
424 |
relative_dir_path,
|
|
425 |
os.path.basename(dep_file_path)))
|
|
426 |
else:
|
|
427 |
copy_dep_file(dep_file_path, appdir)
|
|
428 |
else:
|
|
429 |
debug_print("Dependent module '%s' is a file" % dep_module_path)
|
|
430 |
# If the file is a pyd then we need to move it to extrasdir rooted
|
|
431 |
# at appdir, else move it to appdir + relative_dir_path
|
|
432 |
if not dep_module_path.endswith('.pyd'):
|
|
433 |
copy_dep_file(dep_module_path, os.path.join(appdir,
|
|
434 |
split_and_strip(dep_module_path, module_repo_dir)))
|
|
435 |
else:
|
|
436 |
copy_dep_file(dep_module_path, appdir)
|
|
437 |
|
|
438 |
|
|
439 |
def handle_dotted_dependencies(module_name, module_repo_dir):
|
|
440 |
# module_name is split into <module_root><module_dirs><module_leaf>
|
|
441 |
# For a module 'a.b' - module_root = a, module_dirs = '', module_leaf = b
|
|
442 |
# for 'a.b.c.d' - module_root = a, module_dirs = b.c and module_leaf = d
|
|
443 |
# Also convert all '.' to os.sep('\\' on windows) in module_dirs
|
|
444 |
module_root, module_path = module_name.split('.', 1)
|
|
445 |
if module_path.find('.') != -1:
|
|
446 |
module_dirs, module_leaf = module_path.rsplit('.', 1)
|
|
447 |
module_dirs = module_dirs.replace('.', os.sep)
|
|
448 |
else:
|
|
449 |
module_dirs = ''
|
|
450 |
module_leaf = module_path
|
|
451 |
debug_print("module_root-module_dirs-module_leaf : " + module_root + "-" +\
|
|
452 |
module_dirs + "-" + module_leaf)
|
|
453 |
# List the contents of the directory one level above module_leaf, check if
|
|
454 |
# module_leaf exists. If there are both .py and .py[c|o], then the .py file
|
|
455 |
# will be picked up.
|
|
456 |
sub_dir_contents = os.listdir(os.path.join(module_repo_dir, module_root,
|
|
457 |
module_dirs))
|
|
458 |
debug_print("Module dir contains :" + str(sub_dir_contents))
|
|
459 |
|
|
460 |
if module_leaf.lower() in \
|
|
461 |
[(os.path.basename(leaf_node).split('.')[0]).lower()
|
|
462 |
for leaf_node in sub_dir_contents]:
|
|
463 |
debug_print("Found sub-module '%s' in module directory" % module_leaf)
|
|
464 |
|
|
465 |
# Extract the full path of module_leaf by filtering out everything in
|
|
466 |
# the sub_module dir that does not match module_leaf
|
|
467 |
sub_module_paths = [os.path.join(module_repo_dir, module_root,
|
|
468 |
module_dirs, filename)
|
|
469 |
for filename in os.listdir(os.path.join(module_repo_dir,
|
|
470 |
module_root, module_dirs))]
|
|
471 |
for sub_module_path in sub_module_paths:
|
|
472 |
if os.path.basename(sub_module_path).split('.')[0] == module_leaf:
|
|
473 |
break
|
|
474 |
debug_print("Returning path to leaf node - " + sub_module_path)
|
|
475 |
|
|
476 |
return sub_module_path
|
|
477 |
|
|
478 |
|
|
479 |
def search_module(modules):
|
|
480 |
global error_count
|
|
481 |
dep_module_paths = {'std': [], 'dev': []}
|
|
482 |
if not os.path.exists(dev_modules_dir) or \
|
|
483 |
not os.path.exists(std_modules_dir):
|
|
484 |
raise RuntimeError("Module Dependency folder does not exist")
|
|
485 |
|
|
486 |
std_module_paths = [os.path.join(std_modules_dir, filename) \
|
|
487 |
for filename in os.listdir(std_modules_dir)]
|
|
488 |
std_module_names = [(os.path.basename(
|
|
489 |
std_module).split('.')[0].split(prefix)[-1]).lower()
|
|
490 |
for std_module in std_module_paths]
|
|
491 |
# The module_lookup_file contains a list of paths that should be scanned
|
|
492 |
# by the packaging tool when searching for a module before searching the
|
|
493 |
# module-repo.
|
|
494 |
try:
|
|
495 |
module_lookup_paths = eval(open(module_lookup_file, 'rU').read())
|
|
496 |
except IOError:
|
|
497 |
module_lookup_paths = []
|
|
498 |
pass
|
|
499 |
else:
|
|
500 |
debug_print("Custom lookup paths are :" + str(module_lookup_paths))
|
|
501 |
|
|
502 |
for module_name in modules[std_repo_module]:
|
|
503 |
dotted_module = False
|
|
504 |
# For a module named 'a.b.c.d', we split it into 'a' and 'b.c.d' to
|
|
505 |
# check if 'a' is present in either std-modules or dev-modules. If
|
|
506 |
# found, we then call handle_dotted_dependencies to find and return
|
|
507 |
# the path of 'b.c.d' which is then added to dep_module_paths['std'].
|
|
508 |
if module_name.find('.') != -1:
|
|
509 |
module_name, module_leaf = module_name.split('.', 1)
|
|
510 |
dotted_module = True
|
|
511 |
# Search in standard-modules repo directory. Remove the file extension
|
|
512 |
# and check if the module is present
|
|
513 |
if module_name.lower() in std_module_names:
|
|
514 |
debug_print("Dep module %s found in Std. Library" % module_name)
|
|
515 |
if dotted_module:
|
|
516 |
module_path = handle_dotted_dependencies(module_name + '.' +
|
|
517 |
module_leaf, std_modules_dir)
|
|
518 |
if module_path == None:
|
|
519 |
debug_print("WARNING: Module "+ \
|
|
520 |
"'%s' not found in standard module repo" % (module_name +\
|
|
521 |
'.' + module_leaf), print_anyways=True)
|
|
522 |
continue
|
|
523 |
debug_print("Adding '%s' to dep_module_paths['std']" %
|
|
524 |
module_path)
|
|
525 |
dep_module_paths['std'].append(module_path)
|
|
526 |
else:
|
|
527 |
# If it is a file then extract the full filename from the list
|
|
528 |
# std_module_paths and add it to dep_module_paths['std']
|
|
529 |
if not os.path.isdir(os.path.join(std_modules_dir,
|
|
530 |
module_name)):
|
|
531 |
for std_module_path in std_module_paths:
|
|
532 |
if os.path.basename(
|
|
533 |
std_module_path).split('.')[0].split(prefix)[-1] ==\
|
|
534 |
module_name:
|
|
535 |
break
|
|
536 |
dep_module_paths['std'].append(std_module_path)
|
|
537 |
else:
|
|
538 |
dep_module_paths['std'].append(
|
|
539 |
os.path.join(std_modules_dir, module_name))
|
|
540 |
elif ignore_missing_deps:
|
|
541 |
# If this flag is set then print the missing dependencies as
|
|
542 |
# warnings else print them as errors
|
|
543 |
debug_print("WARNING: Dependent module '%s' not found" %
|
|
544 |
module_name, print_anyways=True)
|
|
545 |
continue
|
|
546 |
else:
|
|
547 |
error_count += 1
|
|
548 |
debug_print("ERROR: Dependent module '%s' not found" %
|
|
549 |
module_name, print_anyways=True)
|
|
550 |
continue
|
|
551 |
|
|
552 |
for module_name in modules[dev_repo_module]:
|
|
553 |
# Dotted dependencies are ignored and the entire dev module is
|
|
554 |
# added to dep_module_paths['dev'].
|
|
555 |
# If the module is a third party dev module then we check the
|
|
556 |
# custom lookup path
|
|
557 |
if module_name not in pys60_extension_modules:
|
|
558 |
module_found = False
|
|
559 |
if module_lookup_paths:
|
|
560 |
for module_lookup_path in module_lookup_paths:
|
|
561 |
if os.path.exists(os.path.join(module_lookup_path,
|
|
562 |
prefix + module_name + '.pyd')):
|
|
563 |
debug_print("Module found in custom lookup path " +
|
|
564 |
module_lookup_path)
|
|
565 |
copy_dep_file(os.path.join(module_lookup_path,
|
|
566 |
prefix + module_name + '.pyd'),
|
|
567 |
appdir)
|
|
568 |
module_found = True
|
|
569 |
break
|
|
570 |
if module_found:
|
|
571 |
continue
|
|
572 |
debug_print("Processing dev module : " + module_name)
|
|
573 |
|
|
574 |
debug_print("Adding '%s' to dep_module_paths['dev']" %
|
|
575 |
os.path.join(dev_modules_dir, module_name))
|
|
576 |
dep_module_paths['dev'].append(
|
|
577 |
os.path.join(dev_modules_dir, module_name))
|
|
578 |
|
|
579 |
return dep_module_paths
|