summaryrefslogtreecommitdiffstats
path: root/py
diff options
context:
space:
mode:
authorPaul B. Schroeder <paulbsch@haywired.net>2010-07-09 14:53:39 -0500
committerClark Williams <williams@redhat.com>2010-07-27 13:02:10 -0500
commitb86c7586c64036f69a492d4fd0415a90dced78f6 (patch)
tree3776991468c9e83fd2d1b570bd76c0c8d3bed566 /py
parent4a42b4545064141d19457bf1b1f324d35ec73f34 (diff)
downloadmock-b86c7586c64036f69a492d4fd0415a90dced78f6.tar.gz
mock-b86c7586c64036f69a492d4fd0415a90dced78f6.tar.xz
mock-b86c7586c64036f69a492d4fd0415a90dced78f6.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>
Diffstat (limited to 'py')
-rwxr-xr-xpy/mock.py17
-rw-r--r--py/mock/backend.py56
2 files changed, 56 insertions, 17 deletions
diff --git a/py/mock.py b/py/mock.py
index 8f58031..6702ba6 100755
--- a/py/mock.py
+++ b/py/mock.py
@@ -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}
@@ -64,6 +64,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__)
@@ -85,6 +89,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",
@@ -576,7 +586,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)