Changeset 3158 for pykota

Show
Ignore:
Timestamp:
03/30/07 22:59:54 (18 years ago)
Author:
matt
Message:

Allow configuration to avoid printing banner pages for consecutive jobs for the same user on the same printer

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r3153 r3158  
    833833                self.logdebug("Print job cancelled, not printing a banner.", "warn") 
    834834            else : 
    835                 getattr(self, "%sBanner" % bannertype)(withaccounting) 
     835                self.logdebug("Checking if job owner printed the last job and if another banner is needed...") 
     836                # Print the banner by default 
     837                printbanner = True 
     838                avoidduplicatebanners = self.config.getAvoidDuplicateBanners(self.PrinterName) 
     839                if ((avoidduplicatebanners == "NO") or (avoidduplicatebanners == 0)): 
     840                    self.logdebug("We want all banners to be printed.") 
     841                else : 
     842                    # Check if we should deny the banner or not 
     843                    if self.Printer.LastJob.Exists \ 
     844                            and (self.Printer.LastJob.UserName == self.UserName) : 
     845                        if (avoidduplicatebanners == "YES") : 
     846                            printbanner = False 
     847                        else :     
     848                            # avoidduplicatebanners is an integer, since NO,  
     849                            # YES and 0 are already handled 
     850                            now = DateTime.now() 
     851                            try : 
     852                                previous = DateTime.ISO.ParseDateTime(str(self.Printer.LastJob.JobDate)[:19]).localtime() 
     853                            except : 
     854                                previous = now 
     855                            difference = (now - previous).seconds 
     856                            self.logdebug("Difference with previous job : %.2f seconds. Try to avoid banners for : %.2f seconds." % (difference, avoidduplicatebanners)) 
     857                            if difference < avoidduplicatebanners : 
     858                                self.logdebug("Duplicate banner avoided because previous banner is less than %.2f seconds old." % avoidduplicatebanners)  
     859                                printbanner = False 
     860                            else : 
     861                                printbanner = True 
     862                if printbanner : 
     863                    getattr(self, "%sBanner" % bannertype)(withaccounting) 
    836864        self.logdebug("%s banner done." % bannertype.title()) 
    837865         
  • pykota/trunk/conf/pykota.conf.sample

    r3148 r3158  
    10591059 
    10601060 
     1061# If a job is printed by the same person as the last job on the same printer,  
     1062# should banners be avoided to save some paper 
     1063# 
     1064# This option can be set either globally or on a per printer basis. 
     1065# If set to yes, any duplicate banners will be avoided forever 
     1066# If set to no or 0, no banners will be avoided (they will all be printed) 
     1067# If set to any positive integer, banners will be avoided if printed within 
     1068#     'integer' seconds of the last job  
     1069# 
     1070# This value defaults to no 
     1071# avoidduplicatebanners: yes 
     1072# avoidduplicatebanners: no 
     1073# avoidduplicatebanners: 600    
     1074 
     1075 
    10611076# StartingBanner : if defined will print a banner before the rest of the job  
    10621077# is printed. The argument can be a printable file, or an executable file. 
  • pykota/trunk/pykota/config.py

    r3133 r3158  
    603603            return value   
    604604 
     605    def getAvoidDuplicateBanners(self, printername) : 
     606        """Returns normalized value for avoiding extra banners. """ 
     607        try : 
     608            avoidduplicatebanners = self.getPrinterOption(printername, "avoidduplicatebanners").upper() 
     609        except PyKotaConfigError : 
     610            return "NO" 
     611        else : 
     612            try : 
     613                value = int(avoidduplicatebanners) 
     614                if value < 0 : 
     615                    raise ValueError 
     616            except ValueError : 
     617                if avoidduplicatebanners not in ["YES", "NO"] : 
     618                    raise PyKotaConfigError, _("Option avoidduplicatebanners only accepts 'yes', 'no', or a positive integer.") 
     619                else : 
     620                    value = avoidduplicatebanners 
     621            return value 
     622 
    605623    def getStartingBanner(self, printername) : 
    606624        """Returns the startingbanner value if set, else None."""