Permalink
Browse files

check for writable dirs, not just existence, in utils.path

replaces various calls to os.path.isdir and os.path.exists with _writable_dir.

closes gh-669
  • Loading branch information...
1 parent 1eea56b commit b1ec9902e1f27b09676bcf80ee403e55d9c15baa @minrk committed Aug 3, 2011
Showing with 9 additions and 4 deletions.
  1. +9 −4 IPython/utils/path.py
View
@@ -41,6 +41,10 @@ def _get_long_path_name(path):
"""Dummy no-op."""
return path
+def _writable_dir(path):
+ """Whether `path` is a directory, to which the user has write access."""
+ return os.path.isdir(path) and os.access(path, os.W_OK)
+
if sys.platform == 'win32':
def _get_long_path_name(path):
"""Get a long path name (expand ~) on Windows using ctypes.
@@ -166,7 +170,7 @@ def get_home_dir():
raised for all other OSes.
"""
- isdir = os.path.isdir
+ isdir = _writable_dir
env = os.environ
# first, check py2exe distribution root directory for _ipython.
@@ -272,7 +276,7 @@ def get_xdg_dir():
This is only for posix (Linux,Unix,OS X, etc) systems.
"""
- isdir = os.path.isdir
+ isdir = _writable_dir
env = os.environ
if os.name == 'posix':
@@ -294,7 +298,8 @@ def get_ipython_dir():
env = os.environ
pjoin = os.path.join
- exists = os.path.exists
+ isdir = _writable_dir
+
ipdir_def = '.ipython'
xdg_def = 'ipython'
@@ -312,7 +317,7 @@ def get_ipython_dir():
xdg_ipdir = pjoin(xdg_dir, xdg_def)
- if exists(xdg_ipdir) or not exists(home_ipdir):
+ if isdir(xdg_ipdir) or not isdir(home_ipdir):
ipdir = xdg_ipdir
if ipdir is None:

0 comments on commit b1ec990

Please sign in to comment.