Index: tea4cups/trunk/tea4cups
===================================================================
--- tea4cups/trunk/tea4cups (revision 597)
+++ tea4cups/trunk/tea4cups (revision 598)
@@ -527,32 +527,48 @@
         
     def runBranches(self) :         
-        """Launches each tee defined for the current print queue."""
+        """Launches each hook or tee defined for the current print queue."""
         exitcode = 0
         signal.signal(signal.SIGTERM, self.sigtermHandler)
-        prehooks = self.enumBranches(self.PrinterName, "prehook")
-        branches = self.enumBranches(self.PrinterName, "tee")
-        prehooks = self.enumBranches(self.PrinterName, "posthook")
-        if self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) :
-            self.logDebug("Serialized Tees")
-            if self.RealBackend :
+        serialize = self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1))
+        for branchtype in ["prehook", "tee", "posthook"] :
+            branches = self.enumBranches(self.PrinterName, branchtype)
+            status = self.runCommands(branchtype, branches, serialize)
+            if status :
+                exitcode = status
+        signal.signal(signal.SIGTERM, signal.SIG_IGN)
+        return exitcode
+        
+    def runCommands(self, btype, branches, serialize) :    
+        """Runs the commands for a particular branch type."""
+        exitcode = 0 
+        btype = btype.lower()
+        btypetitle = btype.title()
+        branchlist = branches.keys()    
+        branchlist.sort()
+        if serialize :
+            self.logDebug("Serialized %ss" % btypetitle)
+            if (btype == "tee") and self.RealBackend :
                 self.logDebug("Launching original backend %s for printer %s" % (self.RealBackend, self.PrinterName))
                 exitcode = self.runOriginalBackend()
-            for (branch, command) in branches.items() :
+            for branch in branchlist :
+                command = branches[branch]
                 if self.gotSigTerm :
                     break
                 self.logDebug("Launching %s : %s" % (branch, command))
                 retcode = os.system(command)
-                self.logDebug("Exit code for tee %s on printer %s is %s" % (branch, self.PrinterName, retcode))
+                self.logDebug("Exit code for %s %s on printer %s is %s" % (btype, branch, self.PrinterName, retcode))
                 if os.WIFEXITED(retcode) :
                     retcode = os.WEXITSTATUS(retcode)
                 if retcode :    
-                    self.logInfo("Tee %s on printer %s didn't exit successfully." % (branch, self.PrinterName), "error")
+                    self.logInfo("%s %s on printer %s didn't exit successfully." % (btypetitle, branch, self.PrinterName), "error")
                     exitcode = 1
         else :        
-            self.logDebug("Forked Tees")
+            self.logDebug("Forked %ss" % btypetitle)
             pids = {}
-            if self.RealBackend :
+            if (btype == "tee") and self.RealBackend :
                 branches["Original backend"] = None     # Fakes a tee to launch one more child
-            for (branch, command) in branches.items() :
+                branchlist = ["Original backend"] + branchlist
+            for branch in branchlist :
+                command = branches[branch]
                 if self.gotSigTerm :
                     break
@@ -574,11 +590,12 @@
             for (branch, pid) in pids.items() :
                 (childpid, retcode) = os.waitpid(pid, 0)
-                self.logDebug("Exit code for tee %s (PID %s) on printer %s is %s" % (branch, childpid, self.PrinterName, retcode))
+                self.logDebug("Exit code for %s %s (PID %s) on printer %s is %s" % (btype, branch, childpid, self.PrinterName, retcode))
                 if os.WIFEXITED(retcode) :
                     retcode = os.WEXITSTATUS(retcode)
                 if retcode :    
-                    self.logInfo("Tee %s (PID %s) on printer %s didn't exit successfully." % (branch, childpid, self.PrinterName), "error")
+                    self.logInfo("%s %s (PID %s) on printer %s didn't exit successfully." % (btypetitle, branch, childpid, self.PrinterName), "error")
                     exitcode = 1
-        signal.signal(signal.SIGTERM, signal.SIG_IGN)
+                if branch == "Original backend" :    
+                    os.environ["TEASTATUS"] = str(retcode)
         return exitcode
         
Index: tea4cups/trunk/tea4cups.conf
===================================================================
--- tea4cups/trunk/tea4cups.conf (revision 597)
+++ tea4cups/trunk/tea4cups.conf (revision 598)
@@ -31,4 +31,5 @@
 # The value defined in a print queue section takes precedence over the
 # value defined in the [global] section.
+# directory : /var/spool/tea4cups/
 directory : /var/spool/cups/
 
@@ -44,6 +45,11 @@
 # Should we serialize the launch of all tees : launch one tee after
 # the other to save some system resources.
-# Defaults to No if unset, meaning that all tees are launched in
+# Defaults to No if unset, meaning that all tees (or hooks) are launched in
 # parallel.
+#
+# NB : in any case, hooks or tees names are sorted alphabetically and 
+# are launched in this sort order (obviously when launched in parallel
+# this is unnoticeable).
+# 
 # Can be set either in the [global] section or any print queue section.
 # The value defined in a print queue section takes precedence over the
@@ -100,5 +106,5 @@
 # 
 # prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME
-# posthook_0 : echo "Your print job has been printed" | smbclient -M $TEAUSERNAME
+# posthook_0 : echo "Your print job has been printed with status $TEASTATUS" | smbclient -M $TEAUSERNAME
 
 
@@ -111,9 +117,15 @@
 # value takes precedence
 #tee_0 : cat $TEADATAFILE >~$TEAUSERNAME/savejobs/$TEAJOBID.prn
+
 # An empty value deletes a value defined in the [global] section
 # so this particular tee doesn't get executed.
 #tee_pdf : 
+
 # A reflector which produces 4 copies each time :
 #tee_4copies : lp -dotherprinter -n4 $CUPSDATAFILE 
+
 # A simple accounting mechanism 
 #tee_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log
+
+# An additionnal posthook :
+#posthook_dummy : echo "$TEAJOBID : $TEAMD5SUM" >>/tmp/jobmd5sums
Index: tea4cups/trunk/README
===================================================================
--- tea4cups/trunk/README (revision 592)
+++ tea4cups/trunk/README (revision 598)
@@ -33,4 +33,15 @@
 message, all of this by printing it a single time.
 
+Tea4CUPS provides three ways to launch commands :
+
+        - prehooks : these are guaranteed to be launched before the 
+                     print job is sent to the real printer.
+                     
+        - tees : these are launched at the same time the job is being             
+                 sent to the real printer.
+                 
+        - posthooks : these are guaranteed to be launched after the
+                      print job has been sent to the real printer.
+                 
 To help your own commands, Tea4CUPS makes available as part of the
 environment several variables which can be used as part of the
@@ -49,4 +60,6 @@
         TEAOPTIONS : Options of the print job.
         TEAINPUTFILE : Print job's data file or empty when job read from stdin.
+        TEASTATUS : Original CUPS backend's exit code : ONLY AVAILABLE FROM 
+                    post hooks, obviously.
         
 In the case you want to use both Tea4CUPS and PyKota, you MUST install 
