Changeset 1584
- Timestamp:
- 07/01/04 21:56:43 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 11 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1562 r1584 24 24 # 25 25 # $Log$ 26 # Revision 1.66 2004/07/01 19:56:25 jalet 27 # Better dispatching of error messages 28 # 26 29 # Revision 1.65 2004/06/22 09:31:17 jalet 27 30 # Always send some debug info to CUPS' back channel stream (stderr) as … … 381 384 # we deny the job in this case (nothing to print anyway) 382 385 if not self.jobSizeBytes : 383 self. logger.log_message(_("Job contains no data. Printing is denied."), "warn")386 self.printInfo(_("Job contains no data. Printing is denied."), "warn") 384 387 action = "DENY" 385 388 … … 446 449 pollobj.unregister(fileno) 447 450 except KeyError : 448 self. logger.log_message(_("File number %s unregistered twice from polling object, ignored.") % fileno, "warn")451 self.printInfo(_("File number %s unregistered twice from polling object, ignored.") % fileno, "warn") 449 452 except : 450 453 self.logdebug("Error while unregistering file number %s from polling object." % fileno) … … 471 474 def sendBackChannelData(self, message) : 472 475 """Sends an informational message to CUPS via back channel stream (stderr).""" 473 sys.stderr.write("INFO: PyKota (PID %s) : %s\n" % (os.getpid(), message.strip())) 474 sys.stderr.flush() 476 self.printInfo("PyKota (PID %s) : %s" % (os.getpid(), message.strip())) 475 477 476 478 def handleData(self) : … … 651 653 retcode = os.WEXITSTATUS(status) 652 654 elif not killed : 653 self. logger.log_message(_("CUPS backend %s died abnormally.") % realbackend, "error")655 self.printInfo(_("CUPS backend %s died abnormally.") % realbackend, "error") 654 656 retcode = -1 655 657 else : -
pykota/trunk/bin/edpykota
r1546 r1584 24 24 # 25 25 # $Log$ 26 # Revision 1.76 2004/07/01 19:56:40 jalet 27 # Better dispatching of error messages 28 # 26 29 # Revision 1.75 2004/06/18 13:34:47 jalet 27 30 # Now all tracebacks include PyKota's version number … … 463 466 if (softlimit is not None) and (hardlimit is not None) and (hardlimit < softlimit) : 464 467 # error, exchange them 465 self. logger.log_message(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit))468 self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) 466 469 (softlimit, hardlimit) = (hardlimit, softlimit) 467 470 … … 541 544 protoquota = getattr(self.storage, "get%sPQuota" % suffix)(protoentry, printer) 542 545 if not protoquota.Exists : 543 self. logger.log_message(_("Prototype %s not found in Quota Storage for printer %s.") % (protoentry.Name, printer.Name))546 self.printInfo(_("Prototype %s not found in Quota Storage for printer %s.") % (protoentry.Name, printer.Name)) 544 547 continue # skip this printer 545 548 else : 546 549 (softlimit, hardlimit) = (protoquota.SoftLimit, protoquota.HardLimit) 547 550 else : 548 self. logger.log_message(_("Prototype object %s not found in Quota Storage.") % protoentry.Name)551 self.printInfo(_("Prototype object %s not found in Quota Storage.") % protoentry.Name) 549 552 550 553 if not options["noquota"] : … … 552 555 hardlimit = softlimit 553 556 if hardlimit is not None : 554 self. logger.log_message(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name))557 self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) 555 558 if softlimit is None : 556 559 softlimit = hardlimit 557 560 if softlimit is not None : 558 self. logger.log_message(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name))561 self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) 559 562 560 563 if options["add"] : … … 568 571 (name, email) = splitname 569 572 if email and (email.count('@') != 1) : 570 self. logger.log_message(_("Invalid email address %s") % email)573 self.printInfo(_("Invalid email address %s") % email) 571 574 email = "" 572 575 entry = getattr(self.storage, "get%s" % suffix)(name) … … 595 598 else : 596 599 if options["groups"] : 597 self. logger.log_message(_("Invalid group name %s") % entry.Name)600 self.printInfo(_("Invalid group name %s") % entry.Name) 598 601 else : 599 self. logger.log_message(_("Invalid user name %s") % entry.Name)602 self.printInfo(_("Invalid user name %s") % entry.Name) 600 603 elif options["delete"] : 601 604 todelete[entry.Name] = entry … … 607 610 608 611 if not entrypquota.Exists : 609 self. logger.log_message(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name))612 self.printInfo(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name)) 610 613 else : 611 614 if options["noquota"] or options["prototype"] or ((softlimit is not None) and (hardlimit is not None)) : … … 640 643 changed[entry.Name]["ingroups"].append(groupname) 641 644 else : 642 self. logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname)645 self.printInfo(_("Group %s not found in the PyKota Storage.") % groupname) 643 646 644 647 # This line disabled to prevent sending of unwanted email -
pykota/trunk/bin/pkhint
r1579 r1584 24 24 # 25 25 # $Log$ 26 # Revision 1.14 2004/07/01 19:56:40 jalet 27 # Better dispatching of error messages 28 # 26 29 # Revision 1.13 2004/06/29 07:55:18 jalet 27 30 # Doesn't output the warning message when --help or --version is asked … … 226 229 device = self.extractDeviceFromURI(deviceuri) 227 230 if devicetype is None : 228 s ys.stderr.write("Unknown device %s for printer %s\n"% (device, printer))231 self.printInfo(_("Unknown device %s for printer %s") % (device, printer)) 229 232 elif devicetype == "network" : 230 233 try : … … 245 248 else : 246 249 configuration.append((printer, "software(/usr/bin/pkpgcounter)")) 247 # elif devicetype == "direct" :248 # sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer))249 #elif devicetype == "serial" :250 # sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer))251 #else :252 # sys.stderr.write("Can't currently handle device %s for printer %s\n" % (device, printer))253 250 else : 254 251 configuration.append((printer, "software(/usr/bin/pkpgcounter)")) -
pykota/trunk/bin/pkprinters
r1582 r1584 24 24 # 25 25 # $Log$ 26 # Revision 1.13 2004/07/01 19:56:41 jalet 27 # Better dispatching of error messages 28 # 26 29 # Revision 1.12 2004/07/01 17:45:47 jalet 27 30 # Added code to handle the description field for printers … … 197 200 if printer.Exists : 198 201 if options["skipexisting"] : 199 self.print Error(_("Printer %s already exists, skipping.") % printer.Name)202 self.printInfo(_("Printer %s already exists, skipping.") % printer.Name) 200 203 else : 201 self.print Error(_("Printer %s already exists, will be modified.") % printer.Name)204 self.printInfo(_("Printer %s already exists, will be modified.") % printer.Name) 202 205 printers.append(printer) 203 206 else : -
pykota/trunk/bin/pykotme
r1546 r1584 24 24 # 25 25 # $Log$ 26 # Revision 1.13 2004/07/01 19:56:42 jalet 27 # Better dispatching of error messages 28 # 26 29 # Revision 1.12 2004/06/18 13:34:49 jalet 27 30 # Now all tracebacks include PyKota's version number … … 151 154 totalsize += parser.getJobSize() 152 155 except PDLAnalyzerError, msg : 153 sys.stderr.write("%s\n" % msg) 154 sys.stderr.flush() 156 self.printInfo(msg) 155 157 156 158 # get current user -
pykota/trunk/NEWS
r1582 r1584 22 22 PyKota NEWS : 23 23 24 - 1.19alpha29 : 25 26 - Correctly dispatches error messages depending on the 27 situation : tools which can be run interactively will 28 ALWAYS output their logs to stderr, excepted for 29 their DEBUG messages, for which the "logger:" 30 directive as set in pykota.conf will be honored. 31 Tools which can't be run interactively will ALWAYS 32 honor the "logger:" directive as set in pykota.conf 33 24 34 - 1.19alpha28 : 25 35 -
pykota/trunk/pykota/accounters/hardware.py
r1536 r1584 22 22 # 23 23 # $Log$ 24 # Revision 1.6 2004/07/01 19:56:42 jalet 25 # Better dispatching of error messages 26 # 24 27 # Revision 1.5 2004/06/10 22:42:06 jalet 25 28 # Better messages in logs … … 60 63 # can't get actual page counter, assume printer is off or warming up 61 64 # log the message anyway. 62 self.filter. logger.log_message("%s" % msg, "warn")65 self.filter.printInfo("%s" % msg, "warn") 63 66 counter = None 64 67 self.filter.logdebug("Printer's internal page counter value is : %s" % str(counter)) … … 106 109 if printer is None : 107 110 raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.printername) 108 self.filter. logger.log_message(_("Launching HARDWARE(%s)...") % commandline, "info")111 self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 109 112 error = 1 110 113 pagecounter = None … … 114 117 pagecounter = int(line.strip()) 115 118 except ValueError : 116 self.filter. logger.log_message(_("Incorrect answer : %s") % repr(line), "error")119 self.filter.printInfo(_("Incorrect answer : %s") % repr(line), "error") 117 120 except IOError : 118 121 # we were interrupted by a signal, certainely a SIGTERM … … 122 125 except : 123 126 pass # already killed ? 124 self.filter. logger.log_message(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid), "info")127 self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 125 128 else : 126 129 error = 0 -
pykota/trunk/pykota/accounters/software.py
r1536 r1584 22 22 # 23 23 # $Log$ 24 # Revision 1.6 2004/07/01 19:56:43 jalet 25 # Better dispatching of error messages 26 # 24 27 # Revision 1.5 2004/06/10 22:42:06 jalet 25 28 # Better messages in logs … … 49 52 def computeJobSize(self) : 50 53 """Feeds an external command with our datas to let it compute the job size, and return its value.""" 51 self.filter. logger.log_message(_("Launching SOFTWARE(%s)...") % self.arguments, "info")54 self.filter.printInfo(_("Launching SOFTWARE(%s)...") % self.arguments) 52 55 MEGABYTE = 1024*1024 53 56 self.filter.jobdatastream.seek(0) … … 62 65 except (IOError, OSError), msg : 63 66 msg = "%s : %s" % (self.arguments, msg) 64 self.filter. logger.log_message(_("Unable to compute job size with accounter %s") % msg)67 self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) 65 68 66 69 pagecount = 0 … … 68 71 pagecount = int(child.fromchild.readline().strip()) 69 72 except (AttributeError, ValueError) : 70 self.filter. logger.log_message(_("Unable to compute job size with accounter %s") % self.arguments)73 self.filter.printInfo(_("Unable to compute job size with accounter %s") % self.arguments) 71 74 except (IOError, OSError), msg : 72 75 msg = "%s : %s" % (self.arguments, msg) 73 self.filter. logger.log_message(_("Unable to compute job size with accounter %s") % msg)76 self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) 74 77 child.fromchild.close() 75 78 … … 77 80 retcode = child.wait() 78 81 except OSError, msg : 79 self.filter. logger.log_message(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg))82 self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg)) 80 83 else : 81 84 if os.WIFEXITED(retcode) : … … 83 86 else : 84 87 status = retcode 85 self.filter. logger.log_message(_("Software accounter %s exit code is %s") % (self.arguments, repr(retcode)))88 self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, repr(retcode))) 86 89 self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecount)) 87 90 return pagecount -
pykota/trunk/pykota/storages/ldapstorage.py
r1582 r1584 22 22 # 23 23 # $Log$ 24 # Revision 1.72 2004/07/01 19:56:43 jalet 25 # Better dispatching of error messages 26 # 24 27 # Revision 1.71 2004/07/01 17:45:49 jalet 25 28 # Added code to handle the description field for printers … … 805 808 message = _("Unable to find an existing objectClass %s entry with %s=%s to attach pykotaAccount objectClass") % (where, self.info["userrdn"], user.Name) 806 809 if action.lower() == "warn" : 807 self.tool. logger.log_message("%s. A new entry will be created instead." % message, "warn")810 self.tool.printInfo("%s. A new entry will be created instead." % message, "warn") 808 811 else : # 'fail' or incorrect setting 809 812 raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message … … 841 844 message = _("Unable to find an existing entry to attach pykotaGroup objectclass %s") % group.Name 842 845 if action.lower() == "warn" : 843 self.tool. logger.log_message("%s. A new entry will be created instead." % message, "warn")846 self.tool.printInfo("%s. A new entry will be created instead." % message, "warn") 844 847 else : # 'fail' or incorrect setting 845 848 raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message -
pykota/trunk/pykota/tool.py
r1582 r1584 22 22 # 23 23 # $Log$ 24 # Revision 1.110 2004/07/01 19:56:42 jalet 25 # Better dispatching of error messages 26 # 24 27 # Revision 1.109 2004/07/01 17:45:49 jalet 25 28 # Added code to handle the description field for printers … … 451 454 except (locale.Error, IOError) : 452 455 gettext.NullTranslations().install() 453 # sys.stderr.write("PyKota : Error while loading translations\n")454 456 455 457 # pykota specific stuff … … 479 481 self.logger.log_message(message, "debug") 480 482 481 def print Error(self, message) :483 def printInfo(self, message, level="info") : 482 484 """Sends a message to standard error.""" 483 sys.stderr.write("%s \n" % message)485 sys.stderr.write("%s: %s\n" % (level.upper(), message)) 484 486 sys.stderr.flush() 485 487 … … 577 579 self.display_usage_and_quit() 578 580 except getopt.error, msg : 579 sys.stderr.write("%s\n" % msg) 580 sys.stderr.flush() 581 self.printInfo(msg) 581 582 self.display_usage_and_quit() 582 583 return (parsed, args) … … 607 608 server = smtplib.SMTP(self.smtpserver) 608 609 except socket.error, msg : 609 self. logger.log_message(_("Impossible to connect to SMTP server : %s") % msg, "error")610 self.printInfo(_("Impossible to connect to SMTP server : %s") % msg, "error") 610 611 else : 611 612 try : … … 613 614 except smtplib.SMTPException, answer : 614 615 for (k, v) in answer.recipients.items() : 615 self. logger.log_message(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error")616 self.printInfo(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error") 616 617 server.quit() 617 618 … … 640 641 else : 641 642 action = "POLICY_DENY" 642 self. logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action))643 self.printInfo(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action)) 643 644 else : 644 645 pagecounter = int(userpquota.PageCounter or 0) … … 769 770 else : 770 771 action = "POLICY_DENY" 771 self. logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (user.Name, action, printer.Name))772 self.printInfo(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (user.Name, action, printer.Name)) 772 773 return action 773 774 else : … … 830 831 if action == "DENY" : 831 832 adminmessage = _("Print Quota exceeded for group %s on printer %s") % (group.Name, printer.Name) 832 self. logger.log_message(adminmessage)833 self.printInfo(adminmessage) 833 834 if mailto in [ "BOTH", "ADMIN" ] : 834 835 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) … … 841 842 elif action == "WARN" : 842 843 adminmessage = _("Print Quota low for group %s on printer %s") % (group.Name, printer.Name) 843 self. logger.log_message(adminmessage)844 self.printInfo(adminmessage) 844 845 if mailto in [ "BOTH", "ADMIN" ] : 845 846 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) … … 868 869 if action == "DENY" : 869 870 adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) 870 self. logger.log_message(adminmessage)871 self.printInfo(adminmessage) 871 872 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 872 873 message = self.config.getHardWarn(printer.Name) … … 879 880 elif action == "WARN" : 880 881 adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name) 881 self. logger.log_message(adminmessage)882 self.printInfo(adminmessage) 882 883 if mailto in [ "BOTH", "USER", "EXTERNAL" ] : 883 884 if user.LimitBy and (user.LimitBy.lower() == "balance") : … … 980 981 # computation is just an indication of what the 981 982 # job's size MAY be. 982 self. logger.log_message(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn")983 self.printInfo(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn") 983 984 return 0 984 985 else : … … 994 995 self.gotSigTerm = 1 995 996 os.environ["PYKOTASTATUS"] = "CANCELLED" 996 self. logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info")997 self.printInfo(_("SIGTERM received, job %s cancelled.") % self.jobid) 997 998 998 999 def exportJobInfo(self) : … … 1035 1036 self.logdebug("Executing post-hook [%s]" % posthook) 1036 1037 os.system(posthook) 1038 1039 def printInfo(self, message, level="info") : 1040 """Sends a message to standard error.""" 1041 self.logger.log_message("%s" % message, level) 1037 1042 1038 1043 def extractInfoFromCupsOrLprng(self) : … … 1098 1103 Kseen = 1 # we assume the user wants at least one copy... 1099 1104 if (rseen is None) and jseen and Pseen and nseen : 1100 self. logger.log_message(_("Printer hostname undefined, set to 'localhost'"), "warn")1105 self.printInfo(_("Printer hostname undefined, set to 'localhost'"), "warn") 1101 1106 rseen = "localhost" 1102 1107 if jseen and Pseen and nseen and rseen : 1103 1108 # job is always in stdin (None) 1104 1109 return ("LPRNG", rseen, Pseen, nseen, jseen, None, Kseen, None, None, None) 1105 self. logger.log_message(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn")1110 self.printInfo(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn") 1106 1111 return (None, None, None, None, None, None, None, None, None, None) # Unknown printing system 1107 1112 … … 1134 1139 commandline = self.formatCommandLine(args, user, printer) 1135 1140 if not printer.Exists : 1136 self. logger.log_message(_("Printer %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.printername, commandline, self.printername), "info")1141 self.printInfo(_("Printer %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.printername, commandline, self.printername)) 1137 1142 if not user.Exists : 1138 self. logger.log_message(_("User %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.username, commandline, self.printername), "info")1143 self.printInfo(_("User %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.username, commandline, self.printername)) 1139 1144 if not userpquota.Exists : 1140 self. logger.log_message(_("User %s doesn't have quota on printer %s in the PyKota system, applying external policy (%s) for printer %s") % (self.username, self.printername, commandline, self.printername), "info")1145 self.printInfo(_("User %s doesn't have quota on printer %s in the PyKota system, applying external policy (%s) for printer %s") % (self.username, self.printername, commandline, self.printername)) 1141 1146 if os.system(commandline) : 1142 self. logger.log_message(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, self.printername), "error")1147 self.printInfo(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, self.printername), "error") 1143 1148 policy = "EXTERNALERROR" 1144 1149 break 1145 1150 else : 1146 1151 if not printer.Exists : 1147 self. logger.log_message(_("Printer %s not registered in the PyKota system, applying default policy (%s)") % (self.printername, policy), "info")1152 self.printInfo(_("Printer %s not registered in the PyKota system, applying default policy (%s)") % (self.printername, policy)) 1148 1153 if not user.Exists : 1149 self. logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (self.username, policy, self.printername), "info")1154 self.printInfo(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (self.username, policy, self.printername)) 1150 1155 if not userpquota.Exists : 1151 self. logger.log_message(_("User %s doesn't have quota on printer %s in the PyKota system, applying default policy (%s)") % (self.username, self.printername, policy), "info")1156 self.printInfo(_("User %s doesn't have quota on printer %s in the PyKota system, applying default policy (%s)") % (self.username, self.printername, policy)) 1152 1157 break 1153 1158 if policy == "EXTERNAL" : 1154 1159 if not printer.Exists : 1155 self. logger.log_message(_("Printer %s still not registered in the PyKota system, job will be rejected") % self.printername, "info")1160 self.printInfo(_("Printer %s still not registered in the PyKota system, job will be rejected") % self.printername) 1156 1161 if not user.Exists : 1157 self. logger.log_message(_("User %s still not registered in the PyKota system, job will be rejected on printer %s") % (self.username, self.printername), "info")1162 self.printInfo(_("User %s still not registered in the PyKota system, job will be rejected on printer %s") % (self.username, self.printername)) 1158 1163 if not userpquota.Exists : 1159 self. logger.log_message(_("User %s still doesn't have quota on printer %s in the PyKota system, job will be rejected") % (self.username, self.printername), "info")1164 self.printInfo(_("User %s still doesn't have quota on printer %s in the PyKota system, job will be rejected") % (self.username, self.printername)) 1160 1165 return (policy, printer, user, userpquota) 1161 1166 … … 1177 1182 else : 1178 1183 if policy not in ("OK", "ALLOW") : 1179 self. logger.log_message(_("Invalid policy %s for printer %s") % (policy, self.printername))1184 self.printInfo(_("Invalid policy %s for printer %s") % (policy, self.printername)) 1180 1185 return self.removeJob() 1181 1186 else : -
pykota/trunk/pykota/version.py
r1575 r1584 22 22 # 23 23 24 __version__ = "1.19alpha2 8_unofficial"24 __version__ = "1.19alpha29_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""