Changeset 636 for tea4cups

Show
Ignore:
Timestamp:
05/24/05 18:10:29 (19 years ago)
Author:
jerome
Message:

Integrated Peter Stuge's patch to allow the creation of pipes between pre and post hooks

Location:
tea4cups/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/CREDITS

    r611 r636  
    2727   
    2828  - Anwar Bashir - University of Teesside 
     29   
     30Contributors : 
     31-------------- 
     32 
     33  The following people contributed to the Tea4CUPS project : 
     34   
     35  - Peter Stuge - stuge@cdy.org 
    2936 
    3037============================================================== 
  • tea4cups/trunk/tea4cups

    r635 r636  
    3838from struct import unpack 
    3939 
    40 version = "2.12alpha_unofficial" 
     40version = "2.12alpha2_unofficial" 
    4141 
    4242class TeeError(Exception): 
     
    124124         
    125125        # 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" 
    131131         
    132132        # out of band values 
     
    582582        signal.signal(signal.SIGTERM, self.sigtermHandler) 
    583583        serialize = self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) 
     584        self.pipe = os.pipe() 
    584585        for branchtype in ["prehook", "tee", "posthook"] : 
     586            if branchtype == "posthook" : 
     587                os.close(self.pipe[1]) 
    585588            branches = self.enumBranches(self.PrinterName, branchtype) 
    586589            status = self.runCommands(branchtype, branches, serialize) 
     
    594597                break # We don't want to execute tees or posthooks in this case 
    595598        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]) 
    596604        if not exitcode : 
    597605            self.logInfo("OK") 
     
    599607            self.logInfo("An error occured, please check CUPS' error_log file.") 
    600608        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] 
    601620         
    602621    def runCommands(self, btype, branches, serialize) :     
     
    621640                    break 
    622641                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]) 
    624646                self.logDebug("Exit code for %s %s on printer %s is %s" % (btype, branch, self.PrinterName, retcode)) 
    625647                if os.WIFEXITED(retcode) :