Show
Ignore:
Timestamp:
04/24/05 00:01:46 (19 years ago)
Author:
jerome
Message:

The job-billing info is now saved into the database if present.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2210 r2217  
    148148        return dirvalues        
    149149             
    150     def getJobOriginatingHostnameFromPageLog(self, cupsconfig, printername, username, jobid) : 
    151         """Retrieves the job-originating-hostname from the CUPS page_log file if possible.""" 
     150    def getJobInfosFromPageLog(self, cupsconfig, printername, username, jobid) : 
     151        """Retrieves the job-originating-hostname and job-billing attributes from the CUPS page_log file if possible.""" 
    152152        pagelogpath = cupsconfig.get("pagelog", "/var/log/cups/page_log") 
    153153        self.logdebug("Trying to extract job-originating-host-name from %s" % pagelogpath) 
     
    156156        except IOError :     
    157157            self.logdebug("Unable to open %s" % pagelogpath) 
    158             return # no page log or can't read it, originating hostname unknown yet 
     158            return (None, None) # no page log or can't read it, originating hostname unknown yet 
    159159        else :     
    160160            # TODO : read backward so we could take first value seen 
     
    173173            if matchingline is None : 
    174174                self.logdebug("No matching line found in %s" % pagelogpath) 
    175                 return # correct line not found, job-originating-host-name unknown 
     175                return (None, None) # correct line not found, job-originating-host-name unknown 
    176176            else :     
    177                 return matchingline.split()[-1] 
     177                (jobbilling, hostname) = matchingline.split()[-2:] 
     178                if jobbilling == "-" : 
     179                    jobbilling = "" 
     180                return (jobbilling, hostname)    
    178181                 
    179182    def doWork(self, policy, printer, user, userpquota) :     
     
    212215                ippdatafile.close() 
    213216            self.dropPriv()     
    214             clienthost = ippmessage.get("job-originating-host-name") \ 
    215                          or self.getJobOriginatingHostnameFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 
     217            clienthost = ippmessage.get("job-originating-host-name")  
     218            billingcode = ippmessage.get("job-billing") 
     219            if clienthost is None : 
     220                (billingcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 
    216221            self.logdebug("Client Hostname : %s" % (clienthost or "Unknown"))     
    217             os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = str(clienthost or "") 
    218              
    219             # TODO : extract username (double check ?) and billing code too 
     222            self.logdebug("Billing Code : %s" % (billingcode or "None"))     
     223            os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = clienthost or "" 
     224            os.environ["PYKOTAJOBBILLING"] = billingcode or "" 
    220225             
    221226            # enters first phase 
     
    355360                                    action, jobsize, jobprice, self.preserveinputfile, \ 
    356361                                    self.title, self.copies, self.options, clienthost, \ 
    357                                     self.jobSizeBytes, self.checksum) 
     362                                    self.jobSizeBytes, self.checksum, None, billingcode) 
    358363            self.printMoreInfo(user, printer, _("Job added to history.")) 
    359364