Changeset 973 for pykota/trunk/pykota

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

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

Location:
pykota/trunk/pykota
Files:
4 added
3 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) :     
  • pykota/trunk/pykota/tool.py

    r956 r973  
    2121# 
    2222# $Log$ 
     23# Revision 1.39  2003/04/29 18:37:54  jalet 
     24# Pluggable accounting methods (actually doesn't support external scripts) 
     25# 
    2326# Revision 1.38  2003/04/24 11:53:48  jalet 
    2427# Default policy for unknown users/groups is to DENY printing instead 
     
    200203        self.storage = storage.openConnection(self.config, asadmin=asadmin) 
    201204        self.smtpserver = self.config.getSMTPServer() 
    202          
    203     def extractInfoFromCupsOrLprng(self) :     
    204         """Returns a tuple (printingsystem, printerhostname, printername, username, jobid, filename) depending on the printing system in use (as seen by the print filter). 
    205          
    206            Returns (None, None, None, None, None, None) if no printing system is recognized. 
    207         """ 
    208         # Try to detect CUPS 
    209         if os.environ.has_key("CUPS_SERVERROOT") and os.path.isdir(os.environ.get("CUPS_SERVERROOT", "")) : 
    210             if len(sys.argv) == 7 : 
    211                 inputfile = sys.argv[6] 
    212             else :     
    213                 inputfile = None 
    214                  
    215             device_uri = os.environ.get("DEVICE_URI", "") 
    216             # TODO : check this for more complex urls than ipp://myprinter.dot.com:631/printers/lp 
    217             try : 
    218                 (backend, destination) = device_uri.split(":", 1)  
    219             except ValueError :     
    220                 raise PyKotaToolError, "Invalid DEVICE_URI : %s\n" % device_uri 
    221             while destination.startswith("/") : 
    222                 destination = destination[1:] 
    223             printerhostname = destination.split("/")[0].split(":")[0] 
    224             return ("CUPS", printerhostname, os.environ.get("PRINTER"), sys.argv[2].strip(), sys.argv[1].strip(), inputfile) 
    225         else :     
    226             # Try to detect LPRng 
    227             jseen = Jseen = Pseen = nseen = rseen = None 
    228             for arg in sys.argv : 
    229                 if arg.startswith("-j") : 
    230                     jseen = arg[2:].strip() 
    231                 elif arg.startswith("-J") :     
    232                     Jseen = arg[2:].strip() 
    233                     if Jseen == "(STDIN)" : 
    234                         Jseen = None 
    235                 elif arg.startswith("-n") :      
    236                     nseen = arg[2:].strip() 
    237                 elif arg.startswith("-P") :     
    238                     Pseen = arg[2:].strip() 
    239                 elif arg.startswith("-r") :     
    240                     rseen = arg[2:].strip() 
    241             if jseen and Pseen and nseen and rseen :         
    242                 return ("LPRNG", rseen, Pseen, nseen, jseen, Jseen) 
    243         return (None, None, None, None, None, None)   # Unknown printing system           
    244205         
    245206    def display_version_and_quit(self) : 
  • pykota/trunk/pykota/version.py

    r962 r973  
    2121# 
    2222 
    23 __version__ = "1.05alpha1-unofficial" 
     23__version__ = "1.05alpha2-unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""