Index: pykota/trunk/bin/cupspykota
===================================================================
--- pykota/trunk/bin/cupspykota (revision 2580)
+++ pykota/trunk/bin/cupspykota (revision 2584)
@@ -988,4 +988,16 @@
         self.storage.beginTransaction()
         try :
+            onbackenderror = self.config.getPrinterOnBackendError(self.PrinterName)
+            if retcode :
+                # NB : We don't send any feedback to the end user. Only the admin
+                # has to know that the real CUPS backend failed.
+                self.Action = "PROBLEM"
+                self.exportReason()
+                if onbackenderror == "NOCHARGE" :
+                    self.JobSize = 0
+                    self.printInfo(_("Job size forced to 0 because the real CUPS backend failed. No accounting will be done."), "warn")
+                else :    
+                    self.printInfo(_("The real CUPS backend failed, but the job will be accounted for anyway."), "warn")
+                    
             # retrieve the job size    
             if self.Action == "DENY" :
@@ -994,10 +1006,13 @@
             else :    
                 self.UserPQuota.resetDenyBannerCounter()
-                self.JobSize = self.accounter.getJobSize(self.Printer)
-                self.sanitizeJobSize()
-                self.JobSize += self.BannerSize
+                if (self.Action != "PROBLEM") or (onbackenderror == "CHARGE") : 
+                    self.JobSize = self.accounter.getJobSize(self.Printer)
+                    self.sanitizeJobSize()
+                    self.JobSize += self.BannerSize
             self.printInfo(_("Job size : %i") % self.JobSize)
             
-            if (self.User.LimitBy == "nochange") or self.Printer.PassThrough :
+            if (self.Action == "PROBLEM") and (onbackenderror == "NOCHARGE") :
+                self.JobPrice = 0.0
+            elif (self.User.LimitBy == "nochange") or self.Printer.PassThrough :
                 # no need to update the quota for the current user on this printer
                 self.printInfo(_("User %s's quota on printer %s won't be modified") % (self.UserName, self.PrinterName))
@@ -1017,6 +1032,7 @@
             
             if hasattr(self, "BillingCode") and self.BillingCode and self.BillingCode.Exists :
-                self.BillingCode.consume(self.JobSize, self.JobPrice)
-                self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode)
+                if (self.Action != "PROBLEM") or (onbackenderror == "CHARGE") :
+                    self.BillingCode.consume(self.JobSize, self.JobPrice)
+                    self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode)
         except :    
             self.storage.rollbackTransaction()
@@ -1064,4 +1080,6 @@
         arguments[2] = self.UserName # in case it was overwritten by external script
         # TODO : do something about job-billing option, in case it was overwritten as well...
+        # TODO : do something about the job title : if we are printing a banner and the backend
+        # TODO : uses the job's title to name an output file (cups-pdf:// for example), we're stuck !
         
         self.logdebug("Starting original backend %s with args %s" % (originalbackend, " ".join(['"%s"' % a for a in arguments])))
@@ -1095,18 +1113,20 @@
         if os.WIFEXITED(status) :
             status = os.WEXITSTATUS(status)
+            message = "CUPS backend %s returned %d." % \
+                            (originalbackend, status)
             if status :
                 level = "error"
+                self.Reason = message
             else :    
                 level = "info"
-            self.printInfo("CUPS backend %s returned %d." % \
-                                     (originalbackend, status), level)
+            self.printInfo(message, level)
             return status
         elif not killed :
-            self.printInfo("CUPS backend %s died abnormally." % \
-                               originalbackend, "error")
+            self.Reason = "CUPS backend %s died abnormally." % originalbackend
+            self.printInfo(self.Reason, "error")
             return -1
         else :
-            self.printInfo("CUPS backend %s was killed." % \
-                               originalbackend, "warn")
+            self.Reason = "CUPS backend %s was killed." % originalbackend
+            self.printInfo(self.Reason, "warn")
             return 1
         
