From: Michael Tremer Date: Sat, 26 Feb 2011 08:23:30 +0000 (+0100) Subject: Drop user to a shell if running on an interactive console. X-Git-Tag: 0.9.3~113^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9c20259c1036c48d5b11bf2109df4dd8c9cce3e;p=pakfire.git Drop user to a shell if running on an interactive console. --- diff --git a/pakfire/__init__.py b/pakfire/__init__.py index 57630ce04..37cdc0a48 100644 --- a/pakfire/__init__.py +++ b/pakfire/__init__.py @@ -126,6 +126,10 @@ class Pakfire(object): continue b.copy_result(resultdir) + + except BuildError: + b.shell() + finally: b.cleanup() diff --git a/pakfire/builder.py b/pakfire/builder.py index 04b7af683..f62ace738 100644 --- a/pakfire/builder.py +++ b/pakfire/builder.py @@ -19,7 +19,7 @@ import transaction import util from constants import * -from errors import BuildRootLocked +from errors import BuildError, BuildRootLocked, Error class Builder(object): @@ -532,7 +532,11 @@ class Builder(object): def build(self): self.create_icecream_toolchain() - self.make("build") + try: + self.make("build") + + except Error: + raise BuildError, "The build command failed." for pkg in reversed(self.packages): packager = packages.Packager(self.pakfire, pkg, self) @@ -542,6 +546,10 @@ class Builder(object): self.pkg.dist(self) def shell(self, args=[]): + if not util.cli_is_interactive(): + logging.warning("Cannot run shell on non-interactive console.") + return + # XXX need to set CFLAGS here command = "/usr/sbin/chroot %s /usr/bin/chroot-shell %s" % \ (self.chrootPath(), " ".join(args)) diff --git a/pakfire/cli.py b/pakfire/cli.py index 40bd3e9b0..8d544a5f9 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -5,6 +5,7 @@ import sys import packages import repository +import util from pakfire import Pakfire @@ -20,7 +21,7 @@ def ask_user(question): If the software is running in a non-inteactive shell, no question is asked at all and the answer is always "yes". """ - if not sys.stdin.isatty() or not sys.stdout.isatty() or not sys.stderr.isatty(): + if not util.cli_is_interactive(): return True print _("%s [y/N]") % question, diff --git a/pakfire/util.py b/pakfire/util.py index 1e03ad9ee..ad40a38ac 100644 --- a/pakfire/util.py +++ b/pakfire/util.py @@ -22,6 +22,15 @@ _libc.unshare.argtypes = [ctypes.c_int,] _libc.unshare.restype = ctypes.c_int CLONE_NEWNS = 0x00020000 +def cli_is_interactive(): + """ + Say weather a shell is interactive or not. + """ + if sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty(): + return True + + return False + def rm(path, *args, **kargs): """ version of shutil.rmtree that ignores no-such-file-or-directory errors,