202 | | |
203 | | def extractInfoFromCupsOrLprng(self) : |
204 | | """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter). |
205 | | |
206 | | Returns (None, None, None, None, None, None) if no printing system is recognized. |
207 | | """ |
208 | | # Try to detect CUPS |
209 | | if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : |
210 | | if len(sys.argv) == 7 : |
211 | | inputfile = sys.argv[6] |
212 | | else : |
213 | | inputfile = None |
214 | | |
215 | | device_uri = os.environ.get("DEVICE_URI", "") |
216 | | # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp |
217 | | try : |
218 | | (backend, destination) = device_uri.split(":", 1) |
219 | | except ValueError : |
220 | | raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri |
221 | | while destination.startswith("/") : |
222 | | destination = destination[1:] |
223 | | printerhostname = destination.split("/")[0].split(":")[0] |
224 | | return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile) |
225 | | else : |
226 | | # Try to detect LPRng |
227 | | jseen = Jseen = Pseen = nseen = rseen = None |
228 | | for arg in sys.argv : |
229 | | if arg.startswith("-j") : |
230 | | jseen = arg[2:].strip() |
231 | | elif arg.startswith("-J") : |
232 | | Jseen = arg[2:].strip() |
233 | | if Jseen == "(STDIN)" : |
234 | | Jseen = None |
235 | | elif arg.startswith("-n") : |
236 | | nseen = arg[2:].strip() |
237 | | elif arg.startswith("-P") : |
238 | | Pseen = arg[2:].strip() |
239 | | elif arg.startswith("-r") : |
240 | | rseen = arg[2:].strip() |
241 | | if jseen and Pseen and nseen and rseen : |
242 | | return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen) |
243 | | return (None, None, None, None, None, None) # Unknown printing system |