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

PyKota banners now basically work !

Files:
1 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...")