public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/, catalyst/base/
Date: Thu, 26 Feb 2015 22:18:38 +0000 (UTC)	[thread overview]
Message-ID: <1424981286.2f8312854d9fac7476f8f972660824941dc4c852.dolsen@gentoo> (raw)

commit:     2f8312854d9fac7476f8f972660824941dc4c852
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 21:19:28 2013 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> 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


WARNING: multiple messages have this Message-ID (diff)
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:pending commit in: catalyst/base/, catalyst/
Date: Thu, 26 Feb 2015 20:44:30 +0000 (UTC)	[thread overview]
Message-ID: <1424981286.2f8312854d9fac7476f8f972660824941dc4c852.dolsen@gentoo> (raw)
Message-ID: <20150226204430.DjjASeIMMMCYiQtWwbK_uV3gaupXZtij0lAVneDNw8k@z> (raw)

commit:     2f8312854d9fac7476f8f972660824941dc4c852
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 21:19:28 2013 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> 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


             reply	other threads:[~2015-02-26 22:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26 22:18 Brian Dolbec [this message]
2015-02-26 20:44 ` [gentoo-commits] proj/catalyst:pending commit in: catalyst/base/, catalyst/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2021-01-18 19:53 [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/, catalyst/base/ Matt Turner
2020-11-14 16:37 ` [gentoo-commits] proj/catalyst:master " Matt Turner
2020-12-19 19:56 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-11-14 16:37 ` [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-16  6:43 Matt Turner
2020-04-22  5:52 Matt Turner
2020-04-13 20:43 Matt Turner
2020-04-10 21:04 Matt Turner
2019-10-20  0:00 Matt Turner
2015-10-11 17:26 Mike Frysinger
2015-10-09  2:40 Mike Frysinger
2015-10-09  2:40 Mike Frysinger
2015-10-06 15:31 Mike Frysinger
2015-09-09 15:22 Brian Dolbec
2015-05-21 23:53 [gentoo-commits] proj/catalyst:pending " Brian Dolbec
2015-05-24  0:08 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec
2015-01-01  5:59 [gentoo-commits] proj/catalyst:pending commit in: catalyst/base/, catalyst/ Brian Dolbec
2015-02-26 20:12 ` [gentoo-commits] proj/catalyst:master commit in: catalyst/, catalyst/base/ Brian Dolbec
2015-01-01  5:59 [gentoo-commits] proj/catalyst:pending " Brian Dolbec
2015-02-26  4:12 ` [gentoo-commits] proj/catalyst:master " Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424981286.2f8312854d9fac7476f8f972660824941dc4c852.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox