--- a/WebappConfig/ebuild.py 2006-12-30 19:38:36.000000000 +0100 +++ b/WebappConfig/ebuild.py 2009-11-22 18:12:55.000000000 +0100 @@ -24,6 +24,9 @@ import os.path, re, pwd, grp +from os import strerror +from subprocess import PIPE, Popen +from multiprocessing import Pipe from WebappConfig.debug import OUT import WebappConfig.wrapper as wrapper from WebappConfig.sandbox import Sandbox @@ -93,6 +96,21 @@ ''' + class HookedScriptError(Exception): + ''' Exception thrown when a hook script fails ''' + + def __init__(self, script, errno): + self.errno = errno + self.script= script + + def __str__(self): + cmd = "'" + self.script + "'" + if self.errno < 0: + return cmd + " was terminated by signal " + repr(-self.errno) + else: + return cmd + " terminated with error status " + repr(self.errno) + + def __init__(self, config): self.__root = wrapper.get_root() @@ -130,23 +148,32 @@ os.access(self.__hooksd + '/' + x, os.X_OK)): OUT.debug('Running hook script', 7) - - fi, fo, fe = os.popen3(self.__hooksd + '/' + x + ' ' - + type) - fi.close() - result_lines = fo.readlines() - error_lines = fe.readlines() - fo.close() - fe.close() - - if result_lines: - for i in result_lines: - OUT.notice(i) - - if error_lines: - for i in error_lines: - OUT.warn(i) - + cmd = self.__hooksd + '/' + x + ' '+ type + try: + p = Popen(cmd,shell=True,bufsize=1,stdin=None, + stdout=PIPE,stderr=PIPE,close_fds=True, + universal_newlines=True) + + (fo,fe) = p.communicate() + + if fo: + OUT.notice(fo) + + if fe and p.returncode != 0: + OUT.error(fe) + else: + OUT.warn(fe) + + if p.returncode: + raise Ebuild.HookedScriptError(cmd, p.returncode) + + except Exception, e: + sandbox.stop() + # remove OUT.die when WebAppConfig finally + # provides at least a catch-all exception handler + # OUT.error(e) + OUT.die(e) + raise sandbox.stop() def show_post(self, filename, ptype, server = None):