Show
Ignore:
Timestamp:
07/28/05 17:58:30 (19 years ago)
Author:
jerome
Message:

Added the overwrite_jobticket directive.
Severity : How Powerful !!! :-)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r2347 r2393  
    665665        self.username = self.username or pwd.getpwuid(os.geteuid())[0] # use CUPS' user when printing test page from CUPS web interface, otherwise username is empty 
    666666         
     667        (newusername, newbillingcode, newaction) = self.overwriteJobTicket() 
     668        if newusername : 
     669            self.printInfo(_("Job ticket overwritten : new username = [%s]") % newusername) 
     670            self.username = newusername 
     671        if newbillingcode : 
     672            self.printInfo(_("Job ticket overwritten : new billing code = [%s]") % newbillingcode) 
     673            self.overwrittenBillingCode = newbillingcode 
     674        else :     
     675            self.overwrittenBillingCode = None 
     676        if newaction :     
     677            self.printInfo(_("Job ticket overwritten : job will be denied (but a bit later).")) 
     678            self.mustDeny = 1 
     679        else :     
     680            self.mustDeny = 0 
     681         
    667682        # do we want to strip out the Samba/Winbind domain name ? 
    668683        separator = self.config.getWinbindSeparator() 
     
    696711        self.logdebug("Capturing SIGTERM events.") 
    697712        signal.signal(signal.SIGTERM, self.sigterm_handler) 
     713         
     714    def overwriteJobTicket(self) :     
     715        """Should we overwrite the job's ticket (username and billingcode) ?""" 
     716        jobticketcommand = self.config.getOverwriteJobTicket(self.printername) 
     717        if jobticketcommand is not None : 
     718            username = billingcode = action = None 
     719            self.logdebug("Launching subprocess [%s] to overwrite the job's ticket." % jobticketcommand) 
     720            inputfile = os.popen(jobticketcommand, "r") 
     721            for line in inputfile.xreadlines() : 
     722                line = line.strip() 
     723                if line == "DENY" : 
     724                    self.logdebug("Seen DENY command.") 
     725                    action = "DENY" 
     726                elif line.startswith("USERNAME=") :     
     727                    username = line.split("=", 1)[1].strip() 
     728                    self.logdebug("Seen new username [%s]" % username) 
     729                    action = None 
     730                elif line.startswith("BILLINGCODE=") :     
     731                    billingcode = line.split("=", 1)[1].strip() 
     732                    self.logdebug("Seen new billing code [%s]" % billingcode) 
     733                    action = None 
     734            inputfile.close()     
     735            return (username, billingcode, action) 
     736        else : 
     737            return (None, None, None) 
    698738         
    699739    def sendBackChannelData(self, message, level="info") :