-
Notifications
You must be signed in to change notification settings - Fork 0
/
_importable_modules.py
52 lines (47 loc) · 1.62 KB
/
_importable_modules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#COPYRIGHT 2012 ESRI
#
#TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
#Unpublished material - all rights reserved under the
#Copyright Laws of the United States.
#
#For additional information, contact:
#Environmental Systems Research Institute, Inc.
#Attn: Contracts Dept
#380 New York Street
#Redlands, California, USA 92373
#
#email: contracts@esri.com
import imp
import os
import sys
__all__ = ['importable_modules']
importable_modules = []
def _refresh():
global importable_modules
module_list = set()
suffixes = set(x[0].lower() for x in imp.get_suffixes())
syspath = map(os.path.normcase, sys.path)
for apath in syspath:
if not apath:
continue
for path, dirs, files in os.walk(apath):
path = os.path.normcase(path)
if path != apath and path in syspath:
continue
elif path.lower().endswith(".egg"): # Skip .egg paths
continue
modname = os.path.relpath(path, apath).replace(os.sep, ".") + "."
if "-" in modname:
continue
elif modname == "..":
modname = ""
for module in [file for file in files if os.path.splitext(file)[1].lower() in suffixes]:
amod = modname + os.path.splitext(os.path.basename(module))[0]
if amod.endswith(".__init__"):
amod = os.path.splitext(amod)[0]
if not os.path.basename(module).startswith("_"):
module_list.add(amod)
importable_modules = sorted(module_list)
_refresh()
if __name__ == "__main__":
print "\n".join(importable_modules)