Changeset 2759

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.

Location:
pykota/trunk
Files:
5 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 
  • pykota/trunk/conf/pykota.conf.sample

    r2692 r2759  
    327327# When the real CUPS backend fail, should we modify the 
    328328# user's page counters and account balance or not ? 
     329# Also should we retry and if yes then how often and how many times ? 
    329330# If you trust your users, set it to "nocharge". 
    330331# If you think they found some mean to kill the real CUPS backend,  
    331332# then set it to "charge". 
     333# If your print queues get regularly disabled by CUPS when the printers 
     334# are switched off, you might want to set it to "retry:N:S" where 
     335# N is the number of times the operation should be retried, and S is 
     336# the delay in seconds during which PyKota will sleep before trying again. 
     337# If N is 0, PyKota will retry indefinitely each S seconds until the 
     338# backend succeeds, so you should use this with caution. If N is 0, 
     339# of course neither "charge" nor "nocharge" will be honored. 
     340# You can combine "charge" or "nocharge" with "retry:N:S" if you want, 
     341# by separating the values with a comma as shown in the examples below. 
    332342# If unset, the default value is "nocharge", meaning that users won't be 
    333343# charged whenever a CUPS backend fails. This is the OPPOSITE 
     
    335345# This value can be set either globally or on a per printer basis 
    336346# If both are defined, the printer option has priority. 
     347# onbackenderror : charge,retry:5:60 
     348# onbackenderror : retry:0:300 
     349# onbackenderror : retry:3:300,nocharge 
    337350# onbackenderror : charge 
    338351onbackenderror : nocharge 
  • pykota/trunk/NEWS

    r2755 r2759  
    2222PyKota NEWS : 
    2323        
     24    - 1.24alpha15 : 
     25     
     26        - Extended the functionnality of the 'onbackenderror' directive to 
     27          allow for configurable retries. 
     28           
    2429    - 1.24alpha14 : 
    2530     
  • pykota/trunk/pykota/config.py

    r2692 r2759  
    299299            action = self.getPrinterOption(printername, "onbackenderror") 
    300300        except PyKotaConfigError :     
    301             return "NOCHARGE" 
    302         else :     
    303             action = action.upper() 
    304             if action not in validactions : 
    305                 raise PyKotaConfigError, _("Option onbackenderror in section %s only supports values in %s") % (printername, str(validactions)) 
     301            return ["NOCHARGE"] 
     302        else :     
     303            action = action.upper().split(",") 
     304            error = False 
     305            for act in action : 
     306                if act not in validactions : 
     307                    if act.startswith("RETRY:") : 
     308                        try : 
     309                            (num, delay) = [int(p) for p in act[6:].split(":", 2)] 
     310                        except ValueError :     
     311                            error = True 
     312                    else :         
     313                        error = True 
     314            if error : 
     315                raise PyKotaConfigError, _("Option onbackenderror in section %s only supports values 'charge', 'nocharge', and 'retry:num:delay'") % printername 
    306316            return action   
    307317             
  • pykota/trunk/pykota/version.py

    r2755 r2759  
    2222# 
    2323 
    24 __version__ = "1.24alpha14_unofficial" 
     24__version__ = "1.24alpha15_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."