Index: pykota/trunk/pykota/tool.py
===================================================================
--- pykota/trunk/pykota/tool.py (revision 1582)
+++ pykota/trunk/pykota/tool.py (revision 1584)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.110  2004/07/01 19:56:42  jalet
+# Better dispatching of error messages
+#
 # Revision 1.109  2004/07/01 17:45:49  jalet
 # Added code to handle the description field for printers
@@ -451,5 +454,4 @@
         except (locale.Error, IOError) :
             gettext.NullTranslations().install()
-            # sys.stderr.write("PyKota : Error while loading translations\n")
     
         # pykota specific stuff
@@ -479,7 +481,7 @@
             self.logger.log_message(message, "debug")
             
-    def printError(self, message) :        
+    def printInfo(self, message, level="info") :        
         """Sends a message to standard error."""
-        sys.stderr.write("%s\n" % message)
+        sys.stderr.write("%s: %s\n" % (level.upper(), message))
         sys.stderr.flush()
         
@@ -577,6 +579,5 @@
                 self.display_usage_and_quit()
         except getopt.error, msg :
-            sys.stderr.write("%s\n" % msg)
-            sys.stderr.flush()
+            self.printInfo(msg)
             self.display_usage_and_quit()
         return (parsed, args)
@@ -607,5 +608,5 @@
             server = smtplib.SMTP(self.smtpserver)
         except socket.error, msg :    
-            self.logger.log_message(_("Impossible to connect to SMTP server : %s") % msg, "error")
+            self.printInfo(_("Impossible to connect to SMTP server : %s") % msg, "error")
         else :
             try :
@@ -613,5 +614,5 @@
             except smtplib.SMTPException, answer :    
                 for (k, v) in answer.recipients.items() :
-                    self.logger.log_message(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error")
+                    self.printInfo(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error")
             server.quit()
         
@@ -640,5 +641,5 @@
             else :    
                 action = "POLICY_DENY"
-            self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action))
+            self.printInfo(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action))
         else :    
             pagecounter = int(userpquota.PageCounter or 0)
@@ -769,5 +770,5 @@
                 else :    
                     action = "POLICY_DENY"
-                self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (user.Name, action, printer.Name))
+                self.printInfo(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (user.Name, action, printer.Name))
                 return action        
             else :    
@@ -830,5 +831,5 @@
         if action == "DENY" :
             adminmessage = _("Print Quota exceeded for group %s on printer %s") % (group.Name, printer.Name)
-            self.logger.log_message(adminmessage)
+            self.printInfo(adminmessage)
             if mailto in [ "BOTH", "ADMIN" ] :
                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage)
@@ -841,5 +842,5 @@
         elif action == "WARN" :    
             adminmessage = _("Print Quota low for group %s on printer %s") % (group.Name, printer.Name)
-            self.logger.log_message(adminmessage)
+            self.printInfo(adminmessage)
             if mailto in [ "BOTH", "ADMIN" ] :
                 self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage)
@@ -868,5 +869,5 @@
         if action == "DENY" :
             adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name)
-            self.logger.log_message(adminmessage)
+            self.printInfo(adminmessage)
             if mailto in [ "BOTH", "USER", "EXTERNAL" ] :
                 message = self.config.getHardWarn(printer.Name)
@@ -879,5 +880,5 @@
         elif action == "WARN" :    
             adminmessage = _("Print Quota low for user %s on printer %s") % (user.Name, printer.Name)
-            self.logger.log_message(adminmessage)
+            self.printInfo(adminmessage)
             if mailto in [ "BOTH", "USER", "EXTERNAL" ] :
                 if user.LimitBy and (user.LimitBy.lower() == "balance") : 
@@ -980,5 +981,5 @@
             # computation is just an indication of what the
             # job's size MAY be.
-            self.logger.log_message(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn")
+            self.printInfo(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn")
             return 0
         else :    
@@ -994,5 +995,5 @@
         self.gotSigTerm = 1
         os.environ["PYKOTASTATUS"] = "CANCELLED"
-        self.logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info")
+        self.printInfo(_("SIGTERM received, job %s cancelled.") % self.jobid)
         
     def exportJobInfo(self) :    
@@ -1035,4 +1036,8 @@
             self.logdebug("Executing post-hook [%s]" % posthook)
             os.system(posthook)
+        
+    def printInfo(self, message, level="info") :        
+        """Sends a message to standard error."""
+        self.logger.log_message("%s" % message, level)
         
     def extractInfoFromCupsOrLprng(self) :    
@@ -1098,10 +1103,10 @@
                 Kseen = 1       # we assume the user wants at least one copy...
             if (rseen is None) and jseen and Pseen and nseen :    
-                self.logger.log_message(_("Printer hostname undefined, set to 'localhost'"), "warn")
+                self.printInfo(_("Printer hostname undefined, set to 'localhost'"), "warn")
                 rseen = "localhost"
             if jseen and Pseen and nseen and rseen :        
                 # job is always in stdin (None)
                 return ("LPRNG", rseen, Pseen, nseen, jseen, None, Kseen, None, None, None)
-        self.logger.log_message(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn")
+        self.printInfo(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn")
         return (None, None, None, None, None, None, None, None, None, None)   # Unknown printing system
         
@@ -1134,28 +1139,28 @@
                 commandline = self.formatCommandLine(args, user, printer)
                 if not printer.Exists :
-                    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")
+                    self.printInfo(_("Printer %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.printername, commandline, self.printername))
                 if not user.Exists :
-                    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")
+                    self.printInfo(_("User %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (self.username, commandline, self.printername))
                 if not userpquota.Exists :
-                    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")
+                    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))
                 if os.system(commandline) :
-                    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")
+                    self.printInfo(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, self.printername), "error")
                     policy = "EXTERNALERROR"
                     break
             else :        
                 if not printer.Exists :
-                    self.logger.log_message(_("Printer %s not registered in the PyKota system, applying default policy (%s)") % (self.printername, policy), "info")
+                    self.printInfo(_("Printer %s not registered in the PyKota system, applying default policy (%s)") % (self.printername, policy))
                 if not user.Exists :
-                    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")
+                    self.printInfo(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (self.username, policy, self.printername))
                 if not userpquota.Exists :
-                    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")
+                    self.printInfo(_("User %s doesn't have quota on printer %s in the PyKota system, applying default policy (%s)") % (self.username, self.printername, policy))
                 break
         if policy == "EXTERNAL" :    
             if not printer.Exists :
-                self.logger.log_message(_("Printer %s still not registered in the PyKota system, job will be rejected") % self.printername, "info")
+                self.printInfo(_("Printer %s still not registered in the PyKota system, job will be rejected") % self.printername)
             if not user.Exists :
-                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")
+                self.printInfo(_("User %s still not registered in the PyKota system, job will be rejected on printer %s") % (self.username, self.printername))
             if not userpquota.Exists :
-                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")
+                self.printInfo(_("User %s still doesn't have quota on printer %s in the PyKota system, job will be rejected") % (self.username, self.printername))
         return (policy, printer, user, userpquota)
         
@@ -1177,5 +1182,5 @@
         else :
             if policy not in ("OK", "ALLOW") :
-                self.logger.log_message(_("Invalid policy %s for printer %s") % (policy, self.printername))
+                self.printInfo(_("Invalid policy %s for printer %s") % (policy, self.printername))
                 return self.removeJob()
             else :
Index: pykota/trunk/pykota/accounters/software.py
===================================================================
--- pykota/trunk/pykota/accounters/software.py (revision 1536)
+++ pykota/trunk/pykota/accounters/software.py (revision 1584)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.6  2004/07/01 19:56:43  jalet
+# Better dispatching of error messages
+#
 # Revision 1.5  2004/06/10 22:42:06  jalet
 # Better messages in logs
@@ -49,5 +52,5 @@
     def computeJobSize(self) :    
         """Feeds an external command with our datas to let it compute the job size, and return its value."""
-        self.filter.logger.log_message(_("Launching SOFTWARE(%s)...") % self.arguments, "info")
+        self.filter.printInfo(_("Launching SOFTWARE(%s)...") % self.arguments)
         MEGABYTE = 1024*1024
         self.filter.jobdatastream.seek(0)
@@ -62,5 +65,5 @@
         except (IOError, OSError), msg :    
             msg = "%s : %s" % (self.arguments, msg) 
-            self.filter.logger.log_message(_("Unable to compute job size with accounter %s") % msg)
+            self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg)
         
         pagecount = 0
@@ -68,8 +71,8 @@
             pagecount = int(child.fromchild.readline().strip())
         except (AttributeError, ValueError) :
-            self.filter.logger.log_message(_("Unable to compute job size with accounter %s") % self.arguments)
+            self.filter.printInfo(_("Unable to compute job size with accounter %s") % self.arguments)
         except (IOError, OSError), msg :    
             msg = "%s : %s" % (self.arguments, msg) 
-            self.filter.logger.log_message(_("Unable to compute job size with accounter %s") % msg)
+            self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg)
         child.fromchild.close()
         
@@ -77,5 +80,5 @@
             retcode = child.wait()
         except OSError, msg :    
-            self.filter.logger.log_message(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg))
+            self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg))
         else :    
             if os.WIFEXITED(retcode) :
@@ -83,5 +86,5 @@
             else :    
                 status = retcode
-            self.filter.logger.log_message(_("Software accounter %s exit code is %s") % (self.arguments, repr(retcode)))
+            self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, repr(retcode)))
         self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecount))
         return pagecount    
Index: pykota/trunk/pykota/accounters/hardware.py
===================================================================
--- pykota/trunk/pykota/accounters/hardware.py (revision 1536)
+++ pykota/trunk/pykota/accounters/hardware.py (revision 1584)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.6  2004/07/01 19:56:42  jalet
+# Better dispatching of error messages
+#
 # Revision 1.5  2004/06/10 22:42:06  jalet
 # Better messages in logs
@@ -60,5 +63,5 @@
             # can't get actual page counter, assume printer is off or warming up
             # log the message anyway.
-            self.filter.logger.log_message("%s" % msg, "warn")
+            self.filter.printInfo("%s" % msg, "warn")
             counter = None
         self.filter.logdebug("Printer's internal page counter value is : %s" % str(counter))
@@ -106,5 +109,5 @@
         if printer is None :
             raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.printername)
-        self.filter.logger.log_message(_("Launching HARDWARE(%s)...") % commandline, "info")
+        self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline)
         error = 1
         pagecounter = None
@@ -114,5 +117,5 @@
             pagecounter = int(line.strip())
         except ValueError :    
-            self.filter.logger.log_message(_("Incorrect answer : %s") % repr(line), "error")
+            self.filter.printInfo(_("Incorrect answer : %s") % repr(line), "error")
         except IOError :    
             # we were interrupted by a signal, certainely a SIGTERM
@@ -122,5 +125,5 @@
             except :    
                 pass # already killed ?
-            self.filter.logger.log_message(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid), "info")
+            self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid))
         else :    
             error = 0
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1582)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1584)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.72  2004/07/01 19:56:43  jalet
+# Better dispatching of error messages
+#
 # Revision 1.71  2004/07/01 17:45:49  jalet
 # Added code to handle the description field for printers
@@ -805,5 +808,5 @@
                 message = _("Unable to find an existing objectClass %s entry with %s=%s to attach pykotaAccount objectClass") % (where, self.info["userrdn"], user.Name)
                 if action.lower() == "warn" :    
-                    self.tool.logger.log_message("%s. A new entry will be created instead." % message, "warn")
+                    self.tool.printInfo("%s. A new entry will be created instead." % message, "warn")
                 else : # 'fail' or incorrect setting
                     raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message
@@ -841,5 +844,5 @@
                 message = _("Unable to find an existing entry to attach pykotaGroup objectclass %s") % group.Name
                 if action.lower() == "warn" :    
-                    self.tool.logger.log_message("%s. A new entry will be created instead." % message, "warn")
+                    self.tool.printInfo("%s. A new entry will be created instead." % message, "warn")
                 else : # 'fail' or incorrect setting
                     raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1575)
+++ pykota/trunk/pykota/version.py (revision 1584)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.19alpha28_unofficial"
+__version__ = "1.19alpha29_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
