svn-gvsig-desktop / tags / v1_0_2_Build_898 / extensions / extScripting / scripts / jython / Lib / user.py @ 10513
History | View | Annotate | Download (1.43 KB)
1 |
"""Hook to allow user-specified customization code to run.
|
---|---|
2 |
|
3 |
As a policy, Python doesn't run user-specified code on startup of
|
4 |
Python programs (interactive sessions execute the script specified in
|
5 |
the PYTHONSTARTUP environment variable if it exists).
|
6 |
|
7 |
However, some programs or sites may find it convenient to allow users
|
8 |
to have a standard customization file, which gets run when a program
|
9 |
requests it. This module implements such a mechanism. A program
|
10 |
that wishes to use the mechanism must execute the statement
|
11 |
|
12 |
import user
|
13 |
|
14 |
The user module looks for a file .pythonrc.py in the user's home
|
15 |
directory and if it can be opened, execfile()s it in its own global
|
16 |
namespace. Errors during this phase are not caught; that's up to the
|
17 |
program that imports the user module, if it wishes.
|
18 |
|
19 |
The user's .pythonrc.py could conceivably test for sys.version if it
|
20 |
wishes to do different things depending on the Python version.
|
21 |
|
22 |
"""
|
23 |
|
24 |
import os |
25 |
|
26 |
home = os.curdir # Default
|
27 |
if os.environ.has_key('HOME'): |
28 |
home = os.environ['HOME']
|
29 |
elif os.name == 'nt': # Contributed by Jeff Bauer |
30 |
if os.environ.has_key('HOMEPATH'): |
31 |
if os.environ.has_key('HOMEDRIVE'): |
32 |
home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH'] |
33 |
else:
|
34 |
home = os.environ['HOMEPATH']
|
35 |
|
36 |
pythonrc = os.path.join(home, ".pythonrc.py")
|
37 |
try:
|
38 |
f = open(pythonrc)
|
39 |
except IOError: |
40 |
pass
|
41 |
else:
|
42 |
f.close() |
43 |
execfile(pythonrc)
|