Changeset 2217 for pykota/trunk
- Timestamp:
- 04/24/05 00:01:46 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2210 r2217 148 148 return dirvalues 149 149 150 def getJob OriginatingHostnameFromPageLog(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.""" 152 152 pagelogpath = cupsconfig.get("pagelog", "/var/log/cups/page_log") 153 153 self.logdebug("Trying to extract job-originating-host-name from %s" % pagelogpath) … … 156 156 except IOError : 157 157 self.logdebug("Unable to open %s" % pagelogpath) 158 return # no page log or can't read it, originating hostname unknown yet158 return (None, None) # no page log or can't read it, originating hostname unknown yet 159 159 else : 160 160 # TODO : read backward so we could take first value seen … … 173 173 if matchingline is None : 174 174 self.logdebug("No matching line found in %s" % pagelogpath) 175 return # correct line not found, job-originating-host-name unknown175 return (None, None) # correct line not found, job-originating-host-name unknown 176 176 else : 177 return matchingline.split()[-1] 177 (jobbilling, hostname) = matchingline.split()[-2:] 178 if jobbilling == "-" : 179 jobbilling = "" 180 return (jobbilling, hostname) 178 181 179 182 def doWork(self, policy, printer, user, userpquota) : … … 212 215 ippdatafile.close() 213 216 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) 216 221 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 too222 self.logdebug("Billing Code : %s" % (billingcode or "None")) 223 os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = clienthost or "" 224 os.environ["PYKOTAJOBBILLING"] = billingcode or "" 220 225 221 226 # enters first phase … … 355 360 action, jobsize, jobprice, self.preserveinputfile, \ 356 361 self.title, self.copies, self.options, clienthost, \ 357 self.jobSizeBytes, self.checksum )362 self.jobSizeBytes, self.checksum, None, billingcode) 358 363 self.printMoreInfo(user, printer, _("Job added to history.")) 359 364 -
pykota/trunk/bin/lprngpykota
r2210 r2217 141 141 action, jobsize, jobprice, self.preserveinputfile, \ 142 142 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 144 144 self.printMoreInfo(user, printer, _("Job added to history.")) 145 145 … … 160 160 action, filename=self.preserveinputfile, title=self.title, \ 161 161 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 163 163 self.logdebug("Job added to history during first pass : Job's size and price are still unknown.") 164 164 -
pykota/trunk/conf/pykota.conf.sample
r2204 r2217 647 647 # page was still printed on the current printer. 648 648 # PYKOTAOVERCHARGE : user's overcharging factor. 649 # PYKOTAJOBBILLING : Job's billing code if present (CUPS only) 649 650 # 650 651 -
pykota/trunk/NEWS
r2216 r2217 24 24 - 1.22alpha8 : 25 25 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 26 30 - Ctrl+C now makes PyKota commands exit without a traceback. 27 31 -
pykota/trunk/pykota/dumper.py
r2163 r2217 150 150 copies = entry[fields["copies"]] or 1 151 151 hostname = entry[fields["hostname"]] or "" 152 billingcode = entry[fields["billingcode"]] or "-" 152 153 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)) 154 155 155 156 def dumpXml(self, entries, datatype) : -
pykota/trunk/pykota/storage.py
r2147 r2217 146 146 raise AttributeError, name 147 147 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) : 149 149 """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) 151 151 # TODO : update LastJob object ? Probably not needed. 152 152 -
pykota/trunk/pykota/storages/ldapstorage.py
r2211 r2217 531 531 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 532 532 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]) 534 534 lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 535 535 lastjob.JobPages = fields.get("pykotaPages", [""])[0] … … 929 929 self.doModify(lastjob.ident, fields) 930 930 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) : 932 932 """Adds a job in a printer's history.""" 933 933 if (not self.disablehistory) or (not printer.LastJob.Exists) : … … 939 939 if self.privacy : 940 940 # 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") 942 942 fields = { 943 943 "objectClass" : ["pykotaObject", "pykotaJob"], … … 955 955 "pykotaJobSizeBytes" : str(jobsizebytes), 956 956 "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 957 959 } 958 960 if (not self.disablehistory) or (not printer.LastJob.Exists) : … … 1089 1091 job.JobHostName = fields.get("pykotaHostName", [""])[0] 1090 1092 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]) 1092 1094 job.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 1093 1095 job.JobPages = fields.get("pykotaPages", [""])[0] -
pykota/trunk/pykota/storages/sql.py
r2147 r2217 255 255 lastjob.JobMD5Sum = fields.get("md5sum") 256 256 lastjob.JobPages = fields.get("pages") 257 lastjob.JobBillingCode = fields.get("billingcode")257 lastjob.JobBillingCode = self.databaseToUserCharset(fields.get("billingcode")) 258 258 lastjob.Exists = 1 259 259 return lastjob … … 450 450 self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 451 451 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) : 453 453 """Adds a job in a printer's history.""" 454 454 if self.privacy : 455 455 # 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") 457 457 filename = self.userCharsetToDatabase(filename) 458 458 title = self.userCharsetToDatabase(title) 459 459 options = self.userCharsetToDatabase(options) 460 jobbilling = self.userCharsetToDatabase(jobbilling) 460 461 if (not self.disablehistory) or (not printer.LastJob.Exists) : 461 462 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))) 463 464 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))) 465 466 else : 466 467 # 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))) 468 469 469 470 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : … … 534 535 job.JobMD5Sum = fields.get("md5sum") 535 536 job.JobPages = fields.get("pages") 536 job.JobBillingCode = fields.get("billingcode")537 job.JobBillingCode = self.databaseToUserCharset(fields.get("billingcode")) 537 538 job.UserName = fields.get("username") 538 539 job.PrinterName = fields.get("printername")