From 91c7f2274a8aade7c9af2715270cdf4b84f25fd5 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 13 Sep 2009 13:12:59 -0500 Subject: [PATCH] Add catalyst.util.remove_dir() helper function --- ChangeLog | 4 ++++ modules/catalyst/util.py | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe8eb22f..14376f10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ # Distributed under the GPL v2 # $Id$ + 13 Sep 2009; Andrew Gaffney + modules/catalyst/util.py: + Add catalyst.util.remove_dir() helper function + 12 Sep 2009; Andrew Gaffney modules/catalyst/util.py: Remove unnecessary os.path import diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index f0dbdd26..122212fd 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -195,16 +195,25 @@ def addl_arg_parse(myspec,addlargs,requiredspec,validspec): if not x in myspec: raise CatalystError, "Required argument \""+x+"\" not specified." -def empty_dir(path): - mystat = os.stat(path) +def remove_dir(path): if os.uname()[0] == "FreeBSD": cmd("chflags -R noschg " + path, \ "Could not remove immutable flag for file " \ + path) - shutil.rmtree(path) - os.makedirs(path, 0755) - os.chown(path, mystat[stat.ST_UID], mystat[stat.ST_GID]) - os.chmod(path, mystat[stat.ST_MODE]) + try: + shutil.rmtree(path) + except: + raise CatalystError("Could not remove directory '%s'" % (path,)) + +def empty_dir(path): + try: + mystat = os.stat(path) + remove_dir(path) + os.makedirs(path, 0755) + os.chown(path, mystat[stat.ST_UID], mystat[stat.ST_GID]) + os.chmod(path, mystat[stat.ST_MODE]) + except: + raise CatalystError("Could not empty directory '%s'" % (path,)) # vim: ts=4 sw=4 sta noet sts=4 ai -- 2.26.2