Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 1601)
+++ /pykota/trunk/pykota/tool.py (revision 1606)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.114  2004/07/20 22:19:45  jalet
+# Sanitized a bit + use of gettext
+#
 # Revision 1.113  2004/07/17 20:37:27  jalet
 # Missing file... Am I really stupid ?
@@ -940,7 +943,8 @@
         signal.signal(signal.SIGTERM, self.sigterm_handler)
         
-    def sendBackChannelData(self, message) :    
+    def sendBackChannelData(self, message, level="info") :    
         """Sends an informational message to CUPS via back channel stream (stderr)."""
-        self.printInfo("PyKota (PID %s) : %s" % (os.getpid(), message.strip()))
+        sys.stderr.write("%s: PyKota (PID %s) : %s\n" % (level.upper(), os.getpid(), message.strip()))
+        sys.stderr.flush()
         
     def openJobDataStream(self) :    
@@ -950,5 +954,5 @@
             # seekable and complexifies our task, so create
             # a temporary file and use it instead
-            self.sendBackChannelData("Duplicating data stream from stdin to temporary file")
+            self.logdebug("Duplicating data stream from stdin to temporary file")
             dummy = 0
             MEGABYTE = 1024*1024
@@ -961,8 +965,8 @@
                 self.jobSizeBytes += len(data)    
                 if not (dummy % 10) :
-                    self.sendBackChannelData("%s bytes read..." % self.jobSizeBytes)
+                    self.logdebug("%s bytes read..." % self.jobSizeBytes)
                 dummy += 1    
                 infile.write(data)
-            self.sendBackChannelData("%s bytes read total." % self.jobSizeBytes)
+            self.logdebug("%s bytes read total." % self.jobSizeBytes)
             infile.flush()    
             infile.seek(0)
@@ -970,5 +974,5 @@
         else :    
             # real file, just open it
-            self.sendBackChannelData("Opening data stream %s" % self.preserveinputfile)
+            self.logdebug("Opening data stream %s" % self.preserveinputfile)
             self.jobSizeBytes = os.stat(self.preserveinputfile)[6]
             return open(self.preserveinputfile, "rb")
@@ -976,5 +980,5 @@
     def closeJobDataStream(self) :    
         """Closes the file which contains the job's datas."""
-        self.sendBackChannelData("Closing data stream.")
+        self.logdebug("Closing data stream.")
         try :
             self.jobdatastream.close()
@@ -1100,6 +1104,6 @@
         else :    
             # Try to detect LPRng
-            # TODO : try to extract filename, job's title, and options if available
-            jseen = Pseen = nseen = rseen = Kseen = None
+            # TODO : try to extract filename, options if available
+            jseen = Jseen = Pseen = nseen = rseen = Kseen = None
             for arg in sys.argv :
                 if arg.startswith("-j") :
@@ -1111,4 +1115,6 @@
                 elif arg.startswith("-r") :    
                     rseen = arg[2:].strip()
+                elif arg.startswith("-J") :    
+                    Jseen = arg[2:].strip()
                 elif arg.startswith("-K") or arg.startswith("-#") :    
                     Kseen = int(arg[2:].strip())
@@ -1125,5 +1131,6 @@
                 inputfile = os.path.join(os.environ.get("SPOOL_DIR", "."), df_name)
             if jseen and Pseen and nseen and rseen :        
-                return ("LPRNG", rseen, Pseen, nseen, jseen, inputfile, Kseen, None, None, None)
+                options = os.environ.get("HF", "")
+                return ("LPRNG", rseen, Pseen, nseen, jseen, inputfile, Kseen, Jseen, options, None)
         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
Index: /pykota/trunk/bin/pkhint
===================================================================
--- /pykota/trunk/bin/pkhint (revision 1584)
+++ /pykota/trunk/bin/pkhint (revision 1606)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.15  2004/07/20 22:19:45  jalet
+# Sanitized a bit + use of gettext
+#
 # Revision 1.14  2004/07/01 19:56:40  jalet
 # Better dispatching of error messages
@@ -196,5 +199,5 @@
             (backend, destination) = device.split(":", 1) 
         except ValueError :    
-            raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device
+            raise PyKotaToolError, _("Invalid DeviceURI : %s") % device
         while destination.startswith("/") :
             destination = destination[1:]
@@ -220,5 +223,5 @@
         """Main work is done here."""
         sys.stderr.write("BEWARE : This tool doesn't support LPRng's printcap files yet.\n")
-        print "\nPlease wait while pkhint analyzes your printing system's configuration..."
+        print _("\nPlease wait while pkhint analyzes your printing system's configuration...")
         printers = self.extractPrintersInformation()
         devicestypes = self.extractDevices() # TODO : IT'S CUPS ONLY FOR NOW
@@ -254,8 +257,8 @@
             print "\nSorry, pkhint can't help you for now. Please configure PyKota manually."
         else :
-            print "\nPut the following lines into your /etc/pykota/pykota.conf file :\n"
-            print "# BEWARE : if software accounting is suggested, this doesn't mean"
-            print "# that hardware accounting wouldn't work, this only means that PyKota"
-            print "# wasn't able to autodetect which hardware accounting method to use."
+            print _("\nPut the following lines into your /etc/pykota/pykota.conf file :\n")
+            print _("# BEWARE : if software accounting is suggested, this doesn't mean")
+            print _("# that hardware accounting wouldn't work, this only means that PyKota")
+            print _("# wasn't able to autodetect which hardware accounting method to use.")
             for (printer, accounter) in configuration :
                 print "[%s]" % printer
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1600)
+++ /pykota/trunk/bin/cupspykota (revision 1606)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.68  2004/07/20 22:19:44  jalet
+# Sanitized a bit + use of gettext
+#
 # Revision 1.67  2004/07/16 12:22:45  jalet
 # LPRng support early version
@@ -348,5 +351,5 @@
             pagelog.close()        
             if matchingline is None :
-                self.logdebug("No matching line found in page_log")
+                self.logdebug("No matching line found in %s" % pagelogpath)
                 return # correct line not found, job-originating-hostname unknown
             else :    
@@ -376,10 +379,7 @@
                 self.softwareJobSize = self.precomputeJobSize()
                 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize)
-                self.sendBackChannelData("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice))
+                self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice))
             os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize)
             os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice)
-            
-            # checks the user's quota
-            action = self.warnUserPQuota(userpquota)
             
             # if no data to pass to real backend, probably a filter
@@ -389,4 +389,7 @@
                 self.printInfo(_("Job contains no data. Printing is denied."), "warn")
                 action = "DENY"
+            else :    
+                # checks the user's quota
+                action = self.warnUserPQuota(userpquota)
             
             # exports some new environment variables
@@ -396,5 +399,5 @@
             self.prehook(userpquota)
             
-            self.sendBackChannelData("Job accounting begins.")
+            self.printInfo(_("Job accounting begins."))
             self.accounter.beginJob(userpquota)
         else :    
@@ -417,21 +420,21 @@
             # stops accounting. 
             self.accounter.endJob(userpquota)
-            self.sendBackChannelData("Job accounting ends.")
+            self.printInfo(_("Job accounting ends."))
                 
             # retrieve the job size    
             if action == "DENY" :
                 jobsize = 0
-                self.sendBackChannelData("Job size forced to 0 because printing is denied.")
+                self.printInfo(_("Job size forced to 0 because printing is denied."))
             else :    
                 jobsize = self.accounter.getJobSize()
-            self.sendBackChannelData("Job size : %i" % jobsize)
+            self.printInfo(_("Job size : %i") % jobsize)
             
             # update the quota for the current user on this printer 
-            self.sendBackChannelData("Updating user %s's quota on printer %s" % (user.Name, printer.Name))
+            self.printInfo(_("Updating user %s's quota on printer %s") % (user.Name, printer.Name))
             jobprice = userpquota.increasePagesUsage(jobsize)
             
             # adds the current job to history    
             printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options, clienthost, self.jobSizeBytes)
-            self.sendBackChannelData("Job added to history.")
+            self.printInfo(_("Job added to history."))
             
             # exports some new environment variables
@@ -481,5 +484,5 @@
         
         # And launch it
-        self.sendBackChannelData("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])])))
+        self.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])])))
         subprocess = PyKotaPopen4([realbackend] + sys.argv[1:], bufsize=0, arg0=os.environ["DEVICE_URI"])
         
@@ -511,9 +514,9 @@
             # job's data is in a file, no need to pass the data
             # to the real backend
-            self.sendBackChannelData("Job's data is in %s" % self.preserveinputfile)
+            self.logdebug("Job's data is in %s" % self.preserveinputfile)
             infno = None
             endinput = 1
         
-        self.sendBackChannelData("Entering streams polling loop...")
+        self.logdebug("Entering streams polling loop...")
         MEGABYTE = 1024*1024
         killed = 0
@@ -531,5 +534,5 @@
                     self.logdebug("Error while sending signal to pid %s : %s" % (subprocess.pid, msg))
                 else :    
-                    self.sendBackChannelData(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid))
+                    self.printInfo(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid))
                     killed = 1
             
@@ -541,5 +544,5 @@
                 availablefds = []
             if not availablefds :
-                self.sendBackChannelData("Nothing to do, sleeping a bit...")
+                self.logdebug("Nothing to do, sleeping a bit...")
                 time.sleep(0.01) # give some time to the system
             else :
@@ -558,10 +561,10 @@
                                         indata = ""
                                 else :        
-                                    self.sendBackChannelData("No data to send to real backend yet, sleeping a bit...")
+                                    self.logdebug("No data to send to real backend yet, sleeping a bit...")
                                     time.sleep(0.01)
                                     
                                 if endinput :    
                                     self.unregisterFileNo(pollster, tocfno)        
-                                    self.sendBackChannelData("Closing real backend's stdin.")
+                                    self.logdebug("Closing real backend's stdin.")
                                     os.close(tocfno)
                                     inputclosed = 1
@@ -595,5 +598,5 @@
                                     if not data :    # If yes, then no more input data
                                         self.unregisterFileNo(pollster, infno)
-                                        self.sendBackChannelData("Input data ends.")
+                                        self.logdebug("Input data ends.")
                                         endinput = 1 # this happens with real files.
                                     else :    
@@ -601,5 +604,5 @@
                                 elif fd == fromcfno :
                                     if not data :
-                                        self.sendBackChannelData("No back channel data to read from real backend yet, sleeping a bit...")
+                                        self.logdebug("No back channel data to read from real backend yet, sleeping a bit...")
                                         time.sleep(0.01)
                                     else :
@@ -616,9 +619,9 @@
                                 # Here we are in the case where the input file is stdin.
                                 # which has no more data to be read.
-                                self.sendBackChannelData("Input data ends.")
+                                self.logdebug("Input data ends.")
                                 endinput = 1
                             elif fd == fromcfno :    
                                 # We are no more interested in this file descriptor        
-                                self.sendBackChannelData("Closing real backend's stdout+stderr.")
+                                self.logdebug("Closing real backend's stdout+stderr.")
                                 os.close(fromcfno)
                                 endoutput = 1
@@ -628,5 +631,5 @@
                                 
                         if mask & select.POLLNVAL :        
-                            self.sendBackChannelData("File %s was closed. Unregistering from polling object." % fd)
+                            self.logdebug("File %s was closed. Unregistering from polling object." % fd)
                             self.unregisterFileNo(pollster, fd)
                     except IOError, msg :            
@@ -635,8 +638,8 @@
         # We must close the real backend's input stream
         if killed and not inputclosed :
-            self.sendBackChannelData("Forcing close of real backend's stdin.")
+            self.logdebug("Forcing close of real backend's stdin.")
             os.close(tocfno)
         
-        self.sendBackChannelData("Exiting streams polling loop...")
+        self.logdebug("Exiting streams polling loop...")
         
         # Check exit code of original CUPS backend.    
@@ -644,5 +647,5 @@
             # we exited the loop before the real backend exited
             # now we have to wait for it to finish and get its status
-            self.sendBackChannelData("Waiting for real backend to exit...")
+            self.logdebug("Waiting for real backend to exit...")
             try :
                 status = subprocess.wait()
@@ -652,5 +655,5 @@
             retcode = os.WEXITSTATUS(status)
         elif not killed :    
-            self.printInfo(_("CUPS backend %s died abnormally.") % realbackend, "error")
+            self.sendBackChannelData(_("CUPS backend %s died abnormally.") % realbackend, "error")
             retcode = -1
         else :    
Index: /pykota/trunk/bin/pykosd
===================================================================
--- /pykota/trunk/bin/pykosd (revision 1605)
+++ /pykota/trunk/bin/pykosd (revision 1606)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.5  2004/07/20 22:19:45  jalet
+# Sanitized a bit + use of gettext
+#
 # Revision 1.4  2004/07/19 22:37:13  jalet
 # pykosd is now a very good tool
@@ -101,15 +104,15 @@
             duration = int(options["duration"])
         except :    
-            raise PyKotaToolError, "Invalid duration option %s" % str(options["duration"])
+            raise PyKotaToolError, _("Invalid duration option %s") % str(options["duration"])
             
         try :    
             loop = int(options["loop"])
         except :    
-            raise PyKotaToolError, "Invalid loop option %s" % str(options["loop"])
+            raise PyKotaToolError, _("Invalid loop option %s") % str(options["loop"])
             
         try :    
             sleep = float(options["sleep"])
         except :    
-            raise PyKotaToolError, "Invalid sleep option %s" % str(options["sleep"])
+            raise PyKotaToolError, _("Invalid sleep option %s") % str(options["sleep"])
             
         uid = os.geteuid()
@@ -118,5 +121,5 @@
             user = cmd.storage.getUserFromBackend(uname)        # don't use cache
             if not user.Exists :
-                raise PyKotaToolError, "User %s doesn't exist in PyKota's database." % uname
+                raise PyKotaToolError, _("User %s doesn't exist in PyKota's database") % uname
             if user.LimitBy == "quota" :    
                 printers = cmd.storage.getMatchingPrinters("*")
