Changeset 3180 for pykota/trunk

Show
Ignore:
Timestamp:
05/29/07 23:03:12 (17 years ago)
Author:
jerome
Message:

Now the various delays are configurable when using hardware accounting,
through the newly introduced 'statusstabilizationdelay' and 'statusstabilizationloops'
directives in pykota.conf

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r3169 r3180  
    12741274 
    12751275 
     1276# Defines the number of times the 'idle' printer status 
     1277# has to be reported before it being considered stable. 
     1278# Each check is done every 'statusstabilizationdelay' seconds 
     1279# as defined below. 
     1280# 
     1281# This directive can be set either globally or on a per printer 
     1282# basis.  
     1283# 
     1284# When not set, an hardcoded value of 5 times is used. 
     1285# The value must be a strictly positive integer. 
     1286statusstabilizationloops = 5 
     1287 
     1288 
     1289 
     1290# Defines the number of seconds to wait between two consecutive 
     1291# checks of the printer's status when using hardware accounting. 
     1292# 
     1293# Each check is done up to 'statusstabilizationloops' times. 
     1294# 
     1295# This directive can be set either globally or on a per printer 
     1296# basis.  
     1297# 
     1298# When not set, an hardcoded value of 4.0 seconds is used. 
     1299# The value must be a positive floating point value greater 
     1300# than or equal to 0.25 seconds. 
     1301statusstabilizationdelay = 4.0 
     1302 
     1303 
     1304 
    12761305# Defines a set of coefficients for ink accounting. 
    12771306# 
  • pykota/trunk/pykota/accounters/pjl.py

    r3177 r3180  
    169169    def waitPrinting(self) : 
    170170        """Waits for printer status being 'printing'.""" 
    171         try : 
    172             noprintingmaxdelay = int(self.parent.filter.config.getNoPrintingMaxDelay(self.parent.filter.PrinterName)) 
    173         except (TypeError, AttributeError) : # NB : AttributeError in testing mode because I'm lazy ! 
    174             noprintingmaxdelay = constants.NOPRINTINGMAXDELAY 
    175             self.parent.filter.logdebug("No max delay defined for printer %s, using %i seconds." % (self.parent.filter.PrinterName, noprintingmaxdelay)) 
     171        statusstabilizationdelay = constants.get(self.parent.filter, "StatusStabilizationDelay") 
     172        noprintingmaxdelay = constants.get(self.parent.filter, "NoPrintingMaxDelay") 
    176173        if not noprintingmaxdelay : 
    177174            self.parent.filter.logdebug("Will wait indefinitely until printer %s is in 'printing' state." % self.parent.filter.PrinterName) 
     
    212209                            break 
    213210            self.parent.filter.logdebug(_("Waiting for printer %s to be printing...") % self.parent.filter.PrinterName) 
    214             time.sleep(constants.ITERATIONDELAY) 
     211            time.sleep(statusstabilizationdelay) 
    215212         
    216213    def waitIdle(self) : 
    217214        """Waits for printer status being 'idle'.""" 
     215        statusstabilizationdelay = constants.get(self.parent.filter, "StatusStabilizationDelay") 
     216        statusstabilizationloops = constants.get(self.parent.filter, "StatusStabilizationLoops") 
    218217        idle_num = 0 
    219218        while True : 
     
    226225                    return  
    227226                idle_num += 1 
    228                 if idle_num >= constants.STABILIZATIONDELAY : 
     227                if idle_num >= statusstabilizationloops : 
    229228                    # printer status is stable, we can exit 
    230229                    break 
     
    232231                idle_num = 0 
    233232            self.parent.filter.logdebug(_("Waiting for printer %s's idle status to stabilize...") % self.parent.filter.PrinterName) 
    234             time.sleep(constants.ITERATIONDELAY) 
     233            time.sleep(statusstabilizationdelay) 
    235234     
    236235    def retrieveInternalPageCounter(self) : 
  • pykota/trunk/pykota/accounters/snmp.py

    r3175 r3180  
    154154    def waitPrinting(self) : 
    155155        """Waits for printer status being 'printing'.""" 
    156         try : 
    157             noprintingmaxdelay = int(self.parent.filter.config.getNoPrintingMaxDelay(self.parent.filter.PrinterName)) 
    158         except (TypeError, AttributeError) : # NB : AttributeError in testing mode because I'm lazy ! 
    159             noprintingmaxdelay = constants.NOPRINTINGMAXDELAY 
    160             self.parent.filter.logdebug("No max delay defined for printer %s, using %i seconds." % (self.parent.filter.PrinterName, noprintingmaxdelay)) 
     156        statusstabilizationdelay = constants.get(self.parent.filter, "StatusStabilizationDelay") 
     157        noprintingmaxdelay = constants.get(self.parent.filter, "NoPrintingMaxDelay") 
    161158        if not noprintingmaxdelay : 
    162159            self.parent.filter.logdebug("Will wait indefinitely until printer %s is in 'printing' state." % self.parent.filter.PrinterName) 
     
    203200                            break 
    204201            self.parent.filter.logdebug(_("Waiting for printer %s to be printing...") % self.parent.filter.PrinterName)     
    205             time.sleep(constants.ITERATIONDELAY) 
     202            time.sleep(statusstabilizationdelay) 
    206203         
    207204    def waitIdle(self) : 
    208205        """Waits for printer status being 'idle'.""" 
     206        statusstabilizationdelay = constants.get(self.parent.filter, "StatusStabilizationDelay") 
     207        statusstabilizationloops = constants.get(self.parent.filter, "StatusStabilizationLoops") 
    209208        idle_num = idle_flag = 0 
    210209        while 1 : 
     
    225224                    return  
    226225                idle_num += 1 
    227                 if idle_num >= constants.STABILIZATIONDELAY : 
     226                if idle_num >= statusstabilizationloops : 
    228227                    # printer status is stable, we can exit 
    229228                    break 
     
    231230                idle_num = 0 
    232231            self.parent.filter.logdebug(_("Waiting for printer %s's idle status to stabilize...") % self.parent.filter.PrinterName)     
    233             time.sleep(constants.ITERATIONDELAY) 
     232            time.sleep(statusstabilizationdelay) 
    234233             
    235234    def retrieveInternalPageCounter(self) : 
  • pykota/trunk/pykota/config.py

    r3172 r3180  
    597597                return maxdelay 
    598598         
     599    def getStatusStabilizationLoops(self, printername) :     
     600        """Returns the number of times the printer must return the 'idle' status to consider it stable.""" 
     601        try :  
     602            stab = self.getPrinterOption(printername, "statusstabilizationloops") 
     603        except PyKotaConfigError :     
     604            return None         # tells to use hardcoded value 
     605        else :     
     606            try : 
     607                stab = int(stab) 
     608                if stab < 1 : 
     609                    raise ValueError 
     610            except (TypeError, ValueError) : 
     611                raise PyKotaConfigError, _("Incorrect value %s for the statusstabilizationloops directive in section %s") % (str(stab), printername) 
     612            else :     
     613                return stab 
     614         
     615    def getStatusStabilizationDelay(self, printername) :     
     616        """Returns the number of seconds to wait between two checks of the printer's status.""" 
     617        try :  
     618            stab = self.getPrinterOption(printername, "statusstabilizationdelay") 
     619        except PyKotaConfigError :     
     620            return None         # tells to use hardcoded value 
     621        else :     
     622            try : 
     623                stab = float(stab) 
     624                if stab < 0.25 : 
     625                    raise ValueError 
     626            except (TypeError, ValueError) : 
     627                raise PyKotaConfigError, _("Incorrect value %s for the statusstabilizationdelay directive in section %s") % (str(stab), printername) 
     628            else :     
     629                return stab 
     630         
    599631    def getWinbindSeparator(self) :           
    600632        """Returns the winbind separator's value if it is set, else None.""" 
  • pykota/trunk/pykota/constants.py

    r3175 r3180  
    2424"""This module contains the definitions of constants used by PyKota.""" 
    2525 
    26 ITERATIONDELAY = 4      # time to sleep between two loops 
    27 STABILIZATIONDELAY = 5  # number of consecutive times the idle status must be seen before we consider it to be stable 
     26STATUSSTABILIZATIONDELAY = 4.0 # time to sleep between two loops 
     27STATUSSTABILIZATIONLOOPS = 5  # number of consecutive times the 'idle' status must be seen before we consider it to be stable 
    2828NOPRINTINGMAXDELAY = 60 # The printer must begin to print within 60 seconds by default. 
     29 
     30def get(application, varname) : 
     31    """Retrieves the value of a particular printer variable from configuration file, else a constant defined here.""" 
     32    pname = application.PrinterName 
     33    try : 
     34        value = getattr(application.config, "get%(varname)s" % locals())(pname) 
     35        if value is None : 
     36            raise TypeError     # Use hardcoded value 
     37    except (TypeError, AttributeError) : # NB : AttributeError in testing mode because I'm lazy ! 
     38        value = globals().get(varname.upper()) 
     39        application.logdebug("No value defined for %(varname)s for printer %(pname)s, using %(value)s." % locals()) 
     40    return value