Changeset 2217 for pykota/trunk

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

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

Location:
pykota/trunk
Files:
8 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             
  • pykota/trunk/bin/lprngpykota

    r2210 r2217  
    141141                                    action, jobsize, jobprice, self.preserveinputfile, \ 
    142142                                    self.title, self.copies, self.options, clienthost, \ 
    143                                     self.jobSizeBytes, self.checksum) 
     143                                    self.jobSizeBytes, self.checksum, None, None) # TODO : pages detail and billing code 
    144144            self.printMoreInfo(user, printer, _("Job added to history.")) 
    145145             
     
    160160                                    action, filename=self.preserveinputfile, title=self.title, \ 
    161161                                    copies=self.copies, options=self.options, clienthost=clienthost, \ 
    162                                     jobsizebytes=self.jobSizeBytes, jobmd5sum=self.checksum) 
     162                                    jobsizebytes=self.jobSizeBytes, jobmd5sum=self.checksum, jobpages=None, jobbilling=None) # TODO : pages detail and billing code 
    163163            self.logdebug("Job added to history during first pass : Job's size and price are still unknown.") 
    164164             
  • pykota/trunk/conf/pykota.conf.sample

    r2204 r2217  
    647647#                   page was still printed on the current printer.                    
    648648# PYKOTAOVERCHARGE : user's overcharging factor. 
     649# PYKOTAJOBBILLING : Job's billing code if present (CUPS only) 
    649650# 
    650651 
  • pykota/trunk/NEWS

    r2216 r2217  
    2424    - 1.22alpha8 : 
    2525     
     26        - The job billing code if present is now saved into the database, 
     27          and exported to subprocesses as the PYKOTAJOBBILLING environment 
     28          variable. 
     29           
    2630        - Ctrl+C now makes PyKota commands exit without a traceback. 
    2731         
  • pykota/trunk/pykota/dumper.py

    r2163 r2217  
    150150            copies = entry[fields["copies"]] or 1 
    151151            hostname = entry[fields["hostname"]] or "" 
     152            billingcode = entry[fields["billingcode"]] or "-" 
    152153            for pagenum in range(1, jobsize+1) : 
    153                 self.outfile.write("%s %s %s [%s] %s %s - %s\n" % (printername, username, jobid, jobdate, pagenum, copies, hostname)) 
     154                self.outfile.write("%s %s %s [%s] %s %s %s %s\n" % (printername, username, jobid, jobdate, pagenum, copies, billingcode, hostname)) 
    154155         
    155156    def dumpXml(self, entries, datatype) :     
  • pykota/trunk/pykota/storage.py

    r2147 r2217  
    146146            raise AttributeError, name 
    147147             
    148     def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None) : 
     148    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None) : 
    149149        """Adds a job to the printer's history.""" 
    150         self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost, jobsizebytes, jobmd5sum) 
     150        self.parent.writeJobNew(self, user, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, clienthost, jobsizebytes, jobmd5sum, jobpages, jobbilling) 
    151151        # TODO : update LastJob object ? Probably not needed. 
    152152         
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2211 r2217  
    531531                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
    532532                lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
    533                 lastjob.JobBillingCode = fields.get("pykotaBillingCode", [None])[0] 
     533                lastjob.JobBillingCode = self.databaseToUserCharset(fields.get("pykotaBillingCode", [None])[0]) 
    534534                lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 
    535535                lastjob.JobPages = fields.get("pykotaPages", [""])[0] 
     
    929929        self.doModify(lastjob.ident, fields)          
    930930         
    931     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None) : 
     931    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None) : 
    932932        """Adds a job in a printer's history.""" 
    933933        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    939939        if self.privacy :     
    940940            # For legal reasons, we want to hide the title, filename and options 
    941             title = filename = options = "Hidden because of privacy concerns" 
     941            title = filename = options = _("Hidden because of privacy concerns") 
    942942        fields = { 
    943943                   "objectClass" : ["pykotaObject", "pykotaJob"], 
     
    955955                   "pykotaJobSizeBytes" : str(jobsizebytes), 
    956956                   "pykotaMD5Sum" : str(jobmd5sum), 
     957                   "pykotaPages" : jobpages,            # don't add this attribute if it is not set, so no string conversion 
     958                   "pykotaBillingCode" : self.userCharsetToDatabase(jobbilling), # don't add this attribute if it is not set, so no string conversion 
    957959                 } 
    958960        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
     
    10891091                job.JobHostName = fields.get("pykotaHostName", [""])[0] 
    10901092                job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
    1091                 job.JobBillingCode = fields.get("pykotaBillingCode", [None])[0] 
     1093                job.JobBillingCode = self.databaseToUserCharset(fields.get("pykotaBillingCode", [None])[0]) 
    10921094                job.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 
    10931095                job.JobPages = fields.get("pykotaPages", [""])[0] 
  • pykota/trunk/pykota/storages/sql.py

    r2147 r2217  
    255255            lastjob.JobMD5Sum = fields.get("md5sum") 
    256256            lastjob.JobPages = fields.get("pages") 
    257             lastjob.JobBillingCode = fields.get("billingcode") 
     257            lastjob.JobBillingCode = self.databaseToUserCharset(fields.get("billingcode")) 
    258258            lastjob.Exists = 1 
    259259        return lastjob 
     
    450450        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 
    451451         
    452     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None) : 
     452    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None) : 
    453453        """Adds a job in a printer's history.""" 
    454454        if self.privacy :     
    455455            # For legal reasons, we want to hide the title, filename and options 
    456             title = filename = options = "Hidden because of privacy concerns" 
     456            title = filename = options = _("Hidden because of privacy concerns") 
    457457        filename = self.userCharsetToDatabase(filename) 
    458458        title = self.userCharsetToDatabase(title) 
    459459        options = self.userCharsetToDatabase(options) 
     460        jobbilling = self.userCharsetToDatabase(jobbilling) 
    460461        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    461462            if jobsize is not None : 
    462                 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname, jobsizebytes, md5sum) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum))) 
     463                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname, jobsizebytes, md5sum, pages, billingcode) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum), self.doQuote(jobpages), self.doQuote(jobbilling))) 
    463464            else :     
    464                 self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname, jobsizebytes, md5sum) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum))) 
     465                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname, jobsizebytes, md5sum, pages, billingcode) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum), self.doQuote(jobpages), self.doQuote(jobbilling))) 
    465466        else :         
    466467            # here we explicitly want to reset jobsize to NULL if needed 
    467             self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobsizebytes=%s, md5sum=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum), self.doQuote(printer.LastJob.ident))) 
     468            self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobsizebytes=%s, md5sum=%s, pages=%s, billingcode=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum), self.doQuote(jobpages), self.doQuote(jobbilling), self.doQuote(printer.LastJob.ident))) 
    468469             
    469470    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 
     
    534535                job.JobMD5Sum = fields.get("md5sum") 
    535536                job.JobPages = fields.get("pages") 
    536                 job.JobBillingCode = fields.get("billingcode") 
     537                job.JobBillingCode = self.databaseToUserCharset(fields.get("billingcode")) 
    537538                job.UserName = fields.get("username") 
    538539                job.PrinterName = fields.get("printername")