98 | | class PyKotaBackend(PyKotaTool) : |
99 | | """Class for the PyKota backend.""" |
100 | | def __init__(self) : |
101 | | PyKotaTool.__init__(self) |
102 | | (self.printingsystem, \ |
103 | | self.printerhostname, \ |
104 | | self.printername, \ |
105 | | self.username, \ |
106 | | self.jobid, \ |
107 | | self.inputfile, \ |
108 | | self.copies, \ |
109 | | self.title, \ |
110 | | self.options, \ |
111 | | self.originalbackend) = self.extractCUPSInfo() |
112 | | self.accounter = openAccounter(self) |
113 | | |
114 | | def extractCUPSInfo(self) : |
115 | | """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename, title, options, backend). |
116 | | |
117 | | Returns (None, None, None, None, None, None, None, None, None, None) if no printing system is recognized. |
118 | | """ |
119 | | # Try to detect CUPS |
120 | | if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : |
121 | | if len(sys.argv) == 7 : |
122 | | inputfile = sys.argv[6] |
123 | | else : |
124 | | inputfile = None |
125 | | |
126 | | # the DEVICE_URI environment variable's value is |
127 | | # prefixed with "cupspykota:" otherwise we wouldn't |
128 | | # be called. We have to remove this from the environment |
129 | | # before launching the real backend. |
130 | | fulldevice_uri = os.environ.get("DEVICE_URI", "") |
131 | | device_uri = fulldevice_uri[len("cupspykota:"):] |
132 | | if device_uri.startswith("//") : # lpd (at least) |
133 | | device_uri = device_uri[2:] |
134 | | os.environ["DEVICE_URI"] = device_uri |
135 | | # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp |
136 | | try : |
137 | | (backend, destination) = device_uri.split(":", 1) |
138 | | except ValueError : |
139 | | raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri |
140 | | while destination.startswith("/") : |
141 | | destination = destination[1:] |
142 | | printerhostname = destination.split("/")[0].split(":")[0] |
143 | | return ("CUPS", \ |
144 | | printerhostname, \ |
145 | | os.environ.get("PRINTER"), \ |
146 | | sys.argv[2].strip(), \ |
147 | | sys.argv[1].strip(), \ |
148 | | inputfile, \ |
149 | | int(sys.argv[4].strip()), \ |
150 | | sys.argv[3], \ |
151 | | sys.argv[5], \ |
152 | | backend) |
153 | | else : |
154 | | self.logger.log_message(_("Printing system unknown, args=%s") % " ".join(sys.argv), "warn") |
155 | | return (None, None, None, None, None, None, None, None, None, None) # Unknown printing system |
156 | | |
157 | | def format_commandline(prt, usr, cmdline) : |
158 | | """Passes printer and user names on the command line.""" |
159 | | printer = prt.Name |
160 | | user = usr.Name |
161 | | # we don't want the external command's standard |
162 | | # output to break the print job's data, but we |
163 | | # want to keep its standard error |
164 | | return "%s >/dev/null" % (cmdline % locals()) |
165 | | |
476 | | except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, AttributeError, KeyError, IndexError, ValueError, TypeError, IOError), msg : |
| 413 | except (PyKotaToolError, PyKotaConfigError, PyKotaStorageError, PyKotaAccounterError, PyKotaRequesterError, AttributeError, KeyError, IndexError, ValueError, TypeError, IOError), msg : |