- Timestamp:
- 05/24/05 18:10:29 (20 years ago)
- Location:
- tea4cups/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/CREDITS
r611 r636 27 27 28 28 - Anwar Bashir - University of Teesside 29 30 Contributors : 31 -------------- 32 33 The following people contributed to the Tea4CUPS project : 34 35 - Peter Stuge - stuge@cdy.org 29 36 30 37 ============================================================== -
tea4cups/trunk/tea4cups
r635 r636 38 38 from struct import unpack 39 39 40 version = "2.12alpha _unofficial"40 version = "2.12alpha2_unofficial" 41 41 42 42 class TeeError(Exception): … … 124 124 125 125 # Delimiter tags 126 self.tags[ 0x01] = "operation-attributes-tag"127 self.tags[ 0x02] = "job-attributes-tag"128 self.tags[ 0x03] = "end-of-attributes-tag"129 self.tags[ 0x04] = "printer-attributes-tag"130 self.tags[ 0x05] = "unsupported-attributes-tag"126 self.tags[OPERATION_ATTRIBUTES_TAG] = "operation-attributes-tag" 127 self.tags[JOB_ATTRIBUTES_TAG] = "job-attributes-tag" 128 self.tags[END_OF_ATTRIBUTES_TAG] = "end-of-attributes-tag" 129 self.tags[PRINTER_ATTRIBUTES_TAG] = "printer-attributes-tag" 130 self.tags[UNSUPPORTED_ATTRIBUTES_TAG] = "unsupported-attributes-tag" 131 131 132 132 # out of band values … … 582 582 signal.signal(signal.SIGTERM, self.sigtermHandler) 583 583 serialize = self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) 584 self.pipe = os.pipe() 584 585 for branchtype in ["prehook", "tee", "posthook"] : 586 if branchtype == "posthook" : 587 os.close(self.pipe[1]) 585 588 branches = self.enumBranches(self.PrinterName, branchtype) 586 589 status = self.runCommands(branchtype, branches, serialize) … … 594 597 break # We don't want to execute tees or posthooks in this case 595 598 signal.signal(signal.SIGTERM, signal.SIG_IGN) 599 try : 600 os.close(self.pipe[1]) 601 except OSError : 602 pass 603 os.close(self.pipe[0]) 596 604 if not exitcode : 597 605 self.logInfo("OK") … … 599 607 self.logInfo("An error occured, please check CUPS' error_log file.") 600 608 return exitcode 609 610 def pipedSystem(self, cmd, stdin=0, stdout=1) : 611 """Launches a command making a pipe available to it.""" 612 # Code contributed by Peter Stuge on May 23rd 2005 613 pid = os.fork() 614 if pid == 0 : 615 os.dup2(stdin, 0) 616 os.dup2(stdout, 1) 617 os.execl("/bin/sh", "sh", "-c", cmd) 618 os.exit(1) 619 return os.waitpid(pid, 0)[1] 601 620 602 621 def runCommands(self, btype, branches, serialize) : … … 621 640 break 622 641 self.logDebug("Launching %s : %s" % (branch, command)) 623 retcode = os.system(command) 642 if btype != "posthook" : 643 retcode = self.pipedSystem(command, 0, self.pipe[1]) 644 else : 645 retcode = self.pipedSystem(command, self.pipe[0]) 624 646 self.logDebug("Exit code for %s %s on printer %s is %s" % (btype, branch, self.PrinterName, retcode)) 625 647 if os.WIFEXITED(retcode) :