From 86e4e8fd51b07ff7fb371342bf88a2ffa2fc784b Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 10 Feb 2015 17:39:03 -0500 Subject: [PATCH] * Bugfixes for tmpdir. --- file/tmpdir.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/file/tmpdir.py b/file/tmpdir.py index 7ccc97b..3e0dc14 100644 --- a/file/tmpdir.py +++ b/file/tmpdir.py @@ -32,7 +32,7 @@ import os.path import tempfile from warnings import warn -from wpylib import shell_utils as sh +from wpylib import shell_tools as sh _g = globals() _g.setdefault("TMPDIR", None) @@ -46,24 +46,26 @@ def tmpdir(): and return the created temporary directory name. For subsequent calls, the same temporary directory name is given again. """ + from wpylib.file.file_utils import is_writable import atexit global TMPDIR, TMPDIR_ROOTS if TMPDIR != None: return TMPDIR tmproot = None # FIXME: site-specific hooks probably need to be set somewhere for d in list(TMPDIR_ROOTS) + [ os.getenv("TMP"), os.getenv("TMPDIR"), "/tmp", "/var/tmp" ]: - if d != None and os.path.isdir(d) and : + if d != None and os.path.isdir(d) and is_writable(d): tmproot = d break if not tmproot: warn("Cannot find suitable temporary directory root, using current directory.", RuntimeWarning) tmproot = os.getcwd() - TMPDIR = tempfile.mkdtemp(prefix=("%s/chkgit-%d" % (tmproot, os.getpid()))) + TMPDIR = tempfile.mkdtemp(prefix=("%s/pytmp-%d" % (tmproot, os.getpid()))) def tmpdir_exitfunc(): global TMPDIR global TMPDIR_CLEANUP + print "TMPDIR_CLEANUP = ", TMPDIR_CLEANUP if TMPDIR != None and os.path.isdir(TMPDIR) and TMPDIR_CLEANUP: try: sh.rm("-rf", TMPDIR)