- Timestamp:
- 04/15/10 12:19:48 (15 years ago)
- Location:
- tea4cups/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r3514 r3523 4 4 # Tea4CUPS : Tee for CUPS 5 5 # 6 # (c) 2005-20 09Jerome Alet <alet@librelogiciel.com>6 # (c) 2005-2010 Jerome Alet <alet@librelogiciel.com> 7 7 # (c) 2005 Peter Stuge <stuge-tea4cups@cdy.org> 8 8 # This program is free software; you can redistribute it and/or modify … … 29 29 Licensing terms : 30 30 31 (c) 2005 , 2006, 2007Jerome Alet <alet@librelogiciel.com>31 (c) 2005-2010 Jerome Alet <alet@librelogiciel.com> 32 32 (c) 2005 Peter Stuge <stuge-tea4cups@cdy.org> 33 33 This program is free software; you can redistribute it and/or modify … … 343 343 CUPS_PRINTER_OPTIONS = 0xe6ff 344 344 345 CUPS_BACKEND_OK = 0 346 CUPS_BACKEND_FAILED = 1 347 CUPS_BACKEND_AUTH_REQUIRED = 2 348 CUPS_BACKEND_HOLD = 3 349 CUPS_BACKEND_STOP = 4 350 CUPS_BACKEND_CANCEL = 5 351 345 352 class FakeAttribute : 346 353 """Fakes an IPPRequest attribute to simplify usage syntax.""" … … 1290 1297 def runBranches(self) : 1291 1298 """Launches each hook defined for the current print queue.""" 1292 self.isCancelled = 0# did a prehook cancel the print job ?1299 self.isCancelled = False # did a prehook cancel the print job ? 1293 1300 serialize = isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) 1294 1301 self.pipes = { 0: (0, 1) } … … 1299 1306 for p in [ (k, v) for (k, v) in self.pipes.items() if k != 0 ] : 1300 1307 os.close(p[1][1]) 1301 if not self.isCancelled : 1308 if self.isCancelled : 1309 retcode = CUPS_BACKEND_CANCEL # Job cancelled, for CUPS. 1310 elif retcode == CUPS_BACKEND_OK : 1302 1311 if self.RealBackend : 1303 1312 retcode = self.launchOriginalBackend() 1304 if retcode :1313 if retcode != CUPS_BACKEND_OK : 1305 1314 onfail = self.getPrintQueueOption(self.PrinterName, \ 1306 1315 "onfail", ignore=1) … … 1313 1322 if self.runCommands("posthook", branches, serialize) : 1314 1323 self.logInfo("An error occured during the execution of posthooks.", "warn") 1315 else : 1316 retcode = 5 # Job cancelled, for CUPS. 1324 1317 1325 for p in [ (k, v) for (k, v) in self.pipes.items() if k != 0 ] : 1318 1326 os.close(p[1][0]) 1319 if not retcode:1327 if retcode == CUPS_BACKEND_OK : 1320 1328 self.logInfo("OK") 1321 1329 else : … … 1358 1366 def runCommands(self, btype, branches, serialize) : 1359 1367 """Runs the commands for a particular branch type.""" 1360 exitcode = 01368 exitcode = CUPS_BACKEND_OK 1361 1369 btype = btype.lower() 1362 1370 btypetitle = btype.title() … … 1371 1379 if (btype == "prehook") and (retcode == 255) : # -1 1372 1380 self.logInfo("Job %s cancelled by prehook %s" % (self.JobId, branch)) 1373 self.isCancelled = 1 1381 self.isCancelled = True 1382 elif (btype == "prehook") and (retcode == 254) : # -2 1383 self.logInfo("Job %s hook processing stopped by prehook %s" % (self.JobId, branch)) 1384 exitcode = CUPS_BACKEND_FAILED 1385 break 1374 1386 else : 1375 1387 self.logInfo("%s %s on printer %s didn't exit successfully." % (btypetitle, branch, self.PrinterName), "error") 1376 exitcode = 11388 exitcode = CUPS_BACKEND_FAILED 1377 1389 self.logDebug("End serialized %ss" % btypetitle) 1378 1390 else : … … 1395 1407 if (btype == "prehook") and (retcode == 255) : # -1 1396 1408 self.logInfo("Job %s cancelled by prehook %s" % (self.JobId, branch)) 1397 self.isCancelled = 11409 self.isCancelled = True 1398 1410 else : 1399 1411 self.logInfo("%s %s (PID %s) on printer %s didn't exit successfully." % (btypetitle, branch, pid, self.PrinterName), "error") 1400 exitcode = 11412 exitcode = CUPS_BACKEND_FAILED 1401 1413 self.logDebug("End forked %ss" % btypetitle) 1402 1414 return exitcode … … 1418 1430 while 1 : 1419 1431 retcode = self.runOriginalBackend() 1420 if not retcode:1432 if retcode == CUPS_BACKEND_OK : 1421 1433 break 1422 1434 else : … … 1459 1471 status = os.WEXITSTATUS(status) 1460 1472 if status : 1461 self.logInfo("CUPS backend %s returned %d." % (originalbackend, \ 1462 status), "error") 1473 self.logInfo("CUPS backend %s returned %d." % (originalbackend, 1474 status), 1475 "error") 1463 1476 return status 1464 1477 elif not killed : … … 1467 1480 return -1 1468 1481 else : 1469 return 11482 return CUPS_BACKEND_FAILED 1470 1483 1471 1484 if __name__ == "__main__" : -
tea4cups/trunk/tea4cups.conf
r3478 r3523 163 163 # successfully. Any other value indicates that a problem occured 164 164 # in the CUPS backend which handles the transmission of the job 165 # to the printer. 165 # to the printer. See the output of 'man backend' for details. 166 166 # 167 167 # prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME