0
|
1 |
# Copyright (c) 2009 Nokia Corporation
|
|
2 |
#
|
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
# you may not use this file except in compliance with the License.
|
|
5 |
# You may obtain a copy of the License at
|
|
6 |
#
|
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
#
|
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
# See the License for the specific language governing permissions and
|
|
13 |
# limitations under the License.
|
|
14 |
|
|
15 |
import os
|
|
16 |
|
|
17 |
excluded_modules = []
|
|
18 |
module_paths = []
|
|
19 |
pyd_path_name = []
|
|
20 |
|
|
21 |
|
|
22 |
def get_mod_list(arg, dirname, names):
|
|
23 |
for name in names:
|
|
24 |
# This check is done for not including the test_ files for modules
|
|
25 |
if not name.startswith('test_') and name.endswith('.py'):
|
|
26 |
path = os.path.join(dirname, name)
|
|
27 |
path = path.replace(lib_path + '\\', '')
|
|
28 |
# This check for 'test' is done to remove those files which fall
|
|
29 |
# under test or crashers
|
|
30 |
if not 'test' in path:
|
|
31 |
module_paths.append(path)
|
|
32 |
|
|
33 |
|
|
34 |
def gen_excluded_list():
|
|
35 |
global excluded_modules
|
|
36 |
py_module = []
|
|
37 |
module_type = []
|
|
38 |
pyd_modules = []
|
|
39 |
builtin_modules = []
|
|
40 |
modules_cfg_path = \
|
|
41 |
os.path.abspath('..\\newcore\\Symbian\\src\\modules.cfg')
|
|
42 |
config_file = open(modules_cfg_path, 'r')
|
|
43 |
for line in config_file:
|
|
44 |
line = line.strip()
|
|
45 |
if line in ['PYD', 'PY_MODULES', 'BUILTIN', 'EXT-MODULES',
|
|
46 |
'EXT-PYD', 'EXT-MOD-CFGS']:
|
|
47 |
module_type = line
|
|
48 |
continue
|
|
49 |
if line and line[0] != '#':
|
|
50 |
if module_type == 'PYD':
|
|
51 |
pyd_modules.append(line.split(',')[0])
|
|
52 |
elif module_type == 'BUILTIN':
|
|
53 |
builtin_modules.append(line.split('=')[0])
|
|
54 |
elif module_type == 'PY_MODULES':
|
|
55 |
py_module.append(line.split(':')[1])
|
|
56 |
excluded_modules = py_module + builtin_modules + pyd_modules
|
|
57 |
|
|
58 |
|
|
59 |
def get_pyd_list(arg, dirname, names):
|
|
60 |
for name in names:
|
|
61 |
if name.endswith('.c'):
|
|
62 |
path = os.path.join(dirname, name)
|
|
63 |
buf = open(path, 'r').read()
|
|
64 |
if "Py_InitModule" in buf:
|
|
65 |
pyd_path_name.append(path)
|
|
66 |
|
|
67 |
|
|
68 |
def add_pyd():
|
|
69 |
pyd_name = []
|
|
70 |
for pyd in pyd_path_name:
|
|
71 |
fp = open(pyd, 'r')
|
|
72 |
file_name = os.path.basename(pyd)
|
|
73 |
for line in fp:
|
|
74 |
if "Py_InitModule" in line:
|
|
75 |
try:
|
|
76 |
pyd_name.append(line.split('"')[1])
|
|
77 |
except:
|
|
78 |
# Some files do not have their pyd names in Py_InitModule,
|
|
79 |
# a split on these files would not yield the names so their
|
|
80 |
# names are hard coded
|
|
81 |
if file_name == 'unicodedata.c':
|
|
82 |
pyd_name.append('unicodedata')
|
|
83 |
elif file_name == 'posixmodule.c':
|
|
84 |
pyd_name.append('posix')
|
|
85 |
elif file_name == 'pyexpat.c':
|
|
86 |
pyd_name.append('pyexpat')
|
|
87 |
elif file_name == 'socketmodule.c':
|
|
88 |
pyd_name.append('_socket')
|
|
89 |
elif file_name == '_bsddb.c':
|
|
90 |
pyd_name.append('_bsddb')
|
|
91 |
continue
|
|
92 |
fp.close()
|
|
93 |
module_paths.extend(pyd_name)
|
|
94 |
|
|
95 |
|
|
96 |
def gen_mod_dep_cfg_template():
|
|
97 |
# These are the module dependency map for modules that are not
|
|
98 |
# found by the module_config_parser and hence they need an explicit mention
|
|
99 |
additional_modules = {'__main__': {'type': 'base', 'deps': []},
|
|
100 |
'__builtin__': {'type': 'base', 'deps': []},
|
|
101 |
'sys': {'type': 'base', 'deps': []},
|
|
102 |
'nt': {'type': 'excluded', 'deps': []},
|
|
103 |
'win32evtlogutil':{'type': 'excluded', 'deps': []},
|
|
104 |
'win32evtlog': {'type': 'excluded', 'deps': []}}
|
|
105 |
|
|
106 |
for module in excluded_modules:
|
|
107 |
if module in module_paths:
|
|
108 |
module_paths.remove(module)
|
|
109 |
|
|
110 |
# The exclude py_files() are parsed here
|
|
111 |
dep_map = {}
|
|
112 |
mod_dep_cfg_template_path = \
|
|
113 |
os.path.abspath(
|
|
114 |
'..\\newcore\\Symbian\\src\\module_dependency.cfg.template')
|
|
115 |
dep_map = eval(open(mod_dep_cfg_template_path, 'r').read())
|
|
116 |
dep_map.update(additional_modules)
|
|
117 |
mod_map = {}
|
|
118 |
for mod in module_paths:
|
|
119 |
mod_map['type'] = 'excluded'
|
|
120 |
mod_map['deps'] = []
|
|
121 |
mod_name = os.path.splitext(mod)[0].replace('\\', '.')
|
|
122 |
dep_map[mod_name] = mod_map
|
|
123 |
open(mod_dep_cfg_template_path, 'w').write(str(dep_map))
|
|
124 |
|
|
125 |
fp = open(mod_dep_cfg_template_path, 'r')
|
|
126 |
buf = fp.read()
|
|
127 |
buf = buf.replace("}, '", "}, \n'")
|
|
128 |
fp.close()
|
|
129 |
open(mod_dep_cfg_template_path, 'w').write(buf)
|
|
130 |
|
|
131 |
if __name__ == "__main__":
|
|
132 |
# Walk through the Lib path for inbuilt modules
|
|
133 |
lib_path = os.path.abspath("..\\newcore\\Lib")
|
|
134 |
os.path.walk(lib_path, get_mod_list, None)
|
|
135 |
gen_excluded_list()
|
|
136 |
os.path.walk(os.path.abspath("..\\newcore\\Modules"), get_pyd_list, None)
|
|
137 |
add_pyd()
|
|
138 |
gen_mod_dep_cfg_template()
|