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 33D15138AD6 for ; Thu, 26 Feb 2015 22:18:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AA599E0996; Thu, 26 Feb 2015 22:18:43 +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 A6B0BE0995 for ; Thu, 26 Feb 2015 22:18:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A06A5340C21 for ; Thu, 26 Feb 2015 22:18:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C11BF129F8 for ; Thu, 26 Feb 2015 22:18:38 +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: <1424981286.2f8312854d9fac7476f8f972660824941dc4c852.dolsen@gentoo> Subject: [gentoo-commits] proj/catalyst:master 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: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 2f8312854d9fac7476f8f972660824941dc4c852 X-VCS-Branch: master Date: Thu, 26 Feb 2015 22:18:38 +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: 4bfb9722-fe2f-4d9f-bf18-3adeb196de86 X-Archives-Hash: 8b913dcf8ed7778ce137154145cd2707 commit: 2f8312854d9fac7476f8f972660824941dc4c852 Author: Brian Dolbec gentoo org> AuthorDate: Mon Dec 30 21:19:28 2013 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Thu Feb 26 20:08:06 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=2f831285 Move some duplicate code to fileops, extend it's capability to not re-make the directory. --- catalyst/base/clearbase.py | 71 +++++++++++++++------------------------------- catalyst/base/resume.py | 26 ++++------------- catalyst/fileops.py | 43 +++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py index 0ebe299..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")): - print "clearing autoresume ..." - self.clear_autoresume() - - print "clearing chroot ..." - self.clear_chroot() - - if "PURGETMPONLY" not in self.settings: - print "clearing package cache ..." - self.clear_packages() - - print "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 + if any(k in self.settings["options"] for k in ("purge", + "purgeonly", "purgetmponly")): + print "purge(); clearing autoresume ..." + self.clear_autoresume(remove) + + print "purge(); clearing chroot ..." + self.clear_chroot(remove) + + if "purgetmponly" not in self.settings["options"]: + print "purge(); clearing package cache ..." + self.clear_packages(remove) + + print "purge(); clearing kerncache ..." + 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 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 23D8F138ADA for ; Thu, 26 Feb 2015 20:44:44 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 90764E0976; Thu, 26 Feb 2015 20:44:37 +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 AFAFAE0976 for ; Thu, 26 Feb 2015 20:44:36 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 89132340BCD for ; Thu, 26 Feb 2015 20:44:35 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A1ECF129E7 for ; Thu, 26 Feb 2015 20:44:30 +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: <1424981286.2f8312854d9fac7476f8f972660824941dc4c852.dolsen@gentoo> Subject: [gentoo-commits] proj/catalyst:pending commit in: catalyst/base/, catalyst/ 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: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 2f8312854d9fac7476f8f972660824941dc4c852 X-VCS-Branch: pending Date: Thu, 26 Feb 2015 20:44:30 +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: c8d820ca-81d6-4d6a-9f23-ffe5335bb56b X-Archives-Hash: c8f0761eeaa6cfa7fbc4f5728f7c8b4b Message-ID: <20150226204430.DjjASeIMMMCYiQtWwbK_uV3gaupXZtij0lAVneDNw8k@z> commit: 2f8312854d9fac7476f8f972660824941dc4c852 Author: Brian Dolbec gentoo org> AuthorDate: Mon Dec 30 21:19:28 2013 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Thu Feb 26 20:08:06 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=2f831285 Move some duplicate code to fileops, extend it's capability to not re-make the directory. --- catalyst/base/clearbase.py | 71 +++++++++++++++------------------------------- catalyst/base/resume.py | 26 ++++------------- catalyst/fileops.py | 43 +++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py index 0ebe299..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")): - print "clearing autoresume ..." - self.clear_autoresume() - - print "clearing chroot ..." - self.clear_chroot() - - if "PURGETMPONLY" not in self.settings: - print "clearing package cache ..." - self.clear_packages() - - print "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 + if any(k in self.settings["options"] for k in ("purge", + "purgeonly", "purgetmponly")): + print "purge(); clearing autoresume ..." + self.clear_autoresume(remove) + + print "purge(); clearing chroot ..." + self.clear_chroot(remove) + + if "purgetmponly" not in self.settings["options"]: + print "purge(); clearing package cache ..." + self.clear_packages(remove) + + print "purge(); clearing kerncache ..." + 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