Index: /pykota/trunk/bin/pkbanner
===================================================================
--- /pykota/trunk/bin/pkbanner (revision 1911)
+++ /pykota/trunk/bin/pkbanner (revision 1918)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.4  2004/11/15 19:59:34  jalet
+# PyKota banners now basically work !
+#
 # Revision 1.3  2004/11/12 23:46:44  jalet
 # Heavy work on pkbanner. Not finished yet though, but mostly works.
@@ -39,4 +42,5 @@
 import os
 import cStringIO
+import popen2
 
 try :
@@ -198,6 +202,21 @@
             self.printInfo("Unknown page size %s, defaulting to A4." % options["pagesize"], "warn")
             
+        self.logdebug("Generating the banner in PDF format...")    
         doc = self.genPDF(pagesize, options["logo"], options["url"].strip())
-        print doc
+        
+        self.logdebug("Converting the banner to PostScript...")    
+        os.environ["PATH"] = "%s:/bin:/usr/bin:/usr/local/bin:/opt/bin:/sbin:/usr/sbin" % os.environ.get("PATH", "")
+        child = popen2.Popen3("gs -q -dNOPAUSE -dBATCH -dPARANOIDSAFER -sDEVICE=pswrite -sOutputFile=- - 2>/tmp/errgs")
+        child.tochild.write(doc)
+        child.tochild.close()
+        sys.stdout.write(child.fromchild.read())
+        sys.stdout.flush()
+        child.fromchild.close()
+        status = child.wait()
+        if os.WIFEXITED(status) :
+            status = os.WEXITSTATUS(status)
+        self.logdebug("PDF to PostScript converter exit code is %s" % str(status))
+        self.logdebug("Banner completed.")
+        return status
 
 def getInfo(name) :
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1902)
+++ /pykota/trunk/bin/cupspykota (revision 1918)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.78  2004/11/15 19:59:34  jalet
+# PyKota banners now basically work !
+#
 # Revision 1.77  2004/11/06 22:40:57  jalet
 # Safer code
@@ -469,7 +472,28 @@
             # launches the pre hook
             self.prehook(userpquota)
-            
+
+            # saves the size of banners which have to be accounted for
+            # this is needed in the case of software accounting
+            bannersize = 0
+            
+            # handle starting banner pages before accounting
+            accountbanner = self.config.getAccountBanner(printer.Name)
+            if accountbanner in ["ENDING", "NONE"] :
+                banner = self.startingBanner(printer.Name)
+                if banner :
+                    self.logdebug("Printing starting banner before accounting begins.")
+                    self.handleData(banner)
+ 
             self.printMoreInfo(user, printer, _("Job accounting begins."))
             self.accounter.beginJob(printer)
+            
+            # handle starting banner pages during accounting
+            if accountbanner in ["STARTING", "BOTH"] :
+                banner = self.startingBanner(printer.Name)
+                if banner :
+                    self.logdebug("Printing starting banner during accounting.")
+                    self.handleData(banner)
+                    if self.accounter.isSoftware :
+                        bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer
         else :    
             action = "ALLOW"
@@ -489,8 +513,24 @@
             os.environ["PYKOTAPHASE"] = "AFTER"
             
+            # handle ending banner pages during accounting
+            if accountbanner in ["ENDING", "BOTH"] :
+                banner = self.endingBanner(printer.Name)
+                if banner :
+                    self.logdebug("Printing ending banner during accounting.")
+                    self.handleData(banner)
+                    if self.accounter.isSoftware :
+                        bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer
+ 
             # stops accounting. 
             self.accounter.endJob(printer)
             self.printMoreInfo(user, printer, _("Job accounting ends."))
                 
+            # handle ending banner pages after accounting ends
+            if accountbanner in ["STARTING", "NONE"] :
+                banner = self.endingBanner(printer.Name)
+                if banner :
+                    self.logdebug("Printing ending banner after accounting ends.")
+                    self.handleData(banner)
+ 
             # retrieve the job size    
             if action == "DENY" :
@@ -498,5 +538,5 @@
                 self.printMoreInfo(user, printer, _("Job size forced to 0 because printing is denied."))
             else :    
-                jobsize = self.accounter.getJobSize(printer)
+                jobsize = self.accounter.getJobSize(printer) + bannersize
             self.printMoreInfo(user, printer, _("Job size : %i") % jobsize)
             
@@ -549,5 +589,5 @@
         return "%s (%s)" % (fd, " | ".join(maskval))
         
-    def handleData(self) :                    
+    def handleData(self, filehandle=None) :
         """Pass the job's data to the real backend."""
         # Find the real backend pathname    
@@ -578,16 +618,23 @@
         totalfromchild = totaltocups = 0
         
-        if self.preserveinputfile is None :
-            # this is not a real file, we read the job's data
-            # from our temporary file which is a copy of stdin 
-            infno = self.jobdatastream.fileno()
-            self.jobdatastream.seek(0)
-            pollster.register(infno, select.POLLIN | select.POLLPRI)
-        else :    
-            # 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)
+        if filehandle is None:
+            if self.preserveinputfile is None :
+               # this is not a real file, we read the job's data
+                # from our temporary file which is a copy of stdin 
+                infno = self.jobdatastream.fileno()
+                self.jobdatastream.seek(0)
+                pollster.register(infno, select.POLLIN | select.POLLPRI)
+            else :    
+                # 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)
+                infno = None
+                endinput = 1
+        else:
+            self.logdebug("Printing data passed from filehandle")
+            indata = filehandle.read()
             infno = None
             endinput = 1
+            filehandle.close()
         
         self.logdebug("Entering streams polling loop...")
Index: /pykota/trunk/MANIFEST.in
===================================================================
--- /pykota/trunk/MANIFEST.in (revision 1911)
+++ /pykota/trunk/MANIFEST.in (revision 1918)
@@ -1,3 +1,3 @@
-include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh checkdeps.py bin/autopykota bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README
+include README FAQ COPYING LICENSE TODO NEWS CREDITS SECURITY MANIFEST.in clean.sh checkdeps.py bin/pkbanner bin/autopykota bin/dumpykota bin/lprngpykota bin/cupspykota bin/edpykota bin/warnpykota bin/repykota bin/pykotme bin/pykosd bin/pkprinters bin/pkhint bin/pkpgcounter bin/snmpprinterstatus bin/waitprinter.sh bin/papwaitprinter.sh bin/mailandpopup.sh bin/README
 recursive-include po README *.sh *.po *.mo *.pot
 recursive-include man README *.sh *.1
Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1911)
+++ /pykota/trunk/setup.py (revision 1918)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.59  2004/11/15 19:59:34  jalet
+# PyKota banners now basically work !
+#
 # Revision 1.58  2004/11/12 23:46:43  jalet
 # Heavy work on pkbanner. Not finished yet though, but mostly works.
@@ -301,4 +304,4 @@
       url = "http://www.librelogiciel.com/software/",
       packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
-      scripts = [ "bin/autopykota", "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
+      scripts = [ "bin/pkbanner", "bin/autopykota", "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ],
       data_files = data_files)
Index: /pykota/trunk/pykota/tool.py
===================================================================
--- /pykota/trunk/pykota/tool.py (revision 1917)
+++ /pykota/trunk/pykota/tool.py (revision 1918)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.140  2004/11/15 19:59:34  jalet
+# PyKota banners now basically work !
+#
 # Revision 1.139  2004/11/15 15:54:03  jalet
 # Continued integration of Matt's patch for banners
@@ -1221,12 +1224,12 @@
            by the printer.
         """
-        banner = "" # no banner by default
         if bannerfileorcommand :
+            banner = "" # no banner by default
             if (os.access(bannerfileorcommand, os.X_OK)) :
                 self.logdebug("Launching %s to generate a banner." % bannerfileorcommand)
                 child = popen2.Popen3(bannerfileorcommand, capturestderr=1)
+                banner = child.fromchild.read()
                 child.tochild.close()
                 child.childerr.close()
-                banner = child.fromchild.read()
                 child.fromchild.close()
                 status = child.wait()
@@ -1243,5 +1246,6 @@
                     banner = fh.read()
                     fh.close()
-        return cStringIO.StringIO(banner)
+            if banner :        
+                return cStringIO.StringIO(banner)
     
     def startingBanner(self, printername) :
