Added function ttob.
[python/dscho.git] / Lib / os.py
blob7322fa56f93f5221580a42f176285cbbcb215c1f
1 # os.py -- either mac or posix depending on what system we're on.
3 # This exports:
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 ':')
11 # Programs that import and use 'os' stand a better chance of being
12 # portable between different platforms. Of course, they must then
13 # only use functions that are defined by all platforms (e.g., unlink
14 # and opendir), and leave all pathname manipulation to os.path
15 # (e.g., split and join).
17 # XXX This will need to distinguish between real posix and MS-DOS emulation
19 try:
20 from posix import *
21 try:
22 from posix import _exit
23 except ImportError:
24 pass
25 name = 'posix'
26 curdir = '.'
27 pardir = '..'
28 sep = '/'
29 import posixpath
30 path = posixpath
31 del posixpath
32 except ImportError:
33 from mac import *
34 name = 'mac'
35 curdir = ':'
36 pardir = '::'
37 sep = ':'
38 import macpath
39 path = macpath
40 del macpath
42 def execl(file, *args):
43 execv(file, args)
45 def execle(file, *args):
46 env = args[-1]
47 execve(file, args[:-1], env)
49 def execlp(file, *args):
50 execvp(file, args)
52 def execvp(file, args):
53 if '/' in file:
54 execv(file, args)
55 return
56 ENOENT = 2
57 if environ.has_key('PATH'):
58 import string
59 PATH = string.splitfields(environ['PATH'], ':')
60 else:
61 PATH = ['', '/bin', '/usr/bin']
62 exc, arg = (ENOENT, 'No such file or directory')
63 for dir in PATH:
64 fullname = path.join(dir, file)
65 try:
66 execv(fullname, args)
67 except error, (errno, msg):
68 if errno != ENOENT:
69 exc, arg = error, (errno, msg)
70 raise exc, arg