- Timestamp:
- 03/13/05 18:22:22 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r583 r584 25 25 import sys 26 26 import os 27 import popen2 27 28 import errno 28 29 import md5 … … 50 51 pass 51 52 53 class Popen4ForCUPS(popen2.Popen4) : 54 """Our own class to execute real backends. 55 56 Their first argument is different from their path so using 57 native popen2.Popen3 would not be feasible. 58 """ 59 def __init__(self, cmd, bufsize=-1, arg0=None) : 60 self.arg0 = arg0 61 popen2.Popen4.__init__(self, cmd, bufsize) 62 63 def _run_child(self, cmd): 64 try : 65 MAXFD = os.sysconf("SC_OPEN_MAX") 66 except (AttributeError, ValueError) : 67 MAXFD = 256 68 for i in range(3, MAXFD) : 69 try: 70 os.close(i) 71 except OSError: 72 pass 73 try: 74 os.execvpe(cmd[0], [self.arg0 or cmd[0]] + cmd[1:], os.environ) 75 finally: 76 os._exit(1) 77 52 78 # Some IPP constants 53 79 OPERATION_ATTRIBUTES_TAG = 0x01 … … 211 237 """Logs something to debug output if debug is enabled.""" 212 238 if self.debug : 213 sys.stderr.write("DEBUG: %s (PID %i) : %s\n" % (self.MyName, self.pid, message))239 sys.stderr.write("DEBUG: %s (PID %i) : %s\n" % (self.MyName, os.getpid(), message)) 214 240 sys.stderr.flush() 215 241 216 242 def logInfo(self, message, level="info") : 217 243 """Logs a message to CUPS' error_log file.""" 218 sys.stderr.write("%s: %s (PID %i) : %s\n" % (level.upper(), self.MyName, self.pid, message))244 sys.stderr.write("%s: %s (PID %i) : %s\n" % (level.upper(), self.MyName, os.getpid(), message)) 219 245 sys.stderr.flush() 220 246 … … 487 513 def runBranches(self) : 488 514 """Launches each tee defined for the current print queue.""" 515 exitcode = 0 489 516 branches = self.enumTeeBranches(self.PrinterName) 490 517 if self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) : 518 self.logDebug("Serialized Tees") 491 519 for (branch, command) in branches.items() : 492 520 self.logDebug("Launching %s : %s" % (branch, command)) 493 os.system(command) 521 retcode = os.system(command) 522 self.logDebug("Exit code for tee %s on printer %s is %s" % (branch, self.PrinterName, retcode)) 523 if os.WIFEXITED(retcode) : 524 retcode = os.WEXITSTATUS(retcode) 525 if retcode : 526 self.logInfo("Tee %s on printer %s didn't exit successfully." % (branch, self.PrinterName), "error") 527 exitcode = 1 494 528 else : 495 raise TeeError, "Forking tees not yet implemented." 529 self.logDebug("Forked Tees") 530 pids = {} 531 for (branch, command) in branches.items() : 532 pid = os.fork() 533 if pid : 534 pids[branch] = pid 535 else : 536 self.logDebug("Launching %s : %s" % (branch, command)) 537 retcode = os.system(command) 538 if os.WIFEXITED(retcode) : 539 retcode = os.WEXITSTATUS(retcode) 540 else : 541 retcode = -1 542 sys.exit(retcode) 543 for (branch, pid) in pids.items() : 544 (childpid, retcode) = os.waitpid(pid, 0) 545 self.logDebug("Exit code for tee %s (PID %s) on printer %s is %s" % (branch, childpid, self.PrinterName, retcode)) 546 if os.WIFEXITED(retcode) : 547 retcode = os.WEXITSTATUS(retcode) 548 if retcode : 549 self.logInfo("Tee %s (PID %s) on printer %s didn't exit successfully." % (branch, childpid, self.PrinterName), "error") 550 exitcode = 1 551 return exitcode 496 552 497 553 if __name__ == "__main__" :