3 # Locate all standard modules available in this build.
5 # This script is designed to run on Python 1.5.2 and newer.
7 # Written by Fredrik Lundh, January 2005
10 import imp
, sys
, os
, re
, time
12 identifier
= "python-%s-%s" % (sys
.version
[:3], sys
.platform
)
13 timestamp
= time
.strftime("%Y%m%dT%H%M%SZ", time
.gmtime(time
.time()))
16 TEST_PACKAGES
= "test.", "bsddb.test.", "distutils.tests."
20 platform
= platform
.platform()
22 platform
= None # unknown
24 suffixes
= imp
.get_suffixes()
27 for suffix
in suffixes
:
28 if file[-len(suffix
[0]):] == suffix
[0]:
37 for m
in sys
.builtin_module_names
:
41 modules
.update(getmodules(p
))
46 # filter out known test packages
48 for d
in TEST_PACKAGES
:
52 keys
= filter(cb
, keys
)
59 outfile
= "modules-" + identifier
+ ".txt"
66 out
= open(outfile
, "w")
68 out
.write("# module list (generated by listmodules.py)\n")
70 out
.write("# timestamp=%s\n" % repr(timestamp
))
71 out
.write("# sys.version=%s\n" % repr(sys
.version
))
72 out
.write("# sys.platform=%s\n" % repr(sys
.platform
))
74 out
.write("# platform=%s\n" % repr(platform
))
80 if out
is not sys
.stdout
:
82 print out
.name
, "ok (%d modules)" % len(modules
)
85 # get modules in a given directory
87 for f
in os
.listdir(p
):
88 f
= os
.path
.join(p
, f
)
90 m
, e
= os
.path
.splitext(f
)
91 suffix
= get_suffix(f
)
94 m
= os
.path
.basename(m
)
95 if re
.compile("(?i)[a-z_]\w*$").match(m
):
96 if suffix
[2] == imp
.C_EXTENSION
:
97 # check that this extension can be imported
103 elif os
.path
.isdir(f
):
104 m
= os
.path
.basename(f
)
105 if os
.path
.isfile(os
.path
.join(f
, "__init__.py")):
106 for mm
, f
in getmodules(f
).items():
107 modules
[m
+ "." + mm
] = f
111 path
= map(os
.path
.normcase
, map(os
.path
.abspath
, sys
.path
[:]))
112 # get rid of site packages
114 if p
[-13:] == "site-packages":
115 def cb(p
, site_package_path
=os
.path
.abspath(p
)):
116 return p
[:len(site_package_path
)] != site_package_path
117 path
= filter(cb
, path
)
119 # get rid of non-existent directories and the current directory
120 def cb(p
, cwd
=os
.path
.normcase(os
.getcwd())):
121 return os
.path
.isdir(p
) and p
!= cwd
122 path
= filter(cb
, path
)
125 if __name__
== "__main__":