From: Andrew Gaffney Date: Sun, 13 Sep 2009 18:12:59 +0000 (-0500) Subject: Add catalyst.util.remove_dir() helper function X-Git-Tag: CATALYST-2.0.10~3^2~109 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=91c7f2274a8aade7c9af2715270cdf4b84f25fd5;p=catalyst.git Add catalyst.util.remove_dir() helper function --- 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