- Timestamp:
- 02/27/06 19:00:44 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2692 r2759 27 27 import sys 28 28 import os 29 import time 29 30 import errno 30 31 import tempfile … … 1018 1019 self.Action = "PROBLEM" 1019 1020 self.exportReason() 1020 if onbackenderror == "NOCHARGE":1021 if "NOCHARGE" in onbackenderror : 1021 1022 self.JobSize = 0 1022 1023 self.printInfo(_("Job size forced to 0 because the real CUPS backend failed. No accounting will be done."), "warn") … … 1033 1034 else : 1034 1035 self.UserPQuota.resetDenyBannerCounter() 1035 if (self.Action != "PROBLEM") or ( onbackenderror == "CHARGE") :1036 if (self.Action != "PROBLEM") or ("CHARGE" in onbackenderror) : 1036 1037 self.JobSize = self.accounter.getJobSize(self.Printer) 1037 1038 self.sanitizeJobSize() … … 1039 1040 self.printInfo(_("Job size : %i") % self.JobSize) 1040 1041 1041 if ((self.Action == "PROBLEM") and ( onbackenderror == "NOCHARGE")) or \1042 if ((self.Action == "PROBLEM") and ("NOCHARGE" in onbackenderror)) or \ 1042 1043 (self.Action in ("DENY", "CANCEL")) : 1043 1044 self.JobPrice = 0.0 … … 1061 1062 if hasattr(self, "BillingCode") and self.BillingCode and self.BillingCode.Exists : 1062 1063 if (self.Action in ("ALLOW", "WARN")) or \ 1063 ((self.Action == "PROBLEM") and ( onbackenderror == "CHARGE")) :1064 ((self.Action == "PROBLEM") and ("CHARGE" in onbackenderror)) : 1064 1065 self.BillingCode.consume(self.JobSize, self.JobPrice) 1065 1066 self.printInfo(_("Billing code %s was updated.") % self.BillingCode.BillingCode) … … 1087 1088 """Sends the job's datas to the real backend.""" 1088 1089 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 1096 1124 self.logdebug("Job's datas sent to real backend.") 1097 1125 return retcode -
pykota/trunk/conf/pykota.conf.sample
r2692 r2759 327 327 # When the real CUPS backend fail, should we modify the 328 328 # user's page counters and account balance or not ? 329 # Also should we retry and if yes then how often and how many times ? 329 330 # If you trust your users, set it to "nocharge". 330 331 # If you think they found some mean to kill the real CUPS backend, 331 332 # 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. 332 342 # If unset, the default value is "nocharge", meaning that users won't be 333 343 # charged whenever a CUPS backend fails. This is the OPPOSITE … … 335 345 # This value can be set either globally or on a per printer basis 336 346 # 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 337 350 # onbackenderror : charge 338 351 onbackenderror : nocharge -
pykota/trunk/NEWS
r2755 r2759 22 22 PyKota NEWS : 23 23 24 - 1.24alpha15 : 25 26 - Extended the functionnality of the 'onbackenderror' directive to 27 allow for configurable retries. 28 24 29 - 1.24alpha14 : 25 30 -
pykota/trunk/pykota/config.py
r2692 r2759 299 299 action = self.getPrinterOption(printername, "onbackenderror") 300 300 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 306 316 return action 307 317 -
pykota/trunk/pykota/version.py
r2755 r2759 22 22 # 23 23 24 __version__ = "1.24alpha1 4_unofficial"24 __version__ = "1.24alpha15_unofficial" 25 25 26 26 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS."