diff --git a/IPython/config/api.py b/IPython/config/api.py index a24a42c..f58d004 100644 --- a/IPython/config/api.py +++ b/IPython/config/api.py @@ -16,7 +16,7 @@ __docformat__ = "restructuredtext en" #------------------------------------------------------------------------------- import os -from IPython.config.cutils import get_home_dir, get_ipython_dir +from IPython.genutils import get_home_dir, get_ipython_dir from IPython.external.configobj import ConfigObj # Traitlets config imports diff --git a/IPython/config/cutils.py b/IPython/config/cutils.py index ad3cfc4..d72bcc9 100644 --- a/IPython/config/cutils.py +++ b/IPython/config/cutils.py @@ -22,71 +22,6 @@ import sys # Normal code begins #--------------------------------------------------------------------------- -class HomeDirError(Exception): - pass - -def get_home_dir(): - """Return the closest possible equivalent to a 'home' directory. - - We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. - - Currently only Posix and NT are implemented, a HomeDirError exception is - raised for all other OSes. """ - - isdir = os.path.isdir - env = os.environ - try: - homedir = env['HOME'] - if not isdir(homedir): - # in case a user stuck some string which does NOT resolve to a - # valid path, it's as good as if we hadn't foud it - raise KeyError - return homedir - except KeyError: - if os.name == 'posix': - raise HomeDirError,'undefined $HOME, IPython can not proceed.' - elif os.name == 'nt': - # For some strange reason, win9x returns 'nt' for os.name. - try: - homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH']) - if not isdir(homedir): - homedir = os.path.join(env['USERPROFILE']) - if not isdir(homedir): - raise HomeDirError - return homedir - except: - try: - # Use the registry to get the 'My Documents' folder. - import _winreg as wreg - key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, - "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") - homedir = wreg.QueryValueEx(key,'Personal')[0] - key.Close() - if not isdir(homedir): - e = ('Invalid "Personal" folder registry key ' - 'typically "My Documents".\n' - 'Value: %s\n' - 'This is not a valid directory on your system.' % - homedir) - raise HomeDirError(e) - return homedir - except HomeDirError: - raise - except: - return 'C:\\' - elif os.name == 'dos': - # Desperate, may do absurd things in classic MacOS. May work under DOS. - return 'C:\\' - else: - raise HomeDirError,'support for your operating system not implemented.' - -def get_ipython_dir(): - ipdir_def = '.ipython' - home_dir = get_home_dir() - ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', - os.path.join(home_dir,ipdir_def))) - return ipdir - def import_item(key): """ Import and return bar given the string foo.bar. diff --git a/IPython/genutils.py b/IPython/genutils.py index b19ae3e..b3e43b9 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -979,6 +979,22 @@ def get_home_dir(): else: raise HomeDirError,'support for your operating system not implemented.' + +def get_ipython_dir(): + """Get the IPython directory for this platform and user. + + This uses the logic in `get_home_dir` to find the home directory + and the adds either .ipython or _ipython to the end of the path. + """ + if os.name == 'posix': + ipdir_def = '.ipython' + else: + ipdir_def = '_ipython' + home_dir = get_home_dir() + ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', + os.path.join(home_dir,ipdir_def))) + return ipdir + #**************************************************************************** # strings and text diff --git a/IPython/kernel/config/__init__.py b/IPython/kernel/config/__init__.py index efc8d0a..25c0421 100644 --- a/IPython/kernel/config/__init__.py +++ b/IPython/kernel/config/__init__.py @@ -17,7 +17,7 @@ __docformat__ = "restructuredtext en" from IPython.external.configobj import ConfigObj from IPython.config.api import ConfigObjManager -from IPython.config.cutils import get_ipython_dir +from IPython.genutils import get_ipython_dir default_kernel_config = ConfigObj() diff --git a/IPython/kernel/controllerservice.py b/IPython/kernel/controllerservice.py index c341da6..3fe5f41 100644 --- a/IPython/kernel/controllerservice.py +++ b/IPython/kernel/controllerservice.py @@ -50,7 +50,7 @@ from IPython.kernel.engineservice import \ IEngineSerialized, \ IEngineQueued -from IPython.config import cutils +from IPython.genutils import get_ipython_dir from IPython.kernel import codeutil #------------------------------------------------------------------------------- @@ -170,7 +170,7 @@ class ControllerService(object, service.Service): def _getEngineInfoLogFile(self): # Store all logs inside the ipython directory - ipdir = cutils.get_ipython_dir() + ipdir = get_ipython_dir() pjoin = os.path.join logdir_base = pjoin(ipdir,'log') if not os.path.isdir(logdir_base): diff --git a/IPython/kernel/scripts/ipcluster.py b/IPython/kernel/scripts/ipcluster.py index afcd53d..b76a6db 100644 --- a/IPython/kernel/scripts/ipcluster.py +++ b/IPython/kernel/scripts/ipcluster.py @@ -93,7 +93,7 @@ from subprocess import Popen,call # IPython imports #--------------------------------------------------------------------------- from IPython.tools import utils -from IPython.config import cutils +from IPython.genutils import get_ipython_dir #--------------------------------------------------------------------------- # Normal code begins @@ -180,7 +180,7 @@ def clusterLocal(opt,arg): """Start a cluster on the local machine.""" # Store all logs inside the ipython directory - ipdir = cutils.get_ipython_dir() + ipdir = get_ipython_dir() pjoin = os.path.join logfile = opt.logfile @@ -265,7 +265,7 @@ def clusterRemote(opt,arg): sshx = clConfig.get('sshx',os.environ.get('IPYTHON_SSHX','sshx')) # Store all logs inside the ipython directory - ipdir = cutils.get_ipython_dir() + ipdir = get_ipython_dir() pjoin = os.path.join logfile = opt.logfile