Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 1560)
+++ /pykota/trunk/pykota/tool.py (revision 1562)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.106  2004/06/22 09:31:18  jalet
+# Always send some debug info to CUPS' back channel stream (stderr) as
+# informationnal messages.
+#
 # Revision 1.105  2004/06/21 08:17:38  jalet
 # Added version number in subject message for directive crashrecipient.
@@ -918,5 +922,6 @@
             # seekable and complexifies our task, so create
             # a temporary file and use it instead
-            self.logdebug("Duplicating data stream from stdin to temporary file")
+            self.sendBackChannelData("Duplicating data stream from stdin to temporary file")
+            dummy = 0
             MEGABYTE = 1024*1024
             self.jobSizeBytes = 0
@@ -927,4 +932,7 @@
                     break
                 self.jobSizeBytes += len(data)    
+                if not (dummy % 10) :
+                    self.sendBackChannelData("%s bytes read..." % self.jobSizeBytes)
+                dummy += 1    
                 infile.write(data)
             infile.flush()    
@@ -933,5 +941,5 @@
         else :    
             # real file, just open it
-            self.logdebug("Opening data stream %s" % self.preserveinputfile)
+            self.sendBackChannelData("Opening data stream %s" % self.preserveinputfile)
             self.jobSizeBytes = os.stat(self.preserveinputfile)[6]
             return open(self.preserveinputfile, "rb")
@@ -939,5 +947,5 @@
     def closeJobDataStream(self) :    
         """Closes the file which contains the job's datas."""
-        self.logdebug("Closing data stream.")
+        self.sendBackChannelData("Closing data stream.")
         try :
             self.jobdatastream.close()
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1546)
+++ /pykota/trunk/bin/cupspykota (revision 1562)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.65  2004/06/22 09:31:17  jalet
+# Always send some debug info to CUPS' back channel stream (stderr) as
+# informationnal messages.
+#
 # Revision 1.64  2004/06/18 13:34:46  jalet
 # Now all tracebacks include PyKota's version number
@@ -366,5 +370,5 @@
                 self.softwareJobSize = self.precomputeJobSize()
                 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize)
-                self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice))
+                self.sendBackChannelData("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)
@@ -386,5 +390,5 @@
             self.prehook(userpquota)
             
-            self.logdebug("Job accounting begins.")
+            self.sendBackChannelData("Job accounting begins.")
             self.accounter.beginJob(userpquota)
         else :    
@@ -407,21 +411,21 @@
             # stops accounting. 
             self.accounter.endJob(userpquota)
-            self.logdebug("Job accounting ends.")
+            self.sendBackChannelData("Job accounting ends.")
                 
             # retrieve the job size    
             if action == "DENY" :
                 jobsize = 0
-                self.logdebug("Job size forced to 0 because printing is denied.")
+                self.sendBackChannelData("Job size forced to 0 because printing is denied.")
             else :    
                 jobsize = self.accounter.getJobSize()
-            self.logdebug("Job size : %i" % jobsize)
+            self.sendBackChannelData("Job size : %i" % jobsize)
             
             # update the quota for the current user on this printer 
-            self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name))
+            self.sendBackChannelData("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.logdebug("Job added to history.")
+            self.sendBackChannelData("Job added to history.")
             
             # exports some new environment variables
@@ -465,4 +469,9 @@
         return "%s (%s)" % (fd, " | ".join(maskval))
         
+    def sendBackChannelData(self, message) :    
+        """Sends an informational message to CUPS via back channel stream (stderr)."""
+        sys.stderr.write("INFO: PyKota (PID %s) : %s\n" % (os.getpid(), message.strip()))
+        sys.stderr.flush()
+        
     def handleData(self) :                    
         """Pass the job's data to the real backend."""
@@ -471,5 +480,5 @@
         
         # And launch it
-        self.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + sys.argv[1:])])))
+        self.sendBackChannelData("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"])
         
@@ -501,9 +510,9 @@
             # job's data is in a file, no need to pass the data
             # to the real backend
-            self.logdebug("Job's data is in %s" % self.preserveinputfile)
+            self.sendBackChannelData("Job's data is in %s" % self.preserveinputfile)
             infno = None
             endinput = 1
         
-        self.logdebug("Entering streams polling loop...")
+        self.sendBackChannelData("Entering streams polling loop...")
         MEGABYTE = 1024*1024
         killed = 0
@@ -521,5 +530,5 @@
                     self.logdebug("Error while sending signal to pid %s : %s" % (subprocess.pid, msg))
                 else :    
-                    self.logger.log_message(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid), "info")
+                    self.sendBackChannelData(_("SIGTERM was sent to real backend %s (pid: %s)") % (realbackend, subprocess.pid))
                     killed = 1
             
@@ -531,5 +540,5 @@
                 availablefds = []
             if not availablefds :
-                self.logdebug("Nothing to do, sleeping a bit...")
+                self.sendBackChannelData("Nothing to do, sleeping a bit...")
                 time.sleep(0.01) # give some time to the system
             else :
@@ -548,10 +557,10 @@
                                         indata = ""
                                 else :        
-                                    self.logdebug("No data to send to real backend yet, sleeping a bit...")
+                                    self.sendBackChannelData("No data to send to real backend yet, sleeping a bit...")
                                     time.sleep(0.01)
                                     
                                 if endinput :    
                                     self.unregisterFileNo(pollster, tocfno)        
-                                    self.logdebug("Closing real backend's stdin.")
+                                    self.sendBackChannelData("Closing real backend's stdin.")
                                     os.close(tocfno)
                                     inputclosed = 1
@@ -585,5 +594,5 @@
                                     if not data :    # If yes, then no more input data
                                         self.unregisterFileNo(pollster, infno)
-                                        self.logdebug("Input data ends.")
+                                        self.sendBackChannelData("Input data ends.")
                                         endinput = 1 # this happens with real files.
                                     else :    
@@ -591,5 +600,5 @@
                                 elif fd == fromcfno :
                                     if not data :
-                                        self.logdebug("No back channel data to read from real backend yet, sleeping a bit...")
+                                        self.sendBackChannelData("No back channel data to read from real backend yet, sleeping a bit...")
                                         time.sleep(0.01)
                                     else :
@@ -606,9 +615,9 @@
                                 # Here we are in the case where the input file is stdin.
                                 # which has no more data to be read.
-                                self.logdebug("Input data ends.")
+                                self.sendBackChannelData("Input data ends.")
                                 endinput = 1
                             elif fd == fromcfno :    
                                 # We are no more interested in this file descriptor        
-                                self.logdebug("Closing real backend's stdout+stderr.")
+                                self.sendBackChannelData("Closing real backend's stdout+stderr.")
                                 os.close(fromcfno)
                                 endoutput = 1
@@ -618,5 +627,5 @@
                                 
                         if mask & select.POLLNVAL :        
-                            self.logdebug("File %s was closed. Unregistering from polling object." % fd)
+                            self.sendBackChannelData("File %s was closed. Unregistering from polling object." % fd)
                             self.unregisterFileNo(pollster, fd)
                     except IOError, msg :            
@@ -625,8 +634,8 @@
         # We must close the real backend's input stream
         if killed and not inputclosed :
-            self.logdebug("Forcing close of real backend's stdin.")
+            self.sendBackChannelData("Forcing close of real backend's stdin.")
             os.close(tocfno)
         
-        self.logdebug("Exiting streams polling loop...")
+        self.sendBackChannelData("Exiting streams polling loop...")
         
         # Check exit code of original CUPS backend.    
@@ -634,5 +643,5 @@
             # we exited the loop before the real backend exited
             # now we have to wait for it to finish and get its status
-            self.logdebug("Waiting for real backend to exit...")
+            self.sendBackChannelData("Waiting for real backend to exit...")
             try :
                 status = subprocess.wait()
