Show More
@@ -16,7 +16,7 __docformat__ = "restructuredtext en" | |||||
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | import os |
|
18 | import os | |
19 |
from IPython. |
|
19 | from IPython.genutils import get_home_dir, get_ipython_dir | |
20 | from IPython.external.configobj import ConfigObj |
|
20 | from IPython.external.configobj import ConfigObj | |
21 |
|
21 | |||
22 | # Traitlets config imports |
|
22 | # Traitlets config imports |
@@ -22,71 +22,6 import sys | |||||
22 | # Normal code begins |
|
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 | def import_item(key): |
|
25 | def import_item(key): | |
91 | """ |
|
26 | """ | |
92 | Import and return bar given the string foo.bar. |
|
27 | Import and return bar given the string foo.bar. |
@@ -979,6 +979,22 def get_home_dir(): | |||||
979 | else: |
|
979 | else: | |
980 | raise HomeDirError,'support for your operating system not implemented.' |
|
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 | # strings and text |
|
999 | # strings and text | |
984 |
|
1000 |
@@ -17,7 +17,7 __docformat__ = "restructuredtext en" | |||||
17 |
|
17 | |||
18 | from IPython.external.configobj import ConfigObj |
|
18 | from IPython.external.configobj import ConfigObj | |
19 | from IPython.config.api import ConfigObjManager |
|
19 | from IPython.config.api import ConfigObjManager | |
20 |
from IPython. |
|
20 | from IPython.genutils import get_ipython_dir | |
21 |
|
21 | |||
22 | default_kernel_config = ConfigObj() |
|
22 | default_kernel_config = ConfigObj() | |
23 |
|
23 |
@@ -50,7 +50,7 from IPython.kernel.engineservice import \ | |||||
50 | IEngineSerialized, \ |
|
50 | IEngineSerialized, \ | |
51 | IEngineQueued |
|
51 | IEngineQueued | |
52 |
|
52 | |||
53 |
from IPython. |
|
53 | from IPython.genutils import get_ipython_dir | |
54 | from IPython.kernel import codeutil |
|
54 | from IPython.kernel import codeutil | |
55 |
|
55 | |||
56 | #------------------------------------------------------------------------------- |
|
56 | #------------------------------------------------------------------------------- | |
@@ -170,7 +170,7 class ControllerService(object, service.Service): | |||||
170 |
|
170 | |||
171 | def _getEngineInfoLogFile(self): |
|
171 | def _getEngineInfoLogFile(self): | |
172 | # Store all logs inside the ipython directory |
|
172 | # Store all logs inside the ipython directory | |
173 |
ipdir = |
|
173 | ipdir = get_ipython_dir() | |
174 | pjoin = os.path.join |
|
174 | pjoin = os.path.join | |
175 | logdir_base = pjoin(ipdir,'log') |
|
175 | logdir_base = pjoin(ipdir,'log') | |
176 | if not os.path.isdir(logdir_base): |
|
176 | if not os.path.isdir(logdir_base): |
@@ -93,7 +93,7 from subprocess import Popen,call | |||||
93 | # IPython imports |
|
93 | # IPython imports | |
94 | #--------------------------------------------------------------------------- |
|
94 | #--------------------------------------------------------------------------- | |
95 | from IPython.tools import utils |
|
95 | from IPython.tools import utils | |
96 |
from IPython. |
|
96 | from IPython.genutils import get_ipython_dir | |
97 |
|
97 | |||
98 | #--------------------------------------------------------------------------- |
|
98 | #--------------------------------------------------------------------------- | |
99 | # Normal code begins |
|
99 | # Normal code begins | |
@@ -180,7 +180,7 def clusterLocal(opt,arg): | |||||
180 | """Start a cluster on the local machine.""" |
|
180 | """Start a cluster on the local machine.""" | |
181 |
|
181 | |||
182 | # Store all logs inside the ipython directory |
|
182 | # Store all logs inside the ipython directory | |
183 |
ipdir = |
|
183 | ipdir = get_ipython_dir() | |
184 | pjoin = os.path.join |
|
184 | pjoin = os.path.join | |
185 |
|
185 | |||
186 | logfile = opt.logfile |
|
186 | logfile = opt.logfile | |
@@ -265,7 +265,7 def clusterRemote(opt,arg): | |||||
265 | sshx = clConfig.get('sshx',os.environ.get('IPYTHON_SSHX','sshx')) |
|
265 | sshx = clConfig.get('sshx',os.environ.get('IPYTHON_SSHX','sshx')) | |
266 |
|
266 | |||
267 | # Store all logs inside the ipython directory |
|
267 | # Store all logs inside the ipython directory | |
268 |
ipdir = |
|
268 | ipdir = get_ipython_dir() | |
269 | pjoin = os.path.join |
|
269 | pjoin = os.path.join | |
270 |
|
270 | |||
271 | logfile = opt.logfile |
|
271 | logfile = opt.logfile |
General Comments 0
You need to be logged in to leave comments.
Login now