Show
Ignore:
Timestamp:
04/29/03 20:37:54 (21 years ago)
Author:
jalet
Message:

Pluggable accounting methods (actually doesn't support external scripts)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/config.py

    r956 r973  
    2121# 
    2222# $Log$ 
     23# Revision 1.24  2003/04/29 18:37:54  jalet 
     24# Pluggable accounting methods (actually doesn't support external scripts) 
     25# 
    2326# Revision 1.23  2003/04/24 11:53:48  jalet 
    2427# Default policy for unknown users/groups is to DENY printing instead 
     
    139142        self.config = ConfigParser.ConfigParser() 
    140143        self.config.read([self.filename]) 
    141         self.checkConfiguration() 
    142          
    143     def checkConfiguration(self) : 
    144         """Checks if configuration is correct. 
    145          
    146            raises PyKotaConfigError in case a problem is detected 
    147         """ 
    148         validmethods = [ "lazy" ] # TODO add more methods             
    149         if self.config.get("global", "method", raw=1).lower() not in validmethods :              
    150             raise PyKotaConfigError, _("Option method only supports values in %s") % str(validmethods) 
    151144                         
    152145    def getPrinterNames(self) :     
     
    198191        return logger     
    199192         
     193    def getAccounterBackend(self, printer) :     
     194        """Returns the accounter backend to use for a given printer. 
     195         
     196           if it is not set, it defaults to 'querying' which means ask printer 
     197           for its internal lifetime page counter. 
     198        """    
     199        validaccounters = [ "querying" ]      
     200        try : 
     201            accounter = self.getPrinterOption(printer, "accounter").lower() 
     202        except PyKotaConfigError :     
     203            accounter = "querying" 
     204        if accounter not in validaccounters : 
     205            raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printer, str(validaccounters)) 
     206        return accounter 
     207         
    200208    def getRequesterBackend(self, printer) :     
    201209        """Returns the requester backend to use for a given printer, with its arguments.""" 
    202         fullrequester = self.getPrinterOption(printer, "requester") 
    203         try : 
    204             (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] 
    205         except ValueError :     
    206             raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
    207         if args.endswith(')') : 
    208             args = args[:-1] 
    209         if not args : 
    210             raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
    211         validrequesters = [ "snmp", "external" ] # TODO : add more requesters 
    212         if requester not in validrequesters : 
    213             raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) 
    214         return (requester, args) 
     210        try : 
     211            fullrequester = self.getPrinterOption(printer, "requester") 
     212        except PyKotaConfigError :     
     213            # No requester defined, maybe it is not needed if accounting method 
     214            # is not set to 'querying', but if we are called, then the accounting 
     215            # method really IS 'querying', and so there's a big problem. 
     216            raise PyKotaConfigError, _("Option requester for printer %s was not set") % printer 
     217        else :     
     218            try : 
     219                (requester, args) = [x.strip() for x in fullrequester.split('(', 1)] 
     220            except ValueError :     
     221                raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
     222            if args.endswith(')') : 
     223                args = args[:-1] 
     224            if not args : 
     225                raise PyKotaConfigError, _("Invalid requester %s for printer %s") % (fullrequester, printer) 
     226            validrequesters = [ "snmp", "external" ] # TODO : add more requesters 
     227            if requester not in validrequesters : 
     228                raise PyKotaConfigError, _("Option requester for printer %s only supports values in %s") % (printer, str(validrequesters)) 
     229            return (requester, args) 
    215230         
    216231    def getPrinterPolicy(self, printer) :