Show
Ignore:
Timestamp:
11/15/05 22:47:29 (18 years ago)
Author:
jerome
Message:

Introduce the onbackenderror directive.
Make problems caused by real backend failures appear
as such in the printing history.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2580 r2584  
    988988        self.storage.beginTransaction() 
    989989        try : 
     990            onbackenderror = self.config.getPrinterOnBackendError(self.PrinterName) 
     991            if retcode : 
     992                # NB : We don't send any feedback to the end user. Only the admin 
     993                # has to know that the real CUPS backend failed. 
     994                self.Action = "PROBLEM" 
     995                self.exportReason() 
     996                if onbackenderror == "NOCHARGE" : 
     997                    self.JobSize = 0 
     998                    self.printInfo(_("Job size forced to 0 because the real CUPS backend failed. No accounting will be done."), "warn") 
     999                else :     
     1000                    self.printInfo(_("The real CUPS backend failed, but the job will be accounted for anyway."), "warn") 
     1001                     
    9901002            # retrieve the job size     
    9911003            if self.Action == "DENY" : 
     
    9941006            else :     
    9951007                self.UserPQuota.resetDenyBannerCounter() 
    996                 self.JobSize = self.accounter.getJobSize(self.Printer) 
    997                 self.sanitizeJobSize() 
    998                 self.JobSize += self.BannerSize 
     1008                if (self.Action != "PROBLEM") or (onbackenderror == "CHARGE") :  
     1009                    self.JobSize = self.accounter.getJobSize(self.Printer) 
     1010                    self.sanitizeJobSize() 
     1011                    self.JobSize += self.BannerSize 
    9991012            self.printInfo(_("Job size : %i") % self.JobSize) 
    10001013             
    1001             if (self.User.LimitBy == "nochange") or self.Printer.PassThrough : 
     1014            if (self.Action == "PROBLEM") and (onbackenderror == "NOCHARGE") : 
     1015                self.JobPrice = 0.0 
     1016            elif (self.User.LimitBy == "nochange") or self.Printer.PassThrough : 
    10021017                # no need to update the quota for the current user on this printer 
    10031018                self.printInfo(_("User %s's quota on printer %s won't be modified") % (self.UserName, self.PrinterName)) 
     
    10171032             
    10181033            if hasattr(self, "BillingCode") and self.BillingCode and self.BillingCode.Exists : 
    1019                 self.BillingCode.consume(self.JobSize, self.JobPrice) 
    1020                 self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode) 
     1034                if (self.Action != "PROBLEM") or (onbackenderror == "CHARGE") : 
     1035                    self.BillingCode.consume(self.JobSize, self.JobPrice) 
     1036                    self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode) 
    10211037        except :     
    10221038            self.storage.rollbackTransaction() 
     
    10641080        arguments[2] = self.UserName # in case it was overwritten by external script 
    10651081        # TODO : do something about job-billing option, in case it was overwritten as well... 
     1082        # TODO : do something about the job title : if we are printing a banner and the backend 
     1083        # TODO : uses the job's title to name an output file (cups-pdf:// for example), we're stuck ! 
    10661084         
    10671085        self.logdebug("Starting original backend %s with args %s" % (originalbackend, " ".join(['"%s"' % a for a in arguments]))) 
     
    10951113        if os.WIFEXITED(status) : 
    10961114            status = os.WEXITSTATUS(status) 
     1115            message = "CUPS backend %s returned %d." % \ 
     1116                            (originalbackend, status) 
    10971117            if status : 
    10981118                level = "error" 
     1119                self.Reason = message 
    10991120            else :     
    11001121                level = "info" 
    1101             self.printInfo("CUPS backend %s returned %d." % \ 
    1102                                      (originalbackend, status), level) 
     1122            self.printInfo(message, level) 
    11031123            return status 
    11041124        elif not killed : 
    1105             self.printInfo("CUPS backend %s died abnormally." % \ 
    1106                                originalbackend, "error") 
     1125            self.Reason = "CUPS backend %s died abnormally." % originalbackend 
     1126            self.printInfo(self.Reason, "error") 
    11071127            return -1 
    11081128        else : 
    1109             self.printInfo("CUPS backend %s was killed." % \ 
    1110                                originalbackend, "warn") 
     1129            self.Reason = "CUPS backend %s was killed." % originalbackend 
     1130            self.printInfo(self.Reason, "warn") 
    11111131            return 1 
    11121132