diff options
author | Paul B. Schroeder <paulbsch@haywired.net> | 2010-07-09 14:53:39 -0500 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2010-07-31 14:03:53 -0500 |
commit | 92861f8a2cbbb1eb4d898da41b9cd8c1366400d4 (patch) | |
tree | 109e4b5bd11f5fc12ca452f9f2897b18f3ebb57c | |
parent | 3e01be4926aa7633375779e7e9579dd055daf10d (diff) | |
download | mock-92861f8a2cbbb1eb4d898da41b9cd8c1366400d4.tar.gz mock-92861f8a2cbbb1eb4d898da41b9cd8c1366400d4.tar.xz mock-92861f8a2cbbb1eb4d898da41b9cd8c1366400d4.zip |
add the --scrub option for cleaning up cache (BZ# 450726)
Added the command line option:
--scrub=[all,chroot,cache,root-cache,c-cache,yum-cache]
which allows selective cleanup of the various cache's maintained
by mock (on on mock's behalf).
Also added logic to umountall() to umount in reverse order of mount.
Signed-off-by: Clark Williams <williams@redhat.com>
-rwxr-xr-x | py/mock.py | 17 | ||||
-rw-r--r-- | py/mock/backend.py | 56 |
2 files changed, 56 insertions, 17 deletions
@@ -20,7 +20,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ usage: - mock [options] {--init|--clean} + mock [options] {--init|--clean|--scrub=[all,chroot,cache,root-cache,c-cache,yum-cache]} mock [options] [--rebuild] /path/to/srpm(s) mock [options] {--shell|--chroot} <cmd> mock [options] --installdeps {SRPM|RPM} @@ -65,6 +65,10 @@ import mock.backend import mock.uid import mock.util +def scrub_callback(option, opt, value, parser): + parser.values.scrub.append(value) + parser.values.mode = "clean" + def command_parse(config_opts): """return options and args from parsing the command line""" parser = OptionParser(usage=__doc__, version=__VERSION__) @@ -86,6 +90,12 @@ def command_parse(config_opts): parser.add_option("--clean", action="store_const", const="clean", dest="mode", help="completely remove the specified chroot") + scrub_choices = ('chroot', 'cache', 'root-cache', 'c-cache', 'yum-cache', 'all') + scrub_metavar = "[all|chroot|cache|root-cache|c-cache|yum-cache]" + parser.add_option("--scrub", action="callback", type="choice", default=[], + choices=scrub_choices, metavar=scrub_metavar, + callback=scrub_callback, + help="completely remove the specified chroot or cache dir or all of the chroot and cache") parser.add_option("--init", action="store_const", const="init", dest="mode", help="initialize the chroot, do not build anything") parser.add_option("--installdeps", action="store_const", const="installdeps", @@ -564,7 +574,10 @@ def main(ret): chroot.init() elif options.mode == 'clean': - chroot.clean() + if len(options.scrub) == 0: + chroot.clean() + else: + chroot.scrub(options.scrub) elif options.mode == 'shell': chroot.tryLockBuildRoot() diff --git a/py/mock/backend.py b/py/mock/backend.py index ca06f59..f8cb412 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -135,6 +135,29 @@ class Root(object): self.chrootWasCleaned = True decorate(traceLog()) + def scrub(self, scrub_opts): + """clean out chroot and/or cache dirs with extreme prejudice :)""" + self.tryLockBuildRoot() + self.state("clean") + self._callHooks('clean') + for scrub in scrub_opts: + if scrub == 'all': + mock.util.rmtree(self.basedir) + self.chrootWasCleaned = True + mock.util.rmtree(self.cachedir) + elif scrub == 'chroot': + mock.util.rmtree(self.basedir) + self.chrootWasCleaned = True + elif scrub == 'cache': + mock.util.rmtree(self.cachedir) + elif scrub == 'c-cache': + mock.util.rmtree(os.path.join(self.cachedir, 'ccache')) + elif scrub == 'root-cache': + mock.util.rmtree(os.path.join(self.cachedir, 'root_cache')) + elif scrub == 'yum-cache': + mock.util.rmtree(os.path.join(self.cachedir, 'yum_cache')) + + decorate(traceLog()) def tryLockBuildRoot(self): self.state("lock buildroot") try: @@ -282,24 +305,24 @@ class Root(object): self._mountall() if self.chrootWasCleaned: self._yum(self.chroot_setup_cmd, returnOutput=1) - finally: - self._umountall() - # create user - self._makeBuildUser() + # create user + self._makeBuildUser() - # create rpmbuild dir - self._buildDirSetup() + # create rpmbuild dir + self._buildDirSetup() - # set up timezone to match host - localtimedir = self.makeChrootPath('etc') - localtimepath = self.makeChrootPath('etc', 'localtime') - if os.path.exists(localtimepath): - os.remove(localtimepath) - shutil.copy2('/etc/localtime', localtimedir) + # set up timezone to match host + localtimedir = self.makeChrootPath('etc') + localtimepath = self.makeChrootPath('etc', 'localtime') + if os.path.exists(localtimepath): + os.remove(localtimepath) + shutil.copy2('/etc/localtime', localtimedir) - # done with init - self._callHooks('postinit') + # done with init + self._callHooks('postinit') + finally: + self._umountall() decorate(traceLog()) def _setupDev(self): @@ -589,7 +612,10 @@ class Root(object): decorate(traceLog()) def _umountall(self): """umount all mounted chroot fs.""" - for cmd in self.umountCmds: + # Unwind mounts by umounting in the opposite order of the mounts + umountCmds = self.umountCmds + umountCmds.reverse() + for cmd in umountCmds: self.root_log.debug(cmd) mock.util.do(cmd, raiseExc=0, shell=True) |