Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / user.py
CommitLineData
86530b38
AT
1"""Hook to allow user-specified customization code to run.
2
3As a policy, Python doesn't run user-specified code on startup of
4Python programs (interactive sessions execute the script specified in
5the PYTHONSTARTUP environment variable if it exists).
6
7However, some programs or sites may find it convenient to allow users
8to have a standard customization file, which gets run when a program
9requests it. This module implements such a mechanism. A program
10that wishes to use the mechanism must execute the statement
11
12 import user
13
14The user module looks for a file .pythonrc.py in the user's home
15directory and if it can be opened, execfile()s it in its own global
16namespace. Errors during this phase are not caught; that's up to the
17program that imports the user module, if it wishes.
18
19The user's .pythonrc.py could conceivably test for sys.version if it
20wishes to do different things depending on the Python version.
21
22"""
23
24import os
25
26home = os.curdir # Default
27if 'HOME' in os.environ:
28 home = os.environ['HOME']
29elif os.name == 'posix':
30 home = os.path.expanduser("~/")
31elif os.name == 'nt': # Contributed by Jeff Bauer
32 if 'HOMEPATH' in os.environ:
33 if 'HOMEDRIVE' in os.environ:
34 home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH']
35 else:
36 home = os.environ['HOMEPATH']
37
38pythonrc = os.path.join(home, ".pythonrc.py")
39try:
40 f = open(pythonrc)
41except IOError:
42 pass
43else:
44 f.close()
45 execfile(pythonrc)