Changeset 598 for tea4cups/trunk/tea4cups
- Timestamp:
- 03/19/05 11:36:04 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r597 r598 527 527 528 528 def runBranches(self) : 529 """Launches each tee defined for the current print queue."""529 """Launches each hook or tee defined for the current print queue.""" 530 530 exitcode = 0 531 531 signal.signal(signal.SIGTERM, self.sigtermHandler) 532 prehooks = self.enumBranches(self.PrinterName, "prehook") 533 branches = self.enumBranches(self.PrinterName, "tee") 534 prehooks = self.enumBranches(self.PrinterName, "posthook") 535 if self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) : 536 self.logDebug("Serialized Tees") 537 if self.RealBackend : 532 serialize = self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) 533 for branchtype in ["prehook", "tee", "posthook"] : 534 branches = self.enumBranches(self.PrinterName, branchtype) 535 status = self.runCommands(branchtype, branches, serialize) 536 if status : 537 exitcode = status 538 signal.signal(signal.SIGTERM, signal.SIG_IGN) 539 return exitcode 540 541 def runCommands(self, btype, branches, serialize) : 542 """Runs the commands for a particular branch type.""" 543 exitcode = 0 544 btype = btype.lower() 545 btypetitle = btype.title() 546 branchlist = branches.keys() 547 branchlist.sort() 548 if serialize : 549 self.logDebug("Serialized %ss" % btypetitle) 550 if (btype == "tee") and self.RealBackend : 538 551 self.logDebug("Launching original backend %s for printer %s" % (self.RealBackend, self.PrinterName)) 539 552 exitcode = self.runOriginalBackend() 540 for (branch, command) in branches.items() : 553 for branch in branchlist : 554 command = branches[branch] 541 555 if self.gotSigTerm : 542 556 break 543 557 self.logDebug("Launching %s : %s" % (branch, command)) 544 558 retcode = os.system(command) 545 self.logDebug("Exit code for tee %s on printer %s is %s" % (branch, self.PrinterName, retcode))559 self.logDebug("Exit code for %s %s on printer %s is %s" % (btype, branch, self.PrinterName, retcode)) 546 560 if os.WIFEXITED(retcode) : 547 561 retcode = os.WEXITSTATUS(retcode) 548 562 if retcode : 549 self.logInfo(" Tee %s on printer %s didn't exit successfully." % (branch, self.PrinterName), "error")563 self.logInfo("%s %s on printer %s didn't exit successfully." % (btypetitle, branch, self.PrinterName), "error") 550 564 exitcode = 1 551 565 else : 552 self.logDebug("Forked Tees")566 self.logDebug("Forked %ss" % btypetitle) 553 567 pids = {} 554 if self.RealBackend :568 if (btype == "tee") and self.RealBackend : 555 569 branches["Original backend"] = None # Fakes a tee to launch one more child 556 for (branch, command) in branches.items() : 570 branchlist = ["Original backend"] + branchlist 571 for branch in branchlist : 572 command = branches[branch] 557 573 if self.gotSigTerm : 558 574 break … … 574 590 for (branch, pid) in pids.items() : 575 591 (childpid, retcode) = os.waitpid(pid, 0) 576 self.logDebug("Exit code for tee %s (PID %s) on printer %s is %s" % (branch, childpid, self.PrinterName, retcode))592 self.logDebug("Exit code for %s %s (PID %s) on printer %s is %s" % (btype, branch, childpid, self.PrinterName, retcode)) 577 593 if os.WIFEXITED(retcode) : 578 594 retcode = os.WEXITSTATUS(retcode) 579 595 if retcode : 580 self.logInfo(" Tee %s (PID %s) on printer %s didn't exit successfully." % (branch, childpid, self.PrinterName), "error")596 self.logInfo("%s %s (PID %s) on printer %s didn't exit successfully." % (btypetitle, branch, childpid, self.PrinterName), "error") 581 597 exitcode = 1 582 signal.signal(signal.SIGTERM, signal.SIG_IGN) 598 if branch == "Original backend" : 599 os.environ["TEASTATUS"] = str(retcode) 583 600 return exitcode 584 601