| 257 | def getPageLogLocation(self) : |
| 258 | """Retrieves CUPS' page_log file location.""" |
| 259 | location = None |
| 260 | cupsroot = os.environ.get("CUPS_SERVERROOT", "/etc/cups") |
| 261 | cupsdconf = os.path.join(cupsroot, "cupsd.conf") |
| 262 | try : |
| 263 | conffile = open(cupsdconf, "r") |
| 264 | except IOError : |
| 265 | return # file doesn't exist or can't be read |
| 266 | else : |
| 267 | for line in conffile.readlines() : |
| 268 | linecopy = line.strip().lower() |
| 269 | if linecopy.startswith("pagelog ") : |
| 270 | try : |
| 271 | location = line.split()[1] |
| 272 | except : |
| 273 | pass # ignore errors, we take the last value in any case. |
| 274 | conffile.close() |
| 275 | return location |
| 276 | |
| 277 | def getJobOriginatingHostname(self, printername, username, jobid) : |
| 278 | """Retrieves the job-originating-hostname from the CUPS page_log file if possible.""" |
| 279 | pagelogpath = self.getPageLogLocation() or "/var/log/cups/page_log" |
| 280 | try : |
| 281 | pagelog = open(pagelogpath, "r") |
| 282 | except IOError : |
| 283 | return # no page log or can't read it, originating hostname unknown yet |
| 284 | else : |
| 285 | # TODO : read backward so we could take first value seen |
| 286 | # TODO : here we read forward so we must take the last value seen |
| 287 | prefix = "%s %s %s" % (printername, username, jobid) |
| 288 | matchingline = None |
| 289 | while 1 : |
| 290 | line = pagelog.readline() |
| 291 | if not line : |
| 292 | break |
| 293 | else : |
| 294 | line = line.strip() |
| 295 | if line.startswith(prefix) : |
| 296 | matchingline = line # no break, because we read forward |
| 297 | pagelog.close() |
| 298 | if matchingline is None : |
| 299 | return # correct line not found, job-originating-hostname unknown |
| 300 | else : |
| 301 | return matchingline.split()[-1] |
| 302 | |
319 | | printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options) |
| 372 | printer.addJobToHistory(self.jobid, user, self.accounter.getLastPageCounter(), action, jobsize, jobprice, self.preserveinputfile, self.title, self.copies, self.options, clienthost) |