From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/
Date: Wed, 22 Jan 2014 05:04:11 +0000 (UTC) [thread overview]
Message-ID: <1388772141.0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60.dol-sen@gentoo> (raw)
commit: 0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 30 21:19:28 2013 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> 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
next reply other threads:[~2014-01-22 5:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-22 5:04 Brian Dolbec [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-04-18 16:52 [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, catalyst/base/ Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-04-18 16:52 Brian Dolbec
2014-01-22 5:04 Brian Dolbec
2014-01-22 5:04 Brian Dolbec
2014-01-22 5:04 Brian Dolbec
2014-01-22 5:04 Brian Dolbec
2014-01-22 5:04 Brian Dolbec
2013-12-31 10:48 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=1388772141.0e4b6cd843b0d6a75909b8455ab76dffa6ee6e60.dol-sen@gentoo \
--to=brian.dolbec@gmail.com \
--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