switch CLI import to TEMP_DIR location; see new Utils functs

svn: r9409
This commit is contained in:
James G Sack
2007-11-26 05:41:04 +00:00
parent 97a720945f
commit 63a3f8479b
4 changed files with 47 additions and 49 deletions

View File

@ -51,6 +51,8 @@ import gen.lib
import Errors
from QuestionDialog import WarningDialog
from const import TEMP_DIR
import shutil
#-------------------------------------------------------------------------
#
@ -862,6 +864,25 @@ def get_new_filename(ext, folder='~/'):
ix = ix + 1
return os.path.expanduser(_NEW_NAME_PATTERN % (folder, os.path.sep, ix, ext))
def get_empty_tempdir(dirname):
""" Return path to TEMP_DIR/dirname, a guaranteed empty directory
makes intervening directories if required
fails if _file_ by that name already exists,
or for inadequate permissions to delete dir/files or create dir(s)
"""
dirpath = os.path.join(TEMP_DIR,dirname)
if os.path.isdir(dirpath):
shutil.rmtree(dirpath)
os.makedirs(dirpath)
return dirpath
def rm_tempdir(path):
"""Remove a tempdir created with get_empty_tempdir"""
if path.startswith(TEMP_DIR) and os.path.isdir(path):
shutil.rmtree(path)
def cast_to_bool(val):
if val == str(True):
return True