1 # os.py -- either mac, dos or posix depending on what system we're on.
4 # - all functions from either posix or mac, e.g., os.unlink, os.stat, etc.
5 # - os.path is either module posixpath or macpath
6 # - os.name is either 'posix' or 'mac'
7 # - os.curdir is a string representing the current directory ('.' or ':')
8 # - os.pardir is a string representing the parent directory ('..' or '::')
9 # - os.sep is the (or a most common) pathname separator ('/' or ':')
10 # - os.pathsep is the component separator used in $PATH etc
11 # - os.defpath is the default search path for executables
13 # Programs that import and use 'os' stand a better chance of being
14 # portable between different platforms. Of course, they must then
15 # only use functions that are defined by all platforms (e.g., unlink
16 # and opendir), and leave all pathname manipulation to os.path
17 # (e.g., split and join).
20 'posix': ('.', '..', '/', ':', ':/bin:/usr/bin'),
21 'dos': ('.', '..', '\\', ';', '.;C:\\bin'),
22 'nt': ('.', '..', '\\', ';', '.;C:\\bin'),
23 'mac': (':', '::', ':', '\n', ':'),
26 # For freeze.py script:
32 for name
in _osindex
.keys():
33 if name
in sys
.builtin_module_names
:
34 curdir
, pardir
, sep
, pathsep
, defpath
= _osindex
[name
]
35 exec 'from %s import *' % name
36 exec 'import %spath' % name
37 exec 'path = %spath' % name
38 exec 'del %spath' % name
40 exec 'from %s import _exit' % name
46 environ
= {} # Make sure os.environ exists, at least
50 raise ImportError, 'no os specific module found'
52 def execl(file, *args
):
55 def execle(file, *args
):
57 execve(file, args
[:-1], env
)
59 def execlp(file, *args
):
62 def execlpe(file, *args
):
64 execvpe(file, args
[:-1], env
)
66 def execvp(file, args
):
69 def execvpe(file, args
, env
):
70 _execvpe(file, args
, env
)
73 def _execvpe(file, args
, env
= None):
82 head
, tail
= path
.split(file)
84 apply(func
, (file,) + argrest
)
86 if env
.has_key('PATH'):
91 PATH
= string
.splitfields(envpath
, pathsep
)
94 # Exec a file that is guaranteed not to exist
95 try: execv(tempfile
.mktemp(), ())
96 except error
, _notfound
: pass
97 exc
, arg
= error
, _notfound
99 fullname
= path
.join(dir, file)
101 apply(func
, (fullname
,) + argrest
)
102 except error
, (errno
, msg
):
104 exc
, arg
= error
, (errno
, msg
)
107 # Provide listdir for Windows NT that doesn't have it built in
114 if path
.ismount(name
):
118 f
= popen('dir/l/b ' + name
, 'r')
121 list.append(line
[:-1])