OLD | NEW |
1 # | 1 # |
2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion |
3 # | 3 # |
4 # Permission is hereby granted, free of charge, to any person obtaining | 4 # Permission is hereby granted, free of charge, to any person obtaining |
5 # a copy of this software and associated documentation files (the | 5 # a copy of this software and associated documentation files (the |
6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
7 # without limitation the rights to use, copy, modify, merge, publish, | 7 # without limitation the rights to use, copy, modify, merge, publish, |
8 # distribute, sublicense, and/or sell copies of the Software, and to | 8 # distribute, sublicense, and/or sell copies of the Software, and to |
9 # permit persons to whom the Software is furnished to do so, subject to | 9 # permit persons to whom the Software is furnished to do so, subject to |
10 # the following conditions: | 10 # the following conditions: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 We name the compatibility modules with an initial '_scons_' (for example, | 54 We name the compatibility modules with an initial '_scons_' (for example, |
55 _scons_subprocess.py is our compatibility module for subprocess) so | 55 _scons_subprocess.py is our compatibility module for subprocess) so |
56 that we can still try to import the real module name and fall back to | 56 that we can still try to import the real module name and fall back to |
57 our compatibility module if we get an ImportError. The import_as() | 57 our compatibility module if we get an ImportError. The import_as() |
58 function defined below loads the module as the "real" name (without the | 58 function defined below loads the module as the "real" name (without the |
59 '_scons'), after which all of the "import {module}" statements in the | 59 '_scons'), after which all of the "import {module}" statements in the |
60 rest of our code will find our pre-loaded compatibility module. | 60 rest of our code will find our pre-loaded compatibility module. |
61 """ | 61 """ |
62 | 62 |
63 __revision__ = "src/engine/SCons/compat/__init__.py 3603 2008/10/10 05:46:45 sco
ns" | 63 __revision__ = "src/engine/SCons/compat/__init__.py 3842 2008/12/20 22:59:52 sco
ns" |
64 | 64 |
65 def import_as(module, name): | 65 def import_as(module, name): |
66 """ | 66 """ |
67 Imports the specified module (from our local directory) as the | 67 Imports the specified module (from our local directory) as the |
68 specified name. | 68 specified name. |
69 """ | 69 """ |
70 import imp | 70 import imp |
71 import os.path | 71 import os.path |
72 dir = os.path.split(__file__)[0] | 72 dir = os.path.split(__file__)[0] |
73 file, filename, suffix_mode_type = imp.find_module(module, [dir]) | 73 file, filename, suffix_mode_type = imp.find_module(module, [dir]) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 except ImportError: | 148 except ImportError: |
149 # Pre-2.3 Python has no textwrap module. | 149 # Pre-2.3 Python has no textwrap module. |
150 import_as('_scons_textwrap', 'textwrap') | 150 import_as('_scons_textwrap', 'textwrap') |
151 | 151 |
152 try: | 152 try: |
153 import optparse | 153 import optparse |
154 except ImportError: | 154 except ImportError: |
155 # Pre-2.3 Python has no optparse module. | 155 # Pre-2.3 Python has no optparse module. |
156 import_as('_scons_optparse', 'optparse') | 156 import_as('_scons_optparse', 'optparse') |
157 | 157 |
| 158 import os |
| 159 try: |
| 160 os.devnull |
| 161 except AttributeError: |
| 162 # Pre-2.4 Python has no os.devnull attribute |
| 163 import sys |
| 164 _names = sys.builtin_module_names |
| 165 if 'posix' in _names: |
| 166 os.devnull = '/dev/null' |
| 167 elif 'nt' in _names: |
| 168 os.devnull = 'nul' |
| 169 os.path.devnull = os.devnull |
| 170 |
158 import shlex | 171 import shlex |
159 try: | 172 try: |
160 shlex.split | 173 shlex.split |
161 except AttributeError: | 174 except AttributeError: |
162 # Pre-2.3 Python has no shlex.split() function. | 175 # Pre-2.3 Python has no shlex.split() function. |
163 # | 176 # |
164 # The full white-space splitting semantics of shlex.split() are | 177 # The full white-space splitting semantics of shlex.split() are |
165 # complicated to reproduce by hand, so just use a compatibility | 178 # complicated to reproduce by hand, so just use a compatibility |
166 # version of the shlex module cribbed from Python 2.5 with some | 179 # version of the shlex module cribbed from Python 2.5 with some |
167 # minor modifications for older Python versions. | 180 # minor modifications for older Python versions. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 import string | 235 import string |
223 version_string = string.split(sys.version)[0] | 236 version_string = string.split(sys.version)[0] |
224 version_ints = map(int, string.split(version_string, '.')) | 237 version_ints = map(int, string.split(version_string, '.')) |
225 sys.version_info = tuple(version_ints + ['final', 0]) | 238 sys.version_info = tuple(version_ints + ['final', 0]) |
226 | 239 |
227 try: | 240 try: |
228 import UserString | 241 import UserString |
229 except ImportError: | 242 except ImportError: |
230 # Pre-1.6 Python has no UserString module. | 243 # Pre-1.6 Python has no UserString module. |
231 import_as('_scons_UserString', 'UserString') | 244 import_as('_scons_UserString', 'UserString') |
OLD | NEW |