diff options
author | Mike Bonnet <mikeb@redhat.com> | 2007-12-11 18:54:10 -0500 |
---|---|---|
committer | Michael E Brown <michael_e_brown@dell.com> | 2007-12-11 18:04:05 -0600 |
commit | bd5d08919539538c0bfead439fd8e3a33f3b01b3 (patch) | |
tree | 04872ede3c1709153a4df4e7abc1ea4b116cac55 | |
parent | c4edf71309f230955998fd2922d6045068b31eab (diff) | |
download | mock-bd5d08919539538c0bfead439fd8e3a33f3b01b3.tar.gz mock-bd5d08919539538c0bfead439fd8e3a33f3b01b3.tar.xz mock-bd5d08919539538c0bfead439fd8e3a33f3b01b3.zip |
- make "mock --chroot" non-interactive - set the exit code of "mock --chroot" to the exit code of the process run in the chroot - log the output of the process to root.log
Signed-off-by: Michael E Brown <michael_e_brown@dell.com>
-rw-r--r-- | docs/mock.1 | 4 | ||||
-rwxr-xr-x | docs/releasetests.sh | 2 | ||||
-rwxr-xr-x | py/mock.py | 13 | ||||
-rw-r--r-- | py/mock/exception.py | 5 | ||||
-rw-r--r-- | py/mock/util.py | 6 |
5 files changed, 23 insertions, 7 deletions
diff --git a/docs/mock.1 b/docs/mock.1 index 89c443a..624c026 100644 --- a/docs/mock.1 +++ b/docs/mock.1 @@ -101,7 +101,9 @@ Show version number and exit. .TP \fB\-\-rebuild\fR \- If no command is specified, rebuild is assumed. Rebuilds the specified SRPM(s). The buildroot is cleaned first, unless --no-clean is specified. .TP -\fB\-\-chroot\fR|\fB\-\-shell\fR \- run the specified command within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run. +\fB\-\-shell\fR \- run the specified command interactively within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run. +.TP +\fB\-\-chroot\fR \- run the specified command non-interactively within the chroot (which must already be initialized -- no 'clean' is performed). Command output will be sent to the log files. .TP \fB\-\-installdeps\fR \- find out deps for SRPM or RPM, and do a yum install to put them in the buildroot. Buildroot must already be initialized -- no 'clean' is performed .TP diff --git a/docs/releasetests.sh b/docs/releasetests.sh index ca5c0f7..2a98e1d 100755 --- a/docs/releasetests.sh +++ b/docs/releasetests.sh @@ -56,7 +56,7 @@ fi # Test that chroot return code is properly passed up # set +e -time $MOCKCMD --offline --chroot 'bash -c "exit 5"' +time $MOCKCMD --offline --chroot -- bash -c "exit 5" if [ $? -ne 5 ]; then echo "'mock --chroot' return code not properly passed back." exit 1 @@ -467,7 +467,7 @@ def main(ret): elif options.mode == 'clean': chroot.clean() - elif options.mode in ('chroot', 'shell'): + elif options.mode == 'shell': chroot.tryLockBuildRoot() try: chroot._mountall() @@ -480,6 +480,17 @@ def main(ret): finally: chroot._umountall() + elif options.mode == 'chroot': + if len(args) == 0: + log.critical("You must specify a command to run") + sys.exit(50) + else: + log.info("Running in chroot: %s" % args) + + chroot.tryLockBuildRoot() + chroot._resetLogging() + chroot.doChroot(args) + elif options.mode == 'installdeps': if len(args) == 0: log.critical("You must specify an SRPM file.") diff --git a/py/mock/exception.py b/py/mock/exception.py index d93fcf3..b6d6282 100644 --- a/py/mock/exception.py +++ b/py/mock/exception.py @@ -8,16 +8,19 @@ # python library imports #from exceptions import Exception +import os # our imports # classes class Error(Exception): "base class for our errors." - def __init__(self, msg): + def __init__(self, msg, status=None): Exception.__init__(self) self.msg = msg self.resultcode = 1 + if status is not None and os.WIFEXITED(status): + self.resultcode = os.WEXITSTATUS(status) def __str__(self): return self.msg diff --git a/py/mock/util.py b/py/mock/util.py index f2ddec2..bfaa03a 100644 --- a/py/mock/util.py +++ b/py/mock/util.py @@ -274,11 +274,11 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa signal.signal(signal.SIGALRM, oldhandler) # mask and return just return value, plus child output - if raiseExc and os.WEXITSTATUS(ret): + if raiseExc and ((os.WIFEXITED(ret) and os.WEXITSTATUS(ret)) or os.WIFSIGNALED(ret)): if returnOutput: - raise mock.exception.Error, "Command failed: \n # %s\n%s" % (command, output) + raise mock.exception.Error, ("Command failed: \n # %s\n%s" % (command, output), ret) else: - raise mock.exception.Error, "Command failed. See logs for output.\n # %s" % command + raise mock.exception.Error, ("Command failed. See logs for output.\n # %s" % (command,), ret) return output |