##// END OF EJS Templates
Make last-ditch attempt to find $HOME when environment is broken....
Fernando Perez -
Show More
@@ -936,10 +936,20 b' def get_home_dir():'
936 # in case a user stuck some string which does NOT resolve to a
936 # in case a user stuck some string which does NOT resolve to a
937 # valid path, it's as good as if we hadn't foud it
937 # valid path, it's as good as if we hadn't foud it
938 raise KeyError
938 raise KeyError
939 return homedir
939 return homedir.decode(sys.getfilesystemencoding())
940 except KeyError:
940 except KeyError:
941 if os.name == 'posix':
941 if os.name == 'posix':
942 raise HomeDirError,'undefined $HOME, IPython can not proceed.'
942 # Last-ditch attempt at finding a suitable $HOME, on systems where
943 # it may not be defined in the environment but the system shell
944 # still knows it - reported once as:
945 # https://github.com/ipython/ipython/issues/154
946 from subprocess import Popen, PIPE
947 homedir = Popen('echo $HOME', shell=True,
948 stdout=PIPE).communicate()[0].strip()
949 if homedir:
950 return homedir.decode(sys.getfilesystemencoding())
951 else:
952 raise HomeDirError('Undefined $HOME, IPython cannot proceed.')
943 elif os.name == 'nt':
953 elif os.name == 'nt':
944 # For some strange reason, win9x returns 'nt' for os.name.
954 # For some strange reason, win9x returns 'nt' for os.name.
945 try:
955 try:
@@ -948,7 +958,7 b' def get_home_dir():'
948 homedir = os.path.join(env['USERPROFILE'])
958 homedir = os.path.join(env['USERPROFILE'])
949 if not isdir(homedir):
959 if not isdir(homedir):
950 raise HomeDirError
960 raise HomeDirError
951 return homedir
961 return homedir.decode(sys.getfilesystemencoding())
952 except KeyError:
962 except KeyError:
953 try:
963 try:
954 # Use the registry to get the 'My Documents' folder.
964 # Use the registry to get the 'My Documents' folder.
@@ -964,7 +974,7 b' def get_home_dir():'
964 'This is not a valid directory on your system.' %
974 'This is not a valid directory on your system.' %
965 homedir)
975 homedir)
966 raise HomeDirError(e)
976 raise HomeDirError(e)
967 return homedir
977 return homedir.decode(sys.getfilesystemencoding())
968 except HomeDirError:
978 except HomeDirError:
969 raise
979 raise
970 except:
980 except:
General Comments 0
You need to be logged in to leave comments. Login now