Show
Ignore:
Timestamp:
02/27/06 19:00:44 (18 years ago)
Author:
jerome
Message:

Added support for an extended syntax for the 'onbackenderror' directive.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2692 r2759  
    2727import sys 
    2828import os 
     29import time 
    2930import errno 
    3031import tempfile 
     
    10181019                self.Action = "PROBLEM" 
    10191020                self.exportReason() 
    1020                 if onbackenderror == "NOCHARGE" : 
     1021                if "NOCHARGE" in onbackenderror : 
    10211022                    self.JobSize = 0 
    10221023                    self.printInfo(_("Job size forced to 0 because the real CUPS backend failed. No accounting will be done."), "warn") 
     
    10331034            else :     
    10341035                self.UserPQuota.resetDenyBannerCounter() 
    1035                 if (self.Action != "PROBLEM") or (onbackenderror == "CHARGE") :  
     1036                if (self.Action != "PROBLEM") or ("CHARGE" in onbackenderror) :  
    10361037                    self.JobSize = self.accounter.getJobSize(self.Printer) 
    10371038                    self.sanitizeJobSize() 
     
    10391040            self.printInfo(_("Job size : %i") % self.JobSize) 
    10401041             
    1041             if ((self.Action == "PROBLEM") and (onbackenderror == "NOCHARGE")) or \ 
     1042            if ((self.Action == "PROBLEM") and ("NOCHARGE" in onbackenderror)) or \ 
    10421043                (self.Action in ("DENY", "CANCEL")) : 
    10431044                self.JobPrice = 0.0 
     
    10611062            if hasattr(self, "BillingCode") and self.BillingCode and self.BillingCode.Exists : 
    10621063                if (self.Action in ("ALLOW", "WARN")) or \ 
    1063                    ((self.Action == "PROBLEM") and (onbackenderror == "CHARGE")) : 
     1064                   ((self.Action == "PROBLEM") and ("CHARGE" in onbackenderror)) : 
    10641065                    self.BillingCode.consume(self.JobSize, self.JobPrice) 
    10651066                    self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode) 
     
    10871088        """Sends the job's datas to the real backend.""" 
    10881089        self.logdebug("Sending job's datas to real backend...") 
    1089         if self.InputFile is None : 
    1090             infile = open(self.DataFile, "rb") 
    1091         else :     
    1092             infile = None 
    1093         retcode = self.runOriginalBackend(infile) 
    1094         if self.InputFile is None : 
    1095             infile.close() 
     1090         
     1091        delay = 0 
     1092        number = 1 
     1093        for onb in self.config.getPrinterOnBackendError(self.PrinterName) : 
     1094            if onb.startswith("RETRY:") : 
     1095                try : 
     1096                    (number, delay) = [int(p) for p in onb[6:].split(":", 2)] 
     1097                    if (number < 0) or (delay < 0) : 
     1098                        raise ValueError 
     1099                except ValueError :     
     1100                    self.printInfo(_("Incorrect value for the 'onbackenderror' directive in section [%s]") % self.PrinterName, "error") 
     1101                    delay = 0 
     1102                    number = 1 
     1103                else :     
     1104                    break 
     1105        loopcnt = 1  
     1106        while True :             
     1107            if self.InputFile is None : 
     1108                infile = open(self.DataFile, "rb") 
     1109            else :     
     1110                infile = None 
     1111            retcode = self.runOriginalBackend(infile) 
     1112            if self.InputFile is None : 
     1113                infile.close() 
     1114            if not retcode : 
     1115                break 
     1116            else : 
     1117                if (not number) or (loopcnt < number) : 
     1118                    self.logdebug(_("The real backend produced an error, we will try again in %s seconds.") % delay) 
     1119                    time.sleep(delay) 
     1120                    loopcnt += 1 
     1121                else :     
     1122                    break 
     1123             
    10961124        self.logdebug("Job's datas sent to real backend.") 
    10971125        return retcode