Changeset 1918 for pykota

Show
Ignore:
Timestamp:
11/15/04 20:59:34 (20 years ago)
Author:
jalet
Message:

PyKota banners now basically work !

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1902 r1918  
    2424# 
    2525# $Log$ 
     26# Revision 1.78  2004/11/15 19:59:34  jalet 
     27# PyKota banners now basically work ! 
     28# 
    2629# Revision 1.77  2004/11/06 22:40:57  jalet 
    2730# Safer code 
     
    469472            # launches the pre hook 
    470473            self.prehook(userpquota) 
    471              
     474 
     475            # saves the size of banners which have to be accounted for 
     476            # this is needed in the case of software accounting 
     477            bannersize = 0 
     478             
     479            # handle starting banner pages before accounting 
     480            accountbanner = self.config.getAccountBanner(printer.Name) 
     481            if accountbanner in ["ENDING", "NONE"] : 
     482                banner = self.startingBanner(printer.Name) 
     483                if banner : 
     484                    self.logdebug("Printing starting banner before accounting begins.") 
     485                    self.handleData(banner) 
     486  
    472487            self.printMoreInfo(user, printer, _("Job accounting begins.")) 
    473488            self.accounter.beginJob(printer) 
     489             
     490            # handle starting banner pages during accounting 
     491            if accountbanner in ["STARTING", "BOTH"] : 
     492                banner = self.startingBanner(printer.Name) 
     493                if banner : 
     494                    self.logdebug("Printing starting banner during accounting.") 
     495                    self.handleData(banner) 
     496                    if self.accounter.isSoftware : 
     497                        bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
    474498        else :     
    475499            action = "ALLOW" 
     
    489513            os.environ["PYKOTAPHASE"] = "AFTER" 
    490514             
     515            # handle ending banner pages during accounting 
     516            if accountbanner in ["ENDING", "BOTH"] : 
     517                banner = self.endingBanner(printer.Name) 
     518                if banner : 
     519                    self.logdebug("Printing ending banner during accounting.") 
     520                    self.handleData(banner) 
     521                    if self.accounter.isSoftware : 
     522                        bannersize += 1 # TODO : fix this by passing the banner's content through PDLAnalyzer 
     523  
    491524            # stops accounting.  
    492525            self.accounter.endJob(printer) 
    493526            self.printMoreInfo(user, printer, _("Job accounting ends.")) 
    494527                 
     528            # handle ending banner pages after accounting ends 
     529            if accountbanner in ["STARTING", "NONE"] : 
     530                banner = self.endingBanner(printer.Name) 
     531                if banner : 
     532                    self.logdebug("Printing ending banner after accounting ends.") 
     533                    self.handleData(banner) 
     534  
    495535            # retrieve the job size     
    496536            if action == "DENY" : 
     
    498538                self.printMoreInfo(user, printer, _("Job size forced to 0 because printing is denied.")) 
    499539            else :     
    500                 jobsize = self.accounter.getJobSize(printer) 
     540                jobsize = self.accounter.getJobSize(printer) + bannersize 
    501541            self.printMoreInfo(user, printer, _("Job size : %i") % jobsize) 
    502542             
     
    549589        return "%s (%s)" % (fd, " | ".join(maskval)) 
    550590         
    551     def handleData(self) :                     
     591    def handleData(self, filehandle=None) : 
    552592        """Pass the job's data to the real backend.""" 
    553593        # Find the real backend pathname     
     
    578618        totalfromchild = totaltocups = 0 
    579619         
    580         if self.preserveinputfile is None : 
    581             # this is not a real file, we read the job's data 
    582             # from our temporary file which is a copy of stdin  
    583             infno = self.jobdatastream.fileno() 
    584             self.jobdatastream.seek(0) 
    585             pollster.register(infno, select.POLLIN | select.POLLPRI) 
    586         else :     
    587             # job's data is in a file, no need to pass the data 
    588             # to the real backend 
    589             self.logdebug("Job's data is in %s" % self.preserveinputfile) 
     620        if filehandle is None: 
     621            if self.preserveinputfile is None : 
     622               # this is not a real file, we read the job's data 
     623                # from our temporary file which is a copy of stdin  
     624                infno = self.jobdatastream.fileno() 
     625                self.jobdatastream.seek(0) 
     626                pollster.register(infno, select.POLLIN | select.POLLPRI) 
     627            else :     
     628                # job's data is in a file, no need to pass the data 
     629                # to the real backend 
     630                self.logdebug("Job's data is in %s" % self.preserveinputfile) 
     631                infno = None 
     632                endinput = 1 
     633        else: 
     634            self.logdebug("Printing data passed from filehandle") 
     635            indata = filehandle.read() 
    590636            infno = None 
    591637            endinput = 1 
     638            filehandle.close() 
    592639         
    593640        self.logdebug("Entering streams polling loop...") 
  • pykota/trunk/bin/pkbanner

    r1911 r1918  
    2424# 
    2525# $Log$ 
     26# Revision 1.4  2004/11/15 19:59:34  jalet 
     27# PyKota banners now basically work ! 
     28# 
    2629# Revision 1.3  2004/11/12 23:46:44  jalet 
    2730# Heavy work on pkbanner. Not finished yet though, but mostly works. 
     
    3942import os 
    4043import cStringIO 
     44import popen2 
    4145 
    4246try : 
     
    198202            self.printInfo("Unknown page size %s, defaulting to A4." % options["pagesize"], "warn") 
    199203             
     204        self.logdebug("Generating the banner in PDF format...")     
    200205        doc = self.genPDF(pagesize, options["logo"], options["url"].strip()) 
    201         print doc 
     206         
     207        self.logdebug("Converting the banner to PostScript...")     
     208        os.environ["PATH"] = "%s:/bin:/usr/bin:/usr/local/bin:/opt/bin:/sbin:/usr/sbin" % os.environ.get("PATH", "") 
     209        child = popen2.Popen3("gs -q -dNOPAUSE -dBATCH -dPARANOIDSAFER -sDEVICE=pswrite -sOutputFile=- - 2>/tmp/errgs") 
     210        child.tochild.write(doc) 
     211        child.tochild.close() 
     212        sys.stdout.write(child.fromchild.read()) 
     213        sys.stdout.flush() 
     214        child.fromchild.close() 
     215        status = child.wait() 
     216        if os.WIFEXITED(status) : 
     217            status = os.WEXITSTATUS(status) 
     218        self.logdebug("PDF to PostScript converter exit code is %s" % str(status)) 
     219        self.logdebug("Banner completed.") 
     220        return status 
    202221 
    203222def getInfo(name) : 
  • pykota/trunk/MANIFEST.in

    r1911 r1918  
    1 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 
     1include 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 
    22recursive-include po README *.sh *.po *.mo *.pot 
    33recursive-include man README *.sh *.1 
  • pykota/trunk/pykota/tool.py

    r1917 r1918  
    2222# 
    2323# $Log$ 
     24# Revision 1.140  2004/11/15 19:59:34  jalet 
     25# PyKota banners now basically work ! 
     26# 
    2427# Revision 1.139  2004/11/15 15:54:03  jalet 
    2528# Continued integration of Matt's patch for banners 
     
    12211224           by the printer. 
    12221225        """ 
    1223         banner = "" # no banner by default 
    12241226        if bannerfileorcommand : 
     1227            banner = "" # no banner by default 
    12251228            if (os.access(bannerfileorcommand, os.X_OK)) : 
    12261229                self.logdebug("Launching %s to generate a banner." % bannerfileorcommand) 
    12271230                child = popen2.Popen3(bannerfileorcommand, capturestderr=1) 
     1231                banner = child.fromchild.read() 
    12281232                child.tochild.close() 
    12291233                child.childerr.close() 
    1230                 banner = child.fromchild.read() 
    12311234                child.fromchild.close() 
    12321235                status = child.wait() 
     
    12431246                    banner = fh.read() 
    12441247                    fh.close() 
    1245         return cStringIO.StringIO(banner) 
     1248            if banner :         
     1249                return cStringIO.StringIO(banner) 
    12461250     
    12471251    def startingBanner(self, printername) : 
  • pykota/trunk/setup.py

    r1911 r1918  
    2424# 
    2525# $Log$ 
     26# Revision 1.59  2004/11/15 19:59:34  jalet 
     27# PyKota banners now basically work ! 
     28# 
    2629# Revision 1.58  2004/11/12 23:46:43  jalet 
    2730# Heavy work on pkbanner. Not finished yet though, but mostly works. 
     
    301304      url = "http://www.librelogiciel.com/software/", 
    302305      packages = [ "pykota", "pykota.storages", "pykota.loggers", "pykota.accounters", "pykota.reporters" ], 
    303       scripts = [ "bin/autopykota", "bin/dumpykota", "bin/pkpgcounter", "bin/snmpprinterstatus", "bin/pykosd", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/pkprinters", "bin/pkhint" ], 
     306      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" ], 
    304307      data_files = data_files)