Changeset 1687 for pykota/trunk/pykota

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/pykota
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • 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."""