134 | | nbsent = self.sock.send(pjlMessage) |
135 | | if nbsent != len(pjlMessage) : |
136 | | raise socket.error, "Short write" |
137 | | except socket.error, msg : |
138 | | self.parent.filter.printInfo(_("Problem while sending PJL query to %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") |
139 | | else : |
140 | | self.parent.filter.logdebug("Query sent to %s : %s" % (self.printerHostname, repr(pjlMessage))) |
141 | | actualpagecount = self.printerStatus = None |
142 | | while (actualpagecount is None) or (self.printerStatus is None) : |
143 | | try : |
144 | | answer = self.queue.get(True, 2) |
145 | | except Queue.Empty : |
146 | | self.parent.filter.logdebug("Timeout when reading printer's answer from %s:%s" % (self.printerHostname, self.port)) |
147 | | else : |
148 | | readnext = False |
149 | | self.parent.filter.logdebug("PJL answer : %s" % repr(answer)) |
150 | | for line in [l.strip() for l in answer.split()] : |
151 | | if line.startswith("CODE=") : |
152 | | self.printerStatus = line.split("=")[1] |
153 | | self.parent.filter.logdebug("Found status : %s" % self.printerStatus) |
154 | | elif line.startswith("PAGECOUNT=") : |
155 | | try : |
156 | | actualpagecount = int(line.split('=')[1].strip()) |
157 | | except ValueError : |
158 | | self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip()) |
159 | | else : |
160 | | self.parent.filter.logdebug("Found pages counter : %s" % actualpagecount) |
161 | | elif line.startswith("PAGECOUNT") : |
162 | | readnext = True # page counter is on next line |
163 | | elif readnext : |
164 | | try : |
165 | | actualpagecount = int(line.strip()) |
166 | | except ValueError : |
167 | | self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip()) |
168 | | else : |
169 | | self.parent.filter.logdebug("Found pages counter : %s" % actualpagecount) |
170 | | readnext = False |
171 | | self.printerInternalPageCounter = max(actualpagecount, self.printerInternalPageCounter) |
| 137 | try : |
| 138 | nbsent = self.sock.send(pjlMessage) |
| 139 | if nbsent != len(pjlMessage) : |
| 140 | raise socket.error, "Short write" |
| 141 | except socket.error, msg : |
| 142 | self.parent.filter.printInfo(_("Problem while sending PJL query to %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") |
| 143 | else : |
| 144 | self.parent.filter.logdebug("Query sent to %s : %s" % (self.printerHostname, repr(pjlMessage))) |
| 145 | actualpagecount = self.printerStatus = None |
| 146 | while (actualpagecount is None) or (self.printerStatus is None) : |
| 147 | try : |
| 148 | answer = self.queue.get(True, 5) |
| 149 | except Queue.Empty : |
| 150 | self.parent.filter.logdebug("Timeout when reading printer's answer from %s:%s" % (self.printerHostname, self.port)) |
| 151 | else : |
| 152 | readnext = False |
| 153 | self.parent.filter.logdebug("PJL answer : %s" % repr(answer)) |
| 154 | for line in [l.strip() for l in answer.split()] : |
| 155 | if line.startswith("CODE=") : |
| 156 | self.printerStatus = line.split("=")[1] |
| 157 | self.parent.filter.logdebug("Found status : %s" % self.printerStatus) |
| 158 | elif line.startswith("PAGECOUNT=") : |
| 159 | try : |
| 160 | actualpagecount = int(line.split('=')[1].strip()) |
| 161 | except ValueError : |
| 162 | self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip()) |
| 163 | else : |
| 164 | self.parent.filter.logdebug("Found pages counter : %s" % actualpagecount) |
| 165 | elif line.startswith("PAGECOUNT") : |
| 166 | readnext = True # page counter is on next line |
| 167 | elif readnext : |
| 168 | try : |
| 169 | actualpagecount = int(line.strip()) |
| 170 | except ValueError : |
| 171 | self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip()) |
| 172 | else : |
| 173 | self.parent.filter.logdebug("Found pages counter : %s" % actualpagecount) |
| 174 | readnext = False |
| 175 | self.printerInternalPageCounter = max(actualpagecount, self.printerInternalPageCounter) |
| 176 | finally : |
| 177 | self.close() |
245 | | try : |
246 | | if (os.environ.get("PYKOTASTATUS") != "CANCELLED") and \ |
247 | | (os.environ.get("PYKOTAACTION") == "ALLOW") and \ |
248 | | (os.environ.get("PYKOTAPHASE") == "AFTER") and \ |
249 | | self.parent.filter.JobSizeBytes : |
250 | | self.waitPrinting() |
251 | | self.waitIdle() |
252 | | except : |
253 | | self.parent.filter.printInfo(_("PJL querying stage interrupted. Using latest value seen for internal page counter (%s) on printer %s.") % (self.printerInternalPageCounter, self.parent.filter.PrinterName), "warn") |
254 | | raise |
255 | | else : |
256 | | return self.printerInternalPageCounter |
257 | | finally : |
258 | | self.close() |
| 248 | if (os.environ.get("PYKOTASTATUS") != "CANCELLED") and \ |
| 249 | (os.environ.get("PYKOTAACTION") == "ALLOW") and \ |
| 250 | (os.environ.get("PYKOTAPHASE") == "AFTER") and \ |
| 251 | self.parent.filter.JobSizeBytes : |
| 252 | self.waitPrinting() |
| 253 | self.waitIdle() |
| 254 | except : |
| 255 | self.parent.filter.printInfo(_("PJL querying stage interrupted. Using latest value seen for internal page counter (%s) on printer %s.") % (self.printerInternalPageCounter, self.parent.filter.PrinterName), "warn") |
| 256 | raise |
| 257 | else : |
| 258 | return self.printerInternalPageCounter |