blob: f6056d0de60ec5177aeed1068f3c1b86be1e5c03 [file] [log] [blame]
Tor Norbye3a2425a2013-11-04 10:16:08 -08001'''
2This module was created to get information available in the interpreter, such as libraries,
3paths, etc.
4
5what is what:
6sys.builtin_module_names: contains the builtin modules embeeded in python (rigth now, we specify all manually).
7sys.prefix: A string giving the site-specific directory prefix where the platform independent Python files are installed
8
9format is something as
10EXECUTABLE:python.exe|libs@compiled_dlls$builtin_mods
11
12all internal are separated by |
13'''
14import sys
15import os
16
17
18try:
19 #Just check if False and True are defined (depends on version, not whether it's jython/python)
20 False
21 True
22except:
23 exec ('True, False = 1,0') #An exec is used so that python 3k does not give a syntax error
24
25import pydevd_constants
26
27if pydevd_constants.USE_LIB_COPY:
28 import _pydev_time as time
29else:
30 import time
31
32if sys.platform == "cygwin":
33
34 try:
35 import ctypes #use from the system if available
36 except ImportError:
37 sys.path.append(os.path.join(sys.path[0], 'ThirdParty/wrapped_for_pydev'))
38 import ctypes
39
40 def nativePath(path):
41 MAX_PATH = 512 # On cygwin NT, its 260 lately, but just need BIG ENOUGH buffer
42 '''Get the native form of the path, like c:\\Foo for /cygdrive/c/Foo'''
43
44 retval = ctypes.create_string_buffer(MAX_PATH)
45 path = fullyNormalizePath(path)
46 ctypes.cdll.cygwin1.cygwin_conv_to_win32_path(path, retval) #@UndefinedVariable
47 return retval.value
48
49else:
50 def nativePath(path):
51 return fullyNormalizePath(path)
52
53def fullyNormalizePath(path):
54 '''fixes the path so that the format of the path really reflects the directories in the system
55 '''
56 return os.path.normpath(path)
57
58
59if __name__ == '__main__':
60 try:
61 #just give some time to get the reading threads attached (just in case)
62 time.sleep(0.1)
63 except:
64 pass
65
66 try:
67 executable = nativePath(sys.executable)
68 except:
69 executable = sys.executable
70
71 if sys.platform == "cygwin" and not executable.endswith('.exe'):
72 executable += '.exe'
73
74
75 try:
76 s = 'Version%s.%s' % (sys.version_info[0], sys.version_info[1])
77 except AttributeError:
78 #older versions of python don't have version_info
79 import string
80 s = string.split(sys.version, ' ')[0]
81 s = string.split(s, '.')
82 major = s[0]
83 minor = s[1]
84 s = 'Version%s.%s' % (major, minor)
85
86 sys.stdout.write('%s\n' % (s,))
87
88 sys.stdout.write('EXECUTABLE:%s|\n' % executable)
89
90 #this is the new implementation to get the system folders
91 #(still need to check if it works in linux)
92 #(previously, we were getting the executable dir, but that is not always correct...)
93 prefix = nativePath(sys.prefix)
94 #print_ 'prefix is', prefix
95
96
97 result = []
98
99 path_used = sys.path
100 try:
101 path_used = path_used[:] #Use a copy.
102 except:
103 pass #just ignore it...
104
105 for p in path_used:
106 p = nativePath(p)
107
108 try:
109 import string #to be compatible with older versions
110 if string.find(p, prefix) == 0: #was startswith
111 result.append((p, True))
112 else:
113 result.append((p, False))
114 except (ImportError, AttributeError):
115 #python 3k also does not have it
116 #jython may not have it (depending on how are things configured)
117 if p.startswith(prefix): #was startswith
118 result.append((p, True))
119 else:
120 result.append((p, False))
121
122 for p, b in result:
123 if b:
124 sys.stdout.write('|%s%s\n' % (p, 'INS_PATH'))
125 else:
126 sys.stdout.write('|%s%s\n' % (p, 'OUT_PATH'))
127
128 sys.stdout.write('@\n') #no compiled libs
129 sys.stdout.write('$\n') #the forced libs
130
131 for builtinMod in sys.builtin_module_names:
132 sys.stdout.write('|%s\n' % builtinMod)
133
134
135 try:
136 sys.stdout.flush()
137 sys.stderr.flush()
138 #and give some time to let it read things (just in case)
139 time.sleep(0.1)
140 except:
141 pass
142
143 raise RuntimeError('Ok, this is so that it shows the output (ugly hack for some platforms, so that it releases the output).')