diff options
author | Clark Williams <williams@redhat.com> | 2007-12-13 17:35:42 -0600 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2007-12-13 17:35:42 -0600 |
commit | 6b2d14f9afb39a955331f4a52a597b122f585166 (patch) | |
tree | 42e0863a785ba46d8c38be540307d850c4375a57 /py | |
parent | 076a90491cfc27c895618d950c4de828489c189c (diff) | |
download | mock-6b2d14f9afb39a955331f4a52a597b122f585166.tar.gz mock-6b2d14f9afb39a955331f4a52a597b122f585166.tar.xz mock-6b2d14f9afb39a955331f4a52a597b122f585166.zip |
changed more uses of .rootdir to makeChrootPath(); updated man page for --copyin and --copyout; updated plugins to use makeChrootPath(); updated releasetests.sh so that daemon tests uses --copyin
Diffstat (limited to 'py')
-rwxr-xr-x | py/mock.py | 20 | ||||
-rw-r--r-- | py/mock/backend.py | 9 | ||||
-rw-r--r-- | py/mock/plugins/bind_mount.py | 6 | ||||
-rw-r--r-- | py/mock/plugins/ccache.py | 7 | ||||
-rw-r--r-- | py/mock/plugins/yum_cache.py | 7 |
5 files changed, 30 insertions, 19 deletions
@@ -25,6 +25,8 @@ mock [options] {--shell|--chroot} <cmd> mock [options] --installdeps {SRPM|RPM} mock [options] --install PACKAGE + mock [options] --copyin path [..path] destination + mock [options] --copyout path [..path] destination """ # library imports @@ -541,6 +543,7 @@ def main(ret): mock.util.orphansKill(chroot.rootdir) elif options.mode == 'copyin': chroot.tryLockBuildRoot() + chroot._resetLogging() uidManager.dropPrivsForever() if len(args) < 2: log.critical("Must have source and destinations for copyin") @@ -551,11 +554,15 @@ def main(ret): sys.exit(50) args = args[:-1] import shutil - for f in args: - print "copying %s to %s" % (f, dest) - shutil.copy(f, dest) + for src in args: + log.debug("copying %s to %s" % (src, dest)) + if os.path.isdir(src): + shutil.copytree(src, dest) + else: + shutil.copy(src, dest) elif options.mode == 'copyout': chroot.tryLockBuildRoot() + chroot._resetLogging() uidManager.dropPrivsForever() if len(args) < 2: log.critical("Must have source and destinations for copyout") @@ -568,8 +575,11 @@ def main(ret): import shutil for f in args: src = chroot.makeChrootPath(f) - print "copying %s to %s" % (src, dest) - shutil.copy(src, dest) + log.debug("copying %s to %s" % (src, dest)) + if os.path.isdir(src): + shutil.copytree(src, dest) + else: + shutil.copy(src, dest) if __name__ == '__main__': # fix for python 2.4 logging module bug: diff --git a/py/mock/backend.py b/py/mock/backend.py index ed283c9..c850118 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -143,6 +143,9 @@ class Root(object): decorate(traceLog()) def makeChrootPath(self, *args): + '''For safety reasons, self.rootdir should not be used directly. Instead + use this handy helper function anytime you want to reference a path in + relation to the chroot.''' tmp = self.rootdir + "/" + "/".join(args) return tmp.replace("//", "/") @@ -227,7 +230,7 @@ class Root(object): # files in /etc that need doing for key in self.chroot_file_contents: - p = self.makeChrootPath(*key.split('/')) + p = self.makeChrootPath(key) if not os.path.exists(p): # write file fo = open(p, 'w+') @@ -538,7 +541,7 @@ class Root(object): self.uidManager.becomeUser(self.chrootuid, self.chrootgid) try: # create dir structure - for subdir in ["%s" % self.makeChrootPath(self.builddir, s) for s in ('RPMS', 'SRPMS', 'SOURCES', 'SPECS', 'BUILD', 'originals')]: + for subdir in [self.makeChrootPath(self.builddir, s) for s in ('RPMS', 'SRPMS', 'SOURCES', 'SPECS', 'BUILD', 'originals')]: mock.util.mkdirIfAbsent(subdir) # change ownership so we can write to build home dir @@ -548,7 +551,7 @@ class Root(object): os.chmod(os.path.join(dirpath, path), 0755) # rpmmacros default - macrofile_out = '%s/.rpmmacros' % self.makeChrootPath(self.homedir) + macrofile_out = self.makeChrootPath(self.homedir, ".rpmmacros") rpmmacros = open(macrofile_out, 'w+') for key, value in self.macros.items(): rpmmacros.write( "%s %s\n" % (key, value) ) diff --git a/py/mock/plugins/bind_mount.py b/py/mock/plugins/bind_mount.py index 60f0f8b..df5e215 100644 --- a/py/mock/plugins/bind_mount.py +++ b/py/mock/plugins/bind_mount.py @@ -29,10 +29,10 @@ class BindMount(object): rootObj.bindMountObj = self rootObj.addHook("preinit", self._bindMountPreInitHook) for srcdir, destdir in self.bind_opts['dirs']: - rootObj.umountCmds.append('umount -n %s/%s' % (rootObj.rootdir, destdir)) - rootObj.mountCmds.append('mount -n --bind %s %s/%s' % (srcdir, rootObj.rootdir, destdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath(destdir)) + rootObj.mountCmds.append('mount -n --bind %s %s' % (srcdir, rootObj.makeChrootPath(destdir))) decorate(traceLog()) def _bindMountPreInitHook(self): for srcdir, destdir in self.bind_opts['dirs']: - mock.util.mkdirIfAbsent("%s/%s" % (self.rootObj.rootdir, destdir)) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath(destdir)) diff --git a/py/mock/plugins/ccache.py b/py/mock/plugins/ccache.py index 7974b1f..77a9130 100644 --- a/py/mock/plugins/ccache.py +++ b/py/mock/plugins/ccache.py @@ -25,13 +25,12 @@ class CCache(object): self.rootObj = rootObj self.ccache_opts = conf self.ccachePath = self.ccache_opts['dir'] % self.ccache_opts - self.rootdir = rootObj.rootdir rootObj.ccacheObj = self rootObj.preExistingDeps = rootObj.preExistingDeps + " ccache " rootObj.addHook("prebuild", self._ccacheBuildHook) rootObj.addHook("preinit", self._ccachePreInitHook) - rootObj.umountCmds.append('umount -n %s/tmp/ccache' % rootObj.rootdir) - rootObj.mountCmds.append('mount -n --bind %s %s/tmp/ccache' % (self.ccachePath, rootObj.rootdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath("/tmp/ccache")) + rootObj.mountCmds.append('mount -n --bind %s %s' % (self.ccachePath, rootObj.makeChrootPath("/tmp/ccache"))) # ============= # 'Private' API @@ -49,7 +48,7 @@ class CCache(object): # cache. decorate(traceLog()) def _ccachePreInitHook(self): - mock.util.mkdirIfAbsent(os.path.join(self.rootdir, 'tmp/ccache')) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath('/tmp/ccache')) mock.util.mkdirIfAbsent(self.ccachePath) os.environ['PATH'] = "/tmp/ccache:%s" % (os.environ['PATH']) os.environ['CCACHE_DIR'] = "/tmp/ccache" diff --git a/py/mock/plugins/yum_cache.py b/py/mock/plugins/yum_cache.py index 5b371bb..bcdf465 100644 --- a/py/mock/plugins/yum_cache.py +++ b/py/mock/plugins/yum_cache.py @@ -30,14 +30,13 @@ class YumCache(object): self.yum_cache_opts = conf self.yumSharedCachePath = self.yum_cache_opts['dir'] % self.yum_cache_opts self.state = rootObj.state - self.rootdir = rootObj.rootdir self.online = rootObj.online rootObj.yum_cacheObj = self rootObj.addHook("preyum", self._yumCachePreYumHook) rootObj.addHook("postyum", self._yumCachePostYumHook) rootObj.addHook("preinit", self._yumCachePreInitHook) - rootObj.umountCmds.append('umount -n %s/var/cache/yum' % rootObj.rootdir) - rootObj.mountCmds.append('mount -n --bind %s %s/var/cache/yum' % (self.yumSharedCachePath, rootObj.rootdir)) + rootObj.umountCmds.append('umount -n %s' % rootObj.makeChrootPath('/var/cache/yum')) + rootObj.mountCmds.append('mount -n --bind %s %s' % (self.yumSharedCachePath, rootObj.makeChrootPath('/var/cache/yum'))) mock.util.mkdirIfAbsent(self.yumSharedCachePath) self.yumCacheLock = open(os.path.join(self.yumSharedCachePath, "yumcache.lock"), "a+") @@ -65,7 +64,7 @@ class YumCache(object): decorate(traceLog()) def _yumCachePreInitHook(self): getLog().info("enabled yum cache") - mock.util.mkdirIfAbsent(os.path.join(self.rootdir, 'var/cache/yum')) + mock.util.mkdirIfAbsent(self.rootObj.makeChrootPath('/var/cache/yum')) # lock so others dont accidentally use yum cache while we operate on it. self._yumCachePreYumHook() |