Changeset 1687

Show
Ignore:
Timestamp:
09/01/04 01:29:53 (20 years ago)
Author:
jalet
Message:

Introduction of the new 'onaccountererror' configuration directive.
Small fix for software accounter's return code which can't be None anymore.
Make software and hardware accounting code look similar : will be factorized
later.

Location:
pykota/trunk
Files:
7 modified

Legend:

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

    r1622 r1687  
    302302# accounter: hardware(/usr/share/pykota/waitprinter.sh %(printer)s && /usr/bin/snmpget -v1 -c public -Ov %(printer)s mib-2.43.10.2.1.4.1.1 | cut -f 2,2 -d " ") 
    303303accounter: software(/usr/bin/pkpgcounter) 
     304 
     305# What should we do if the accounter's subprocess doesn't return 
     306# a valid result (for example doesn't return an integer on its stdout) 
     307# 
     308# Valid values are : 'continue' and 'stop'. 'stop' is the default 
     309# if unset. 
     310# 
     311# 'continue' means try to process as usual, this may introduce 
     312# accounting errors and free jobs. This was the default behavior 
     313# until v1.20alpha5. 
     314# 
     315# 'stop' means fail and stop the print queue. If an accounter 
     316# error occurs, most of the time this is a misconfiguration, so 
     317# stopping the print queue is usually the better thing to do  
     318# until the admin has fixed the configuration. 
     319# 
     320# This value can be set either globally or on a per printer basis 
     321# If both are defined, the printer option has priority. 
     322# 
     323# onaccountererror: continue 
     324onaccountererror: stop 
    304325 
    305326# Print Quota administrator 
  • pykota/trunk/NEWS

    r1686 r1687  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha5 : 
     25       
     26        - Introduces the new configuration directive 'onaccountererror' 
     27          to specify what must be done whenever the software or 
     28          hardware accounter fails. Allowed values are 'continue' and 
     29          'stop' (default).  
     30           
     31        - Minor fix in software accounter for a recently introduced 
     32          problem. 
     33           
    2434    - 1.20alpha4 : 
    2535     
  • pykota/trunk/pykota/accounter.py

    r1624 r1687  
    2222# 
    2323# $Log$ 
     24# Revision 1.19  2004/08/31 23:29:53  jalet 
     25# Introduction of the new 'onaccountererror' configuration directive. 
     26# Small fix for software accounter's return code which can't be None anymore. 
     27# Make software and hardware accounting code look similar : will be factorized 
     28# later. 
     29# 
    2430# Revision 1.18  2004/07/22 22:41:48  jalet 
    2531# Hardware accounting for LPRng should be OK now. UNTESTED. 
     
    97103        self.filter = kotafilter 
    98104        self.arguments = arguments 
     105        self.onerror = self.filter.config.getPrinterOnAccounterError(self.filter.printername) 
    99106        self.isSoftware = 1 # by default software accounting 
    100107         
  • pykota/trunk/pykota/accounters/hardware.py

    r1685 r1687  
    2222# 
    2323# $Log$ 
     24# Revision 1.11  2004/08/31 23:29:53  jalet 
     25# Introduction of the new 'onaccountererror' configuration directive. 
     26# Small fix for software accounter's return code which can't be None anymore. 
     27# Make software and hardware accounting code look similar : will be factorized 
     28# later. 
     29# 
    2430# Revision 1.10  2004/08/27 22:49:04  jalet 
    2531# No answer from subprocess now is really a fatal error. Waiting for some 
     
    154160        except OSError, msg :     
    155161            self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 
    156         if (pagecounter is not None) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 
    157             return pagecounter 
    158162        else :     
    159             raise PyKotaAccounterError, _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline)  
     163            if os.WIFEXITED(status) : 
     164                status = os.WEXITSTATUS(status) 
     165            self.filter.printInfo(_("Hardware accounter %s exit code is %s") % (self.arguments, str(status))) 
    160166             
     167        if pagecounter is None : 
     168            message = _("Unable to query printer %s via HARDWARE(%s)") % (printer, commandline) 
     169            if self.onerror == "CONTINUE" : 
     170                self.filter.printInfo(message, "error") 
     171            else : 
     172                raise PyKotaAccounterError, message  
     173        return pagecounter         
  • pykota/trunk/pykota/accounters/software.py

    r1680 r1687  
    2222# 
    2323# $Log$ 
     24# Revision 1.10  2004/08/31 23:29:53  jalet 
     25# Introduction of the new 'onaccountererror' configuration directive. 
     26# Small fix for software accounter's return code which can't be None anymore. 
     27# Make software and hardware accounting code look similar : will be factorized 
     28# later. 
     29# 
    2430# Revision 1.9  2004/08/25 22:34:39  jalet 
    2531# Now both software and hardware accounting raise an exception when no valid 
     
    99105         
    100106        try : 
    101             retcode = child.wait() 
     107            status = child.wait() 
    102108        except OSError, msg :     
    103109            self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg)) 
    104110        else :     
    105             if os.WIFEXITED(retcode) : 
    106                 status = os.WEXITSTATUS(retcode) 
    107             else :     
    108                 status = retcode 
     111            if os.WIFEXITED(status) : 
     112                status = os.WEXITSTATUS(status) 
    109113            self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) 
    110114             
    111115        if pagecounter is None :     
    112             raise PyKotaAccounterError, _("Unable to compute job size with accounter %s") % self.arguments 
     116            message = _("Unable to compute job size with accounter %s") % self.arguments 
     117            if self.onerror == "CONTINUE" : 
     118                self.filter.printInfo(message, "error") 
     119            else : 
     120                raise PyKotaAccounterError, message 
    113121             
    114         self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, pagecounter)) 
    115         return pagecounter     
    116              
     122        self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, repr(pagecounter))) 
     123        return pagecounter or 0 
  • pykota/trunk/pykota/config.py

    r1646 r1687  
    2222# 
    2323# $Log$ 
     24# Revision 1.51  2004/08/31 23:29:53  jalet 
     25# Introduction of the new 'onaccountererror' configuration directive. 
     26# Small fix for software accounter's return code which can't be None anymore. 
     27# Make software and hardware accounting code look similar : will be factorized 
     28# later. 
     29# 
    2430# Revision 1.50  2004/07/27 07:07:27  jalet 
    2531# Typo : treshold ==> threshold 
     
    366372            return enforcement     
    367373             
     374    def getPrinterOnAccounterError(self, printername) :     
     375        """Returns what must be done whenever the accounter fails.""" 
     376        validactions = [ "CONTINUE", "STOP" ]      
     377        try : 
     378            action = self.getPrinterOption(printername, "onaccountererror") 
     379        except PyKotaConfigError :     
     380            return "STOP" 
     381        else :     
     382            action = action.upper() 
     383            if action not in validactions : 
     384                raise PyKotaConfigError, _("Option onaccountererror in section %s only supports values in %s") % (printername, str(validactions)) 
     385            return action   
     386             
    368387    def getPrinterPolicy(self, printername) :     
    369388        """Returns the default policy for the current printer.""" 
  • pykota/trunk/pykota/version.py

    r1686 r1687  
    2222# 
    2323 
    24 __version__ = "1.20alpha4_unofficial" 
     24__version__ = "1.20alpha5_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""