diff options
author | Michael E Brown <michael_e_brown@dell.com> | 2009-01-08 14:05:35 -0600 |
---|---|---|
committer | Michael E Brown <michael_e_brown@dell.com> | 2009-01-08 14:05:35 -0600 |
commit | 6ed8d50169bb513b419e1a6bcc5092cbf15b5497 (patch) | |
tree | 92337a53a6e2dca259b4a912b8d467771df42ec6 /py/mock/backend.py | |
parent | a9c9f083e197a9ffe83003230b635730af66e3ba (diff) | |
download | mock-6ed8d50169bb513b419e1a6bcc5092cbf15b5497.tar.gz mock-6ed8d50169bb513b419e1a6bcc5092cbf15b5497.tar.xz mock-6ed8d50169bb513b419e1a6bcc5092cbf15b5497.zip |
initial work to copy spec/sources and build srpm.
Diffstat (limited to 'py/mock/backend.py')
-rw-r--r-- | py/mock/backend.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/py/mock/backend.py b/py/mock/backend.py index 6cfd603..dccfdf9 100644 --- a/py/mock/backend.py +++ b/py/mock/backend.py @@ -444,6 +444,64 @@ class Root(object): # tell caching we are done building self._callHooks('postbuild') + + # + # UNPRIVLEGED: + # Everything in this function runs as the build user + # -> except hooks. :) + # + decorate(traceLog()) + def buildsrpm(self, spec, sources, timeout): + """build an srpm into binary rpms, capture log""" + + # tell caching we are building + self._callHooks('earlyprebuild') + + try: + self._mountall() + self.uidManager.becomeUser(self.chrootuid, self.chrootgid) + self.state("setup") + + # copy spec/sources + shutil.copy(spec, self.makeChrootPath(self.builddir, "SPECS")) + os.unlink(self.makeChrootPath(self.builddir, "SOURCES")) + shutil.copytree(sources, self.makeChrootPath(self.builddir, "SOURCES")) + + spec = self.makeChrootPath(self.builddir, "SPECS", os.path.basename(spec)) + chrootspec = spec.replace(self.makeChrootPath(), '') # get rid of rootdir prefix + + # Completely/Permanently drop privs while running the following: + os.environ["HOME"] = self.homedir + self.doChroot( + ["bash", "--login", "-c", 'rpmbuild -bs --target %s --nodeps %s' % (self.rpmbuild_arch, chrootspec)], + shell=False, + logger=self.build_log, timeout=timeout, + uid=self.chrootuid, + gid=self.chrootgid, + ) + + rebuiltSrpmFile = glob.glob("%s/%s/SRPMS/*.src.rpm" % (self.makeChrootPath(), self.builddir)) + if len(rebuiltSrpmFile) != 1: + raise mock.exception.PkgError, "Didnt find single rebuilt srpm." + + rebuiltSrpmFile = rebuiltSrpmFile[0] + + srpms = glob.glob(self.makeChrootPath(self.builddir) + '/SRPMS/*.rpm') + self.root_log.debug("Copying packages to result dir") + for item in srpms: + shutil.copy2(item, self.resultdir) + + finally: + self.uidManager.restorePrivs() + self._umountall() + + # tell caching we are done building + self._callHooks('postbuild') + + + + + # ============= # 'Private' API # ============= |