Show More
@@ -16,7 +16,7 b' __docformat__ = "restructuredtext en"' | |||
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | import os |
|
19 |
from IPython. |
|
|
19 | from IPython.genutils import get_home_dir, get_ipython_dir | |
|
20 | 20 | from IPython.external.configobj import ConfigObj |
|
21 | 21 | |
|
22 | 22 | # Traitlets config imports |
@@ -22,71 +22,6 b' import sys' | |||
|
22 | 22 | # Normal code begins |
|
23 | 23 | #--------------------------------------------------------------------------- |
|
24 | 24 | |
|
25 | class HomeDirError(Exception): | |
|
26 | pass | |
|
27 | ||
|
28 | def get_home_dir(): | |
|
29 | """Return the closest possible equivalent to a 'home' directory. | |
|
30 | ||
|
31 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. | |
|
32 | ||
|
33 | Currently only Posix and NT are implemented, a HomeDirError exception is | |
|
34 | raised for all other OSes. """ | |
|
35 | ||
|
36 | isdir = os.path.isdir | |
|
37 | env = os.environ | |
|
38 | try: | |
|
39 | homedir = env['HOME'] | |
|
40 | if not isdir(homedir): | |
|
41 | # in case a user stuck some string which does NOT resolve to a | |
|
42 | # valid path, it's as good as if we hadn't foud it | |
|
43 | raise KeyError | |
|
44 | return homedir | |
|
45 | except KeyError: | |
|
46 | if os.name == 'posix': | |
|
47 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' | |
|
48 | elif os.name == 'nt': | |
|
49 | # For some strange reason, win9x returns 'nt' for os.name. | |
|
50 | try: | |
|
51 | homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH']) | |
|
52 | if not isdir(homedir): | |
|
53 | homedir = os.path.join(env['USERPROFILE']) | |
|
54 | if not isdir(homedir): | |
|
55 | raise HomeDirError | |
|
56 | return homedir | |
|
57 | except: | |
|
58 | try: | |
|
59 | # Use the registry to get the 'My Documents' folder. | |
|
60 | import _winreg as wreg | |
|
61 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, | |
|
62 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") | |
|
63 | homedir = wreg.QueryValueEx(key,'Personal')[0] | |
|
64 | key.Close() | |
|
65 | if not isdir(homedir): | |
|
66 | e = ('Invalid "Personal" folder registry key ' | |
|
67 | 'typically "My Documents".\n' | |
|
68 | 'Value: %s\n' | |
|
69 | 'This is not a valid directory on your system.' % | |
|
70 | homedir) | |
|
71 | raise HomeDirError(e) | |
|
72 | return homedir | |
|
73 | except HomeDirError: | |
|
74 | raise | |
|
75 | except: | |
|
76 | return 'C:\\' | |
|
77 | elif os.name == 'dos': | |
|
78 | # Desperate, may do absurd things in classic MacOS. May work under DOS. | |
|
79 | return 'C:\\' | |
|
80 | else: | |
|
81 | raise HomeDirError,'support for your operating system not implemented.' | |
|
82 | ||
|
83 | def get_ipython_dir(): | |
|
84 | ipdir_def = '.ipython' | |
|
85 | home_dir = get_home_dir() | |
|
86 | ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', | |
|
87 | os.path.join(home_dir,ipdir_def))) | |
|
88 | return ipdir | |
|
89 | ||
|
90 | 25 | def import_item(key): |
|
91 | 26 | """ |
|
92 | 27 | Import and return bar given the string foo.bar. |
@@ -979,6 +979,22 b' def get_home_dir():' | |||
|
979 | 979 | else: |
|
980 | 980 | raise HomeDirError,'support for your operating system not implemented.' |
|
981 | 981 | |
|
982 | ||
|
983 | def get_ipython_dir(): | |
|
984 | """Get the IPython directory for this platform and user. | |
|
985 | ||
|
986 | This uses the logic in `get_home_dir` to find the home directory | |
|
987 | and the adds either .ipython or _ipython to the end of the path. | |
|
988 | """ | |
|
989 | if os.name == 'posix': | |
|
990 | ipdir_def = '.ipython' | |
|
991 | else: | |
|
992 | ipdir_def = '_ipython' | |
|
993 | home_dir = get_home_dir() | |
|
994 | ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', | |
|
995 | os.path.join(home_dir,ipdir_def))) | |
|
996 | return ipdir | |
|
997 | ||
|
982 | 998 | #**************************************************************************** |
|
983 | 999 | # strings and text |
|
984 | 1000 |
@@ -17,7 +17,7 b' __docformat__ = "restructuredtext en"' | |||
|
17 | 17 | |
|
18 | 18 | from IPython.external.configobj import ConfigObj |
|
19 | 19 | from IPython.config.api import ConfigObjManager |
|
20 |
from IPython. |
|
|
20 | from IPython.genutils import get_ipython_dir | |
|
21 | 21 | |
|
22 | 22 | default_kernel_config = ConfigObj() |
|
23 | 23 |
@@ -50,7 +50,7 b' from IPython.kernel.engineservice import \\' | |||
|
50 | 50 | IEngineSerialized, \ |
|
51 | 51 | IEngineQueued |
|
52 | 52 | |
|
53 |
from IPython. |
|
|
53 | from IPython.genutils import get_ipython_dir | |
|
54 | 54 | from IPython.kernel import codeutil |
|
55 | 55 | |
|
56 | 56 | #------------------------------------------------------------------------------- |
@@ -170,7 +170,7 b' class ControllerService(object, service.Service):' | |||
|
170 | 170 | |
|
171 | 171 | def _getEngineInfoLogFile(self): |
|
172 | 172 | # Store all logs inside the ipython directory |
|
173 |
ipdir = |
|
|
173 | ipdir = get_ipython_dir() | |
|
174 | 174 | pjoin = os.path.join |
|
175 | 175 | logdir_base = pjoin(ipdir,'log') |
|
176 | 176 | if not os.path.isdir(logdir_base): |
@@ -93,7 +93,7 b' from subprocess import Popen,call' | |||
|
93 | 93 | # IPython imports |
|
94 | 94 | #--------------------------------------------------------------------------- |
|
95 | 95 | from IPython.tools import utils |
|
96 |
from IPython. |
|
|
96 | from IPython.genutils import get_ipython_dir | |
|
97 | 97 | |
|
98 | 98 | #--------------------------------------------------------------------------- |
|
99 | 99 | # Normal code begins |
@@ -180,7 +180,7 b' def clusterLocal(opt,arg):' | |||
|
180 | 180 | """Start a cluster on the local machine.""" |
|
181 | 181 | |
|
182 | 182 | # Store all logs inside the ipython directory |
|
183 |
ipdir = |
|
|
183 | ipdir = get_ipython_dir() | |
|
184 | 184 | pjoin = os.path.join |
|
185 | 185 | |
|
186 | 186 | logfile = opt.logfile |
@@ -265,7 +265,7 b' def clusterRemote(opt,arg):' | |||
|
265 | 265 | sshx = clConfig.get('sshx',os.environ.get('IPYTHON_SSHX','sshx')) |
|
266 | 266 | |
|
267 | 267 | # Store all logs inside the ipython directory |
|
268 |
ipdir = |
|
|
268 | ipdir = get_ipython_dir() | |
|
269 | 269 | pjoin = os.path.join |
|
270 | 270 | |
|
271 | 271 | logfile = opt.logfile |
General Comments 0
You need to be logged in to leave comments.
Login now