Changeset 2060 for pykota/trunk/bin

Show
Ignore:
Timestamp:
02/14/05 23:53:44 (20 years ago)
Author:
jalet
Message:

Now always precomputes the job's size with the internal PDL parser, and not
only when 'enforcement: strict' was set in pykota.conf

Location:
pykota/trunk/bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2057 r2060  
    2424# 
    2525# $Log$ 
     26# Revision 1.87  2005/02/14 22:53:44  jalet 
     27# Now always precomputes the job's size with the internal PDL parser, and not 
     28# only when 'enforcement: strict' was set in pykota.conf 
     29# 
    2630# Revision 1.86  2005/02/13 22:48:37  jalet 
    2731# Added the md5sum to the history 
     
    378382        """    
    379383        return 0 
     384         
     385    def genBanner(self, bannerfileorcommand) : 
     386        """Reads a banner or generates one through an external command. 
     387         
     388           Returns the banner's content in a format which MUST be accepted 
     389           by the printer. 
     390        """ 
     391        if bannerfileorcommand : 
     392            banner = "" # no banner by default 
     393            if os.access(bannerfileorcommand, os.X_OK) or not os.path.isfile(bannerfileorcommand) : 
     394                self.logdebug("Launching %s to generate a banner." % bannerfileorcommand) 
     395                child = popen2.Popen3(bannerfileorcommand, capturestderr=1) 
     396                banner = child.fromchild.read() 
     397                child.tochild.close() 
     398                child.childerr.close() 
     399                child.fromchild.close() 
     400                status = child.wait() 
     401                if os.WIFEXITED(status) : 
     402                    status = os.WEXITSTATUS(status) 
     403                self.printInfo(_("Banner generator %s exit code is %s") % (bannerfileorcommand, str(status))) 
     404            else : 
     405                self.logdebug("Using %s as the banner." % bannerfileorcommand) 
     406                try : 
     407                    fh = open(bannerfileorcommand, 'r') 
     408                except IOError, msg :     
     409                    self.printInfo("Impossible to open %s : %s" % (bannerfileorcommand, msg), "error") 
     410                else :     
     411                    banner = fh.read() 
     412                    fh.close() 
     413            if banner :         
     414                return cStringIO.StringIO(banner) 
     415     
     416    def startingBanner(self, printername) : 
     417        """Retrieves a starting banner for current printer and returns its content.""" 
     418        self.logdebug("Retrieving starting banner...") 
     419        return self.genBanner(self.config.getStartingBanner(printername)) 
     420     
     421    def endingBanner(self, printername) : 
     422        """Retrieves an ending banner for current printer and returns its content.""" 
     423        self.logdebug("Retrieving ending banner...") 
     424        return self.genBanner(self.config.getEndingBanner(printername)) 
    380425         
    381426    def getCupsConfigDirectives(self, directives=[]) : 
     
    480525            os.environ["PYKOTAPHASE"] = "BEFORE" 
    481526             
    482             # do we want strict or laxist quota enforcement ? 
    483             if self.config.getPrinterEnforcement(printer.Name) == "STRICT" : 
    484                 self.softwareJobSize = self.precomputeJobSize() 
    485                 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 
    486                 self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 
    487             os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 
     527            # precomputes the job's price 
     528            self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 
    488529            os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) 
     530            self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 
    489531             
    490532            # if no data to pass to real backend, probably a filter 
  • pykota/trunk/bin/lprngpykota

    r2057 r2060  
    2424# 
    2525# $Log$ 
     26# Revision 1.15  2005/02/14 22:53:44  jalet 
     27# Now always precomputes the job's size with the internal PDL parser, and not 
     28# only when 'enforcement: strict' was set in pykota.conf 
     29# 
    2630# Revision 1.14  2005/02/13 22:48:37  jalet 
    2731# Added the md5sum to the history 
     
    137141        os.environ["PYKOTAPHASE"] = "BEFORE" 
    138142         
    139         # do we want strict or laxist quota enforcement ? 
    140         if self.config.getPrinterEnforcement(printer.Name) == "STRICT" : 
    141             self.softwareJobSize = self.precomputeJobSize() 
    142             self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 
    143             self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 
    144         os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 
     143        # precomputes the job's price 
     144        self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 
    145145        os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) 
     146        self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 
    146147         
    147148        # if no data to pass to real backend, probably a filter 
     
    251252            # retrieve the job size     
    252253            jobsize = self.accounter.getJobSize(printer) 
     254            if self.softwareJobSize and (jobsize != self.softwareJobSize) : 
     255                self.printInfo(_("Beware : computed job size (%s) != precomputed job size (%s)") % (jobsize, self.softwareJobSize), "error") 
    253256             
    254257            self.printMoreInfo(user, printer, _("Job size : %i") % jobsize)