Changeset 1192 for pykota/trunk
- Timestamp:
- 11/19/03 00:43:12 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/conf/pykota.conf.sample
r1188 r1192 185 185 # 186 186 # Who should we send an email to in case a quota is reached ? 187 # possible values are : DevNull, User, Admin, Both 187 # possible values are : DevNull, User, Admin, Both, External(some command) 188 188 # The Both value means that the User and the Admin will receive 189 189 # an email message. … … 192 192 # If both are defined, the printer option has priority. 193 193 # If the value is not set, then the default BOTH applies. 194 # 195 # For mailto: external(/usr/bin/mycommand) 196 # 197 # You can use : 198 # 199 # '%(action)s' will contain either WARN or DENY 200 # '%(username)s' will contain the user's name 201 # '%(printername)s' will contain the printer's name 202 # '%(email)s' will contain the user's email address 203 # '%(message)s' will contain the message if you want 204 # use it. 205 # 206 # On your command line, to pass arguments to your command. 207 # Example : 208 # 209 # mailto: external(/usr/bin/callpager %(username)s "Quota problem on %(printername)s") 210 # 194 211 mailto: both 195 212 -
pykota/trunk/NEWS
r1191 r1192 22 22 PyKota NEWS : 23 23 24 - 1.16alpha9 : 25 26 - mailto can be set to external(...) to warn users above 27 quota with any command of your choice (e.g. linpopup). 28 Several parameters are available, see sample configuration 29 file for details. 30 24 31 - 1.16alpha8 : 25 32 -
pykota/trunk/po/en/pykota.po
r1152 r1192 21 21 # 22 22 # $Log$ 23 # Revision 1.36 2003/11/18 23:43:11 jalet 24 # Mailto can be any external command now, as usual. 25 # 23 26 # Revision 1.35 2003/10/08 21:41:38 jalet 24 27 # External policies for printers works ! … … 443 446 msgstr "" 444 447 448 msgid "Invalid option mailto %s for printer %s" 449 msgstr "" 450 -
pykota/trunk/po/fr/pykota.po
r1152 r1192 21 21 # 22 22 # $Log$ 23 # Revision 1.35 2003/11/18 23:43:12 jalet 24 # Mailto can be any external command now, as usual. 25 # 23 26 # Revision 1.34 2003/10/08 21:41:38 jalet 24 27 # External policies for printers works ! … … 453 456 msgstr "L'action externe %s sur l'imprimante %s n'a pas pu ajouter l'utilisateur %s. Job rejet� 454 457 458 msgid "Invalid option mailto %s for printer %s" 459 msgstr "Option mailto %s invalide pour l'imprimante %s" 460 -
pykota/trunk/po/pykota.pot
r1152 r1192 21 21 # 22 22 # $Log$ 23 # Revision 1.36 2003/11/18 23:43:11 jalet 24 # Mailto can be any external command now, as usual. 25 # 23 26 # Revision 1.35 2003/10/08 21:41:38 jalet 24 27 # External policies for printers works ! … … 443 446 msgstr "" 444 447 448 msgid "Invalid option mailto %s for printer %s" 449 msgstr "" 450 -
pykota/trunk/pykota/config.py
r1152 r1192 22 22 # 23 23 # $Log$ 24 # Revision 1.40 2003/11/18 23:43:12 jalet 25 # Mailto can be any external command now, as usual. 26 # 24 27 # Revision 1.39 2003/10/08 21:41:38 jalet 25 28 # External policies for printers works ! … … 209 212 raise PyKotaConfigError, _("Option %s not found in section global of %s") % (option, self.filename) 210 213 211 def getPrinterOption(self, printer , option) :214 def getPrinterOption(self, printername, option) : 212 215 """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError.""" 213 216 globaloption = self.getGlobalOption(option, ignore=1) 214 217 try : 215 return self.config.get(printer , option, raw=1)218 return self.config.get(printername, option, raw=1) 216 219 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 217 220 if globaloption is not None : 218 221 return globaloption 219 222 else : 220 raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printer , self.filename)223 raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printername, self.filename) 221 224 222 225 def getStorageBackend(self) : … … 272 275 return logger 273 276 274 def getAccounterBackend(self, printer ) :277 def getAccounterBackend(self, printername) : 275 278 """Returns the accounter backend to use for a given printer. 276 279 … … 280 283 validaccounters = [ "querying", "stupid", "external" ] 281 284 try : 282 fullaccounter = self.getPrinterOption(printer , "accounter").strip()285 fullaccounter = self.getPrinterOption(printername, "accounter").strip() 283 286 except PyKotaConfigError : 284 287 fullaccounter = "querying" … … 287 290 (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] 288 291 except ValueError : 289 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printer )292 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printername) 290 293 if args.endswith(')') : 291 294 args = args[:-1] 292 295 if not args : 293 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printer )296 raise PyKotaConfigError, _("Invalid external accounter %s for printer %s") % (fullaccounter, printername) 294 297 return (accounter.lower(), args) 295 298 elif fullaccounter.lower() not in validaccounters : 296 raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printer , str(validaccounters))299 raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printername, str(validaccounters)) 297 300 else : 298 301 return (fullaccounter.lower(), None) 299 302 300 def getRequesterBackend(self, printer ) :303 def getRequesterBackend(self, printername) : 301 304 """Returns the requester backend to use for a given printer, with its arguments.""" 302 305 try : 303 fullrequester = self.getPrinterOption(printer , "requester")306 fullrequester = self.getPrinterOption(printername, "requester") 304 307 except PyKotaConfigError : 305 308 # No requester defined, maybe it is not needed if accounting method 306 309 # is not set to 'querying', but if we are called, then the accounting 307 310 # method really IS 'querying', and so there's a big problem. 308 raise PyKotaConfigError, _("Option requester for printer %s was not set") % printer 311 raise PyKotaConfigError, _("Option requester for printer %s was not set") % printername 309 312 else : 310 313 try : 311 314 (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] 312 315 except ValueError : 313 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer )316 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printername) 314 317 if args.endswith(')') : 315 318 args = args[:-1] 316 319 if not args : 317 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer )320 raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printername) 318 321 validrequesters = [ "snmp", "external" ] # TODO : add more requesters 319 322 requester = requester.lower() 320 323 if requester not in validrequesters : 321 raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer , str(validrequesters))324 raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printername, str(validrequesters)) 322 325 return (requester, args) 323 326 324 def getPrinterPolicy(self, printer ) :327 def getPrinterPolicy(self, printername) : 325 328 """Returns the default policy for the current printer.""" 326 329 validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ] 327 330 try : 328 fullpolicy = self.getPrinterOption(printer , "policy")331 fullpolicy = self.getPrinterOption(printername, "policy") 329 332 except PyKotaConfigError : 330 333 return ("DENY", None) … … 333 336 policy = [x.strip() for x in fullpolicy.split('(', 1)] 334 337 except ValueError : 335 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer )338 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 336 339 if len(policy) == 1 : 337 340 policy.append("") … … 341 344 policy = policy.upper() 342 345 if (policy == "EXTERNAL") and not args : 343 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer )346 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 344 347 if policy not in validpolicies : 345 raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printer , str(validpolicies))348 raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printername, str(validpolicies)) 346 349 return (policy, args) 347 350 … … 353 356 return "localhost" 354 357 355 def getAdminMail(self, printer ) :358 def getAdminMail(self, printername) : 356 359 """Returns the Email address of the Print Quota Administrator.""" 357 360 try : 358 return self.getPrinterOption(printer , "adminmail")361 return self.getPrinterOption(printername, "adminmail") 359 362 except PyKotaConfigError : 360 363 return "root@localhost" 361 364 362 def getAdmin(self, printer ) :365 def getAdmin(self, printername) : 363 366 """Returns the full name of the Print Quota Administrator.""" 364 367 try : 365 return self.getPrinterOption(printer , "admin")368 return self.getPrinterOption(printername, "admin") 366 369 except PyKotaConfigError : 367 370 return "root" 368 371 369 def getMailTo(self, printer ) :372 def getMailTo(self, printername) : 370 373 """Returns the recipient of email messages.""" 371 validmailtos = [ "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] 372 try : 373 mailto = self.getPrinterOption(printer, "mailto").upper() 374 except PyKotaConfigError : 375 mailto = "BOTH" 376 if mailto not in validmailtos : 377 raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printer, str(validmailtos)) 378 return mailto 379 380 def getGraceDelay(self, printer) : 374 validmailtos = [ "EXTERNAL", "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] 375 try : 376 fullmailto = self.getPrinterOption(printername, "mailto") 377 except PyKotaConfigError : 378 return ("BOTH", None) 379 else : 380 try : 381 mailto = [x.strip() for x in fullmailto.split('(', 1)] 382 except ValueError : 383 raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 384 if len(mailto) == 1 : 385 mailto.append("") 386 (mailto, args) = mailto 387 if args.endswith(')') : 388 args = args[:-1] 389 mailto = mailto.upper() 390 if (mailto == "EXTERNAL") and not args : 391 raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 392 if mailto not in validmailtos : 393 raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printername, str(validmailtos)) 394 return (mailto, args) 395 396 def getGraceDelay(self, printername) : 381 397 """Returns the grace delay in days.""" 382 398 try : 383 gd = self.getPrinterOption(printer , "gracedelay")399 gd = self.getPrinterOption(printername, "gracedelay") 384 400 except PyKotaConfigError : 385 401 gd = 7 … … 407 423 return _("Your Print Quota account balance is Low.\nSoon you'll not be allowed to print anymore.\nPlease contact the Print Quota Administrator to solve the problem.") 408 424 409 def getHardWarn(self, printer ) :425 def getHardWarn(self, printername) : 410 426 """Returns the hard limit error message.""" 411 427 try : 412 return self.getPrinterOption(printer , "hardwarn")413 except PyKotaConfigError : 414 return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printer 415 416 def getSoftWarn(self, printer ) :428 return self.getPrinterOption(printername, "hardwarn") 429 except PyKotaConfigError : 430 return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername 431 432 def getSoftWarn(self, printername) : 417 433 """Returns the soft limit error message.""" 418 434 try : 419 return self.getPrinterOption(printer , "softwarn")420 except PyKotaConfigError : 421 return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printer 435 return self.getPrinterOption(printername, "softwarn") 436 except PyKotaConfigError : 437 return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername 422 438 423 439 def getDebug(self) : -
pykota/trunk/pykota/tool.py
r1171 r1192 22 22 # 23 23 # $Log$ 24 # Revision 1.55 2003/11/18 23:43:12 jalet 25 # Mailto can be any external command now, as usual. 26 # 24 27 # Revision 1.54 2003/10/24 21:52:46 jalet 25 28 # Now can force language when coming from CGI script. … … 506 509 return action 507 510 511 def externalMailTo(self, cmd, action, user, printername, message) : 512 """Warns the user with an external command.""" 513 username = user.Name 514 email = user.Email or user.Name 515 if "@" not in email : 516 email = "%s@%s" % (email, self.smtpserver) 517 os.system(cmd % locals()) 518 508 519 def warnGroupPQuota(self, grouppquota) : 509 520 """Checks a group quota and send messages if quota is exceeded on current printer.""" … … 512 523 admin = self.config.getAdmin(printer.Name) 513 524 adminmail = self.config.getAdminMail(printer.Name) 514 mailto= self.config.getMailTo(printer.Name)525 (mailto, arguments) = self.config.getMailTo(printer.Name) 515 526 action = self.checkGroupPQuota(grouppquota) 516 527 if action.startswith("POLICY_") : … … 521 532 if mailto in [ "BOTH", "ADMIN" ] : 522 533 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) 523 if mailto in [ "BOTH", "USER" ] :534 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 524 535 for user in self.storage.getGroupMembers(group) : 525 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 536 if mailto != "EXTERNAL" : 537 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 538 else : 539 self.externalMailTo(arguments, action, user, printer.Name, message) 526 540 elif action == "WARN" : 527 541 adminmessage = _("Print Quota low for group %s on printer %s") % (group.Name, printer.Name) … … 533 547 else : 534 548 message = self.config.getSoftWarn(printer.Name) 535 if mailto in [ "BOTH", "USER" ] :549 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 536 550 for user in self.storage.getGroupMembers(group) : 537 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 551 if mailto != "EXTERNAL" : 552 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 553 else : 554 self.externalMailTo(arguments, action, user, printer.Name, message) 538 555 return action 539 556 … … 544 561 admin = self.config.getAdmin(printer.Name) 545 562 adminmail = self.config.getAdminMail(printer.Name) 546 mailto= self.config.getMailTo(printer.Name)563 (mailto, arguments) = self.config.getMailTo(printer.Name) 547 564 action = self.checkUserPQuota(userpquota) 548 565 if action.startswith("POLICY_") : … … 551 568 adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) 552 569 self.logger.log_message(adminmessage) 553 if mailto in [ "BOTH", "USER" ] : 554 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), self.config.getHardWarn(printer.Name)) 570 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 571 message = self.config.getHardWarn(printer.Name) 572 if mailto != "EXTERNAL" : 573 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Exceeded"), message) 574 else : 575 self.externalMailTo(arguments, action, user, printer.Name, message) 555 576 if mailto in [ "BOTH", "ADMIN" ] : 556 577 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) … … 558 579 adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name) 559 580 self.logger.log_message(adminmessage) 560 if mailto in [ "BOTH", "USER" ] :581 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 561 582 if user.LimitBy and (user.LimitBy.lower() == "balance") : 562 583 message = self.config.getPoorWarn() 563 584 else : 564 585 message = self.config.getSoftWarn(printer.Name) 565 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 586 if mailto != "EXTERNAL" : 587 self.sendMessageToUser(admin, adminmail, user, _("Print Quota Low"), message) 588 else : 589 self.externalMailTo(arguments, action, user, printer.Name, message) 566 590 if mailto in [ "BOTH", "ADMIN" ] : 567 591 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) -
pykota/trunk/pykota/version.py
r1189 r1192 22 22 # 23 23 24 __version__ = "1.16alpha 8_unofficial"24 __version__ = "1.16alpha9_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""