Changeset 1584 for pykota/trunk/pykota
- Timestamp:
- 07/01/04 21:56:43 (20 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
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."""