Changeset 3523

Show
Ignore:
Timestamp:
04/15/10 12:19:48 (14 years ago)
Author:
jerome
Message:

Should fix #49. This is entirely untested, so please report any problem ASAP.

Location:
tea4cups/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/tea4cups

    r3514 r3523  
    44# Tea4CUPS : Tee for CUPS 
    55# 
    6 # (c) 2005-2009 Jerome Alet <alet@librelogiciel.com> 
     6# (c) 2005-2010 Jerome Alet <alet@librelogiciel.com> 
    77# (c) 2005 Peter Stuge <stuge-tea4cups@cdy.org> 
    88# This program is free software; you can redistribute it and/or modify 
     
    2929Licensing terms : 
    3030 
    31   (c) 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com> 
     31  (c) 2005-2010 Jerome Alet <alet@librelogiciel.com> 
    3232  (c) 2005 Peter Stuge <stuge-tea4cups@cdy.org> 
    3333  This program is free software; you can redistribute it and/or modify 
     
    343343CUPS_PRINTER_OPTIONS = 0xe6ff 
    344344 
     345CUPS_BACKEND_OK = 0 
     346CUPS_BACKEND_FAILED = 1 
     347CUPS_BACKEND_AUTH_REQUIRED = 2 
     348CUPS_BACKEND_HOLD = 3 
     349CUPS_BACKEND_STOP = 4 
     350CUPS_BACKEND_CANCEL = 5 
     351 
    345352class FakeAttribute : 
    346353    """Fakes an IPPRequest attribute to simplify usage syntax.""" 
     
    12901297    def runBranches(self) : 
    12911298        """Launches each hook defined for the current print queue.""" 
    1292         self.isCancelled = 0    # did a prehook cancel the print job ? 
     1299        self.isCancelled = False    # did a prehook cancel the print job ? 
    12931300        serialize = isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) 
    12941301        self.pipes = { 0: (0, 1) } 
     
    12991306        for p in [ (k, v) for (k, v) in self.pipes.items() if k != 0 ] : 
    13001307            os.close(p[1][1]) 
    1301         if not self.isCancelled : 
     1308        if self.isCancelled : 
     1309            retcode = CUPS_BACKEND_CANCEL # Job cancelled, for CUPS. 
     1310        elif retcode == CUPS_BACKEND_OK : 
    13021311            if self.RealBackend : 
    13031312                retcode = self.launchOriginalBackend() 
    1304                 if retcode : 
     1313                if retcode != CUPS_BACKEND_OK : 
    13051314                    onfail = self.getPrintQueueOption(self.PrinterName, \ 
    13061315                                                      "onfail", ignore=1) 
     
    13131322            if self.runCommands("posthook", branches, serialize) : 
    13141323                self.logInfo("An error occured during the execution of posthooks.", "warn") 
    1315         else : 
    1316             retcode = 5 # Job cancelled, for CUPS. 
     1324 
    13171325        for p in [ (k, v) for (k, v) in self.pipes.items() if k != 0 ] : 
    13181326            os.close(p[1][0]) 
    1319         if not retcode : 
     1327        if retcode == CUPS_BACKEND_OK : 
    13201328            self.logInfo("OK") 
    13211329        else : 
     
    13581366    def runCommands(self, btype, branches, serialize) : 
    13591367        """Runs the commands for a particular branch type.""" 
    1360         exitcode = 0 
     1368        exitcode = CUPS_BACKEND_OK 
    13611369        btype = btype.lower() 
    13621370        btypetitle = btype.title() 
     
    13711379                    if (btype == "prehook") and (retcode == 255) : # -1 
    13721380                        self.logInfo("Job %s cancelled by prehook %s" % (self.JobId, branch)) 
    1373                         self.isCancelled = 1 
     1381                        self.isCancelled = True 
     1382                    elif (btype == "prehook") and (retcode == 254) : # -2 
     1383                        self.logInfo("Job %s hook processing stopped by prehook %s" % (self.JobId, branch)) 
     1384                        exitcode = CUPS_BACKEND_FAILED 
     1385                        break 
    13741386                    else : 
    13751387                        self.logInfo("%s %s on printer %s didn't exit successfully." % (btypetitle, branch, self.PrinterName), "error") 
    1376                         exitcode = 1 
     1388                        exitcode = CUPS_BACKEND_FAILED 
    13771389            self.logDebug("End serialized %ss" % btypetitle) 
    13781390        else : 
     
    13951407                    if (btype == "prehook") and (retcode == 255) : # -1 
    13961408                        self.logInfo("Job %s cancelled by prehook %s" % (self.JobId, branch)) 
    1397                         self.isCancelled = 1 
     1409                        self.isCancelled = True 
    13981410                    else : 
    13991411                        self.logInfo("%s %s (PID %s) on printer %s didn't exit successfully." % (btypetitle, branch, pid, self.PrinterName), "error") 
    1400                         exitcode = 1 
     1412                        exitcode = CUPS_BACKEND_FAILED 
    14011413            self.logDebug("End forked %ss" % btypetitle) 
    14021414        return exitcode 
     
    14181430        while 1 : 
    14191431            retcode = self.runOriginalBackend() 
    1420             if not retcode : 
     1432            if retcode == CUPS_BACKEND_OK : 
    14211433                break 
    14221434            else : 
     
    14591471            status = os.WEXITSTATUS(status) 
    14601472            if status : 
    1461                 self.logInfo("CUPS backend %s returned %d." % (originalbackend, \ 
    1462                                                              status), "error") 
     1473                self.logInfo("CUPS backend %s returned %d." % (originalbackend, 
     1474                                                               status), 
     1475                             "error") 
    14631476            return status 
    14641477        elif not killed : 
     
    14671480            return -1 
    14681481        else : 
    1469             return 1 
     1482            return CUPS_BACKEND_FAILED 
    14701483 
    14711484if __name__ == "__main__" : 
  • tea4cups/trunk/tea4cups.conf

    r3478 r3523  
    163163# successfully. Any other value indicates that a problem occured 
    164164# in the CUPS backend which handles the transmission of the job 
    165 # to the printer. 
     165# to the printer. See the output of 'man backend' for details. 
    166166# 
    167167# prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME