From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BBEA2138247 for ; Wed, 22 Jan 2014 05:04:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B35C4E1161; Wed, 22 Jan 2014 05:04:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7D204E1167 for ; Wed, 22 Jan 2014 05:04:14 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7C91833F219 for ; Wed, 22 Jan 2014 05:04:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 3D2BA187B9 for ; Wed, 22 Jan 2014 05:04:11 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1388772141.0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60.dol-sen@gentoo> Subject: [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/clearbase.py catalyst/base/resume.py catalyst/fileops.py X-VCS-Directories: catalyst/ catalyst/base/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60 X-VCS-Branch: 3.0 Date: Wed, 22 Jan 2014 05:04:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 13a50549-16d8-4d00-ac0b-ce218b87c972 X-Archives-Hash: c2ff4d6eea0a2b8657061932f8772935 commit: 0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60 Author: Brian Dolbec gentoo org> AuthorDate: Mon Dec 30 21:19:28 2013 +0000 Commit: Brian Dolbec gmail com> CommitDate: Fri Jan 3 18:02:21 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=0e4b6cd8 Move some duplicate code to fileops, extend it's capability to not re-make the directory. --- catalyst/base/clearbase.py | 55 +++++++++++++--------------------------------- catalyst/base/resume.py | 26 +++++----------------- catalyst/fileops.py | 43 +++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py index 50cbc35..e38b1a8 100644 --- a/catalyst/base/clearbase.py +++ b/catalyst/base/clearbase.py @@ -5,7 +5,7 @@ from stat import ST_UID, ST_GID, ST_MODE from catalyst.support import cmd, countdown -from catalyst.fileops import ensure_dirs +from catalyst.fileops import ensure_dirs, clear_dir class ClearBase(object): """ @@ -16,68 +16,43 @@ class ClearBase(object): self.resume = None - def clear_autoresume(self): + def clear_autoresume(self, remove=False): """ Clean resume points since they are no longer needed """ if "autoresume" in self.settings["options"]: print "Removing AutoResume Points: ..." self.resume.clear_all() - def clear_chroot(self): + def clear_chroot(self, remove=False): print 'Clearing the chroot path ...' - self.clear_dir(self.settings["chroot_path"], 0755, True) + clear_dir(self.settings["chroot_path"], 0755, True, remove) - def clear_packages(self): + def clear_packages(self, remove=False): if "pkgcache" in self.settings["options"]: print "purging the pkgcache ..." - self.clear_dir(self.settings["pkgcache_path"]) + clear_dir(self.settings["pkgcache_path"], remove=remove) - def clear_kerncache(self): + def clear_kerncache(self, remove=False): if "kerncache" in self.settings["options"]: print "purging the kerncache ..." - self.clear_dir(self.settings["kerncache_path"]) + clear_dir(self.settings["kerncache_path"], remove=remove) - def purge(self): + def purge(self, remove=False): countdown(10,"Purging Caches ...") - if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")): + if any(k in self.settings["options"] for k in ("purge", + "purgeonly", "purgetmponly")): print "purge(); clearing autoresume ..." - self.clear_autoresume() + self.clear_autoresume(remove) print "purge(); clearing chroot ..." - self.clear_chroot() + self.clear_chroot(remove) if "purgetmponly" not in self.settings["options"]: print "purge(); clearing package cache ..." - self.clear_packages() + self.clear_packages(remove) print "purge(); clearing kerncache ..." - self.clear_kerncache() - - - def clear_dir(self, myemp, mode=0755, chg_flags=False): - '''Universal directory clearing function - ''' - if not myemp: - return False - if os.path.isdir(myemp): - print "Emptying directory" , myemp - """ - stat the dir, delete the dir, recreate the dir and set - the proper perms and ownership - """ - try: - mystat=os.stat(myemp) - """ There's no easy way to change flags recursively in python """ - if chg_flags and os.uname()[0] == "FreeBSD": - os.system("chflags -R noschg " + myemp) - shutil.rmtree(myemp) - ensure_dirs(myemp, mode=mode) - os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) - os.chmod(myemp,mystat[ST_MODE]) - except Exception as e: - print CatalystError("clear_dir(); Exeption: %s" % str(e)) - return False - return True + self.clear_kerncache(remove) diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py index e42c7dc..cf495fc 100644 --- a/catalyst/base/resume.py +++ b/catalyst/base/resume.py @@ -16,7 +16,7 @@ import shutil from stat import ST_UID, ST_GID, ST_MODE import traceback -from catalyst.fileops import ensure_dirs, pjoin, listdir_files +from catalyst.fileops import ensure_dirs, pjoin, listdir_files, clear_dir from catalyst.support import touch @@ -139,28 +139,12 @@ class AutoResume(object): return list(self._points) - def clear_all(self): + def clear_all(self, remove=False): '''Clear all active resume points @return boolean ''' - try: - print "Emptying directory---", self.basedir - """ - stat the dir, delete the dir, recreate the dir and set - the proper perms and ownership - """ - mystat=os.stat(self.basedir) - if os.uname()[0] == "FreeBSD": - cmd("chflags -R noschg " + self.basedir,\ - "Could not remove immutable flag for file "\ - + self.basedir) - shutil.rmtree(self.basedir) - ensure_dirs(self.basedir, 0755) - os.chown(self.basedir,mystat[ST_UID],mystat[ST_GID]) - os.chmod(self.basedir,mystat[ST_MODE]) + if clear_dir(self.basedir, mode=0755, chg_flags=True, remove=remove): self._points = {} - except Exception as e: - print AutoResumeError(str(e)) - return False - return True + return True + return False diff --git a/catalyst/fileops.py b/catalyst/fileops.py index e3a4ead..245c83e 100644 --- a/catalyst/fileops.py +++ b/catalyst/fileops.py @@ -10,7 +10,13 @@ ensuring directories exist,... imports snakeoils osutils functions for use throughout catalyst. ''' -from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs, normpath, +import os +import shutil +from stat import ST_UID, ST_GID, ST_MODE + +# NOTE: pjoin and listdir_files are imported here for export +# to other catalyst modules +from snakeoil.osutils import (ensure_dirs as snakeoil_ensure_dirs, pjoin, listdir_files) from catalyst.support import CatalystError @@ -42,3 +48,38 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0777, minimal=True, raise CatalystError( "Failed to create directory: %s" % path, print_traceback=True) return succeeded + + +def clear_dir(target, mode=0755, chg_flags=False, remove=False): + '''Universal directory clearing function + ''' + #print "fileops.clear_dir()" + if not target: + #print "fileops.clear_dir(), no target... returning" + return False + if os.path.isdir(target): + print "Emptying directory" , target + """ + stat the dir, delete the dir, recreate the dir and set + the proper perms and ownership + """ + try: + #print "fileops.clear_dir(), os.stat()" + mystat=os.stat(target) + """ There's no easy way to change flags recursively in python """ + if chg_flags and os.uname()[0] == "FreeBSD": + os.system("chflags -R noschg " + target) + #print "fileops.clear_dir(), shutil.rmtree()" + shutil.rmtree(target) + if not remove: + #print "fileops.clear_dir(), ensure_dirs()" + ensure_dirs(target, mode=mode) + os.chown(target, mystat[ST_UID], mystat[ST_GID]) + os.chmod(target, mystat[ST_MODE]) + except Exception as e: + print CatalystError("clear_dir(); Exeption: %s" % str(e)) + return False + else: + print "fileops.clear_dir(), %s is not a directory" % (target) + #print "fileops.clear_dir(), DONE, returning True" + return True