Changeset 597 for tea4cups

Show
Ignore:
Timestamp:
03/16/05 21:16:13 (20 years ago)
Author:
jerome
Message:

Did some work for pre and post hooks

Location:
tea4cups/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/tea4cups

    r590 r597  
    3737from struct import unpack 
    3838 
    39 version = "1.00" 
     39version = "1.5alpha" 
    4040 
    4141class TeeError(Exception): 
     
    278278                raise ConfigError, "Option %s not found in section [%s] of %s" % (option, printqueuename, self.conffile) 
    279279                 
    280     def enumTeeBranches(self, printqueuename) : 
    281         """Returns the list of branches for a particular section's Tee.""" 
    282         try : 
    283             globalbranches = [ (k, v) for (k, v) in self.config.items("global") if k.startswith("tee_") ] 
     280    def enumBranches(self, printqueuename, branchtype="tee") : 
     281        """Returns the list of branchtypes branches for a particular section's.""" 
     282        branchbasename = "%s_" % branchtype.lower() 
     283        try : 
     284            globalbranches = [ (k, v) for (k, v) in self.config.items("global") if k.startswith(branchbasename) ] 
    284285        except ConfigParser.NoSectionError, msg :     
    285286            raise ConfigError, "Invalid configuration file : %s" % msg 
    286287        try : 
    287             sectionbranches = [ (k, v) for (k, v) in self.config.items(printqueuename) if k.startswith("tee_") ] 
     288            sectionbranches = [ (k, v) for (k, v) in self.config.items(printqueuename) if k.startswith(branchbasename) ] 
    288289        except ConfigParser.NoSectionError, msg :     
    289290            self.logInfo("No section for print queue %s : %s" % (printqueuename, msg)) 
     
    529530        exitcode = 0 
    530531        signal.signal(signal.SIGTERM, self.sigtermHandler) 
    531         branches = self.enumTeeBranches(self.PrinterName) 
     532        prehooks = self.enumBranches(self.PrinterName, "prehook") 
     533        branches = self.enumBranches(self.PrinterName, "tee") 
     534        prehooks = self.enumBranches(self.PrinterName, "posthook") 
    532535        if self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) : 
    533536            self.logDebug("Serialized Tees") 
  • tea4cups/trunk/tea4cups.conf

    r586 r597  
    4949# The value defined in a print queue section takes precedence over the 
    5050# value defined in the [global] section. 
     51# This value also applies to prehooks and posthooks (see below) 
    5152# serialize : yes 
    5253 
    53 # When executing the contents of a tee directive, tea4cups makes 
    54 # the following environment variables available to your own commands : 
     54# When executing the contents of a tee, prehook or posthook directive,  
     55# tea4cups makes the following environment variables available to your 
     56# own commands : 
    5557# 
    5658# TEAPRINTERNAME : The print queue name. 
     
    7274         
    7375# Now defines some default tees which will always be launched 
     76# at the same time that the job's datas are being sent to the  
     77# printer. 
    7478# The tee names are completely free BUT THEY MUST BEGIN WITH 'tee_' 
    7579# 
     
    7781#tee_0 : cat $TEADATAFILE >/tmp/$TEAJOBID.prn 
    7882#tee_pdf : cat $TEADATAFILE | su -c "lp -dPDFGenerator" $TEAUSERNAME 
     83 
     84# Some hooks : prehooks and posthooks 
     85# 
     86# Contrary to tees, prehooks are guaranteed to be launched  
     87# BEFORE the job's datas are sent to the printer, and  
     88# posthooks are guaranteed to be launched AFTER the job's 
     89# datas have been sent to the printer. 
     90# 
     91# prehook names are completely free BUT THEY MUST BEGIN WITH 'prehook_' 
     92# posthook names are completely free BUT THEY MUST BEGIN WITH 'posthook_' 
     93# 
     94# An additionnal environment variable is made available to posthooks, 
     95# named TEASTATUS which contains the exitcode of the real CUPS backend. 
     96# The normal value is 0, meaning that the real CUPS backend exited 
     97# successfully. Any other value indicates that a problem occured 
     98# in the CUPS backend which handles the transmission of the job 
     99# to the printer. 
     100#  
     101# prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME 
     102# posthook_0 : echo "Your print job has been printed" | smbclient -M $TEAUSERNAME 
     103 
    79104 
    80105# Sample section for print queue HP2100