##// END OF EJS Templates
fix to help users with invalid $HOME under win32.
fperez -
r6:396feddb
parent child Browse files
Show More
@@ -5,7 +5,7 b' General purpose utilities.'
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 638 2005-07-18 03:01:41Z fperez $"""
8 $Id: genutils.py 645 2005-07-19 01:59:26Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -702,15 +702,27 b' def get_home_dir():'
702 Currently only Posix and NT are implemented, a HomeDirError exception is
702 Currently only Posix and NT are implemented, a HomeDirError exception is
703 raised for all other OSes. """
703 raised for all other OSes. """
704
704
705 isdir = os.path.isdir
706 env = os.environ
705 try:
707 try:
706 return os.environ['HOME']
708 homedir = env['HOME']
709 if not isdir(homedir):
710 # in case a user stuck some string which does NOT resolve to a
711 # valid path, it's as good as if we hadn't foud it
712 raise KeyError
713 return homedir
707 except KeyError:
714 except KeyError:
708 if os.name == 'posix':
715 if os.name == 'posix':
709 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
716 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
710 elif os.name == 'nt':
717 elif os.name == 'nt':
711 # For some strange reason, win9x returns 'nt' for os.name.
718 # For some strange reason, win9x returns 'nt' for os.name.
712 try:
719 try:
713 return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH'])
720 homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH'])
721 if not isdir(homedir):
722 homedir = os.path.join(env['USERPROFILE'])
723 if not isdir(homedir):
724 raise HomeDirError
725 return homedir
714 except:
726 except:
715 try:
727 try:
716 # Use the registry to get the 'My Documents' folder.
728 # Use the registry to get the 'My Documents' folder.
@@ -1,3 +1,8 b''
1 2005-07-18 Fernando Perez <fperez@colorado.edu>
2
3 * IPython/genutils.py (get_home_dir): fix to help users with
4 invalid $HOME under win32.
5
1 2005-07-17 Fernando Perez <fperez@colorado.edu>
6 2005-07-17 Fernando Perez <fperez@colorado.edu>
2
7
3 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
8 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
General Comments 0
You need to be logged in to leave comments. Login now