188 | | from pykota.accounter import openAccounter, PyKotaAccounterError |
189 | | |
190 | | class PyKotaFilter(PyKotaTool) : |
191 | | """Class for the PyKota filter.""" |
192 | | def __init__(self) : |
193 | | PyKotaTool.__init__(self) |
194 | | (self.printingsystem, self.printerhostname, self.printername, self.username, self.jobid, self.inputfile, self.copies) = self.extractInfoFromCupsOrLprng() |
195 | | self.accounter = openAccounter(self) |
196 | | |
197 | | def extractInfoFromCupsOrLprng(self) : |
198 | | """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter). |
199 | | |
200 | | Returns (None, None, None, None, None, None, None) if no printing system is recognized. |
201 | | """ |
202 | | # Try to detect CUPS |
203 | | if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : |
204 | | if len(sys.argv) == 7 : |
205 | | inputfile = sys.argv[6] |
206 | | else : |
207 | | inputfile = None |
208 | | |
209 | | device_uri = os.environ.get("DEVICE_URI", "") |
210 | | # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp |
211 | | try : |
212 | | (backend, destination) = device_uri.split(":", 1) |
213 | | except ValueError : |
214 | | raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri |
215 | | while destination.startswith("/") : |
216 | | destination = destination[1:] |
217 | | printerhostname = destination.split("/")[0].split(":")[0] |
218 | | return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile, int(sys.argv[4].strip())) |
219 | | else : |
220 | | # Try to detect LPRng |
221 | | jseen = Pseen = nseen = rseen = Kseen = None |
222 | | for arg in sys.argv : |
223 | | if arg.startswith("-j") : |
224 | | jseen = arg[2:].strip() |
225 | | elif arg.startswith("-n") : |
226 | | nseen = arg[2:].strip() |
227 | | elif arg.startswith("-P") : |
228 | | Pseen = arg[2:].strip() |
229 | | elif arg.startswith("-r") : |
230 | | rseen = arg[2:].strip() |
231 | | elif arg.startswith("-K") or arg.startswith("-#") : |
232 | | Kseen = int(arg[2:].strip()) |
233 | | if Kseen is None : |
234 | | Kseen = 1 # we assume the user wants at least one copy... |
235 | | if (rseen is None) and jseen and Pseen and nseen : |
236 | | self.logger.log_message(_("Printer hostname undefined, set to 'localhost'"), "warn") |
237 | | rseen = "localhost" |
238 | | if jseen and Pseen and nseen and rseen : |
239 | | # job is always in stdin (None) |
240 | | return ("LPRNG", rseen, Pseen, nseen, jseen, None, Kseen) |
241 | | self.logger.log_message(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn") |
242 | | return (None, None, None, None, None, None, None) # Unknown printing system |
243 | | |
| 193 | from pykota.accounter import PyKotaAccounterError |
| 194 | from pykota.requester import PyKotaRequesterError |
| 195 | |
| 196 | class PyKotaFilter(PyKotaFilterOrBackend) : |
| 197 | """A class for the pykota filter.""" |
344 | | except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, AttributeError, KeyError, IndexError, ValueError, TypeError, IOError), msg : |
| 289 | except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, PyKotaRequesterError, AttributeError, KeyError, IndexError, ValueError, TypeError, IOError), msg : |