Changeset 598
- Timestamp:
- 03/19/05 11:36:04 (20 years ago)
- Location:
- tea4cups/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/README
r592 r598 33 33 message, all of this by printing it a single time. 34 34 35 Tea4CUPS provides three ways to launch commands : 36 37 - prehooks : these are guaranteed to be launched before the 38 print job is sent to the real printer. 39 40 - tees : these are launched at the same time the job is being 41 sent to the real printer. 42 43 - posthooks : these are guaranteed to be launched after the 44 print job has been sent to the real printer. 45 35 46 To help your own commands, Tea4CUPS makes available as part of the 36 47 environment several variables which can be used as part of the … … 49 60 TEAOPTIONS : Options of the print job. 50 61 TEAINPUTFILE : Print job's data file or empty when job read from stdin. 62 TEASTATUS : Original CUPS backend's exit code : ONLY AVAILABLE FROM 63 post hooks, obviously. 51 64 52 65 In the case you want to use both Tea4CUPS and PyKota, you MUST install -
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 -
tea4cups/trunk/tea4cups.conf
r597 r598 31 31 # The value defined in a print queue section takes precedence over the 32 32 # value defined in the [global] section. 33 # directory : /var/spool/tea4cups/ 33 34 directory : /var/spool/cups/ 34 35 … … 44 45 # Should we serialize the launch of all tees : launch one tee after 45 46 # the other to save some system resources. 46 # Defaults to No if unset, meaning that all tees are launched in47 # Defaults to No if unset, meaning that all tees (or hooks) are launched in 47 48 # parallel. 49 # 50 # NB : in any case, hooks or tees names are sorted alphabetically and 51 # are launched in this sort order (obviously when launched in parallel 52 # this is unnoticeable). 53 # 48 54 # Can be set either in the [global] section or any print queue section. 49 55 # The value defined in a print queue section takes precedence over the … … 100 106 # 101 107 # prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME 102 # posthook_0 : echo "Your print job has been printed " | smbclient -M $TEAUSERNAME108 # posthook_0 : echo "Your print job has been printed with status $TEASTATUS" | smbclient -M $TEAUSERNAME 103 109 104 110 … … 111 117 # value takes precedence 112 118 #tee_0 : cat $TEADATAFILE >~$TEAUSERNAME/savejobs/$TEAJOBID.prn 119 113 120 # An empty value deletes a value defined in the [global] section 114 121 # so this particular tee doesn't get executed. 115 122 #tee_pdf : 123 116 124 # A reflector which produces 4 copies each time : 117 125 #tee_4copies : lp -dotherprinter -n4 $CUPSDATAFILE 126 118 127 # A simple accounting mechanism 119 128 #tee_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log 129 130 # An additionnal posthook : 131 #posthook_dummy : echo "$TEAJOBID : $TEAMD5SUM" >>/tmp/jobmd5sums