root / pykota / trunk / pykota / accounter.py @ 973

Revision 973, 2.1 kB (checked in by jalet, 21 years ago)

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2#
3# PyKota : Print Quotas for CUPS and LPRng
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19#
20# $Id$
21#
22# $Log$
23# Revision 1.1  2003/04/29 18:37:54  jalet
24# Pluggable accounting methods (actually doesn't support external scripts)
25#
26#
27#
28
29class PyKotaAccounterError(Exception):
30    """An exception for Accounter related stuff."""
31    def __init__(self, message = ""):
32        self.message = message
33        Exception.__init__(self, message)
34    def __repr__(self):
35        return self.message
36    __str__ = __repr__
37   
38class AccounterBase :   
39    """A class to account print usage by querying printers."""
40    def __init__(self, kotafilter) :
41        """Sets instance vars depending on the current printer."""
42        self.filter = kotafilter
43       
44    def doAccounting(self, printerid, userid) :   
45        """Does the real accounting."""
46        raise PyKotaAccounterError, "Accounter not implemented !"
47       
48def openAccounter(kotafilter) :
49    """Returns a connection handle to the appropriate accounter."""
50    backend = kotafilter.config.getAccounterBackend(kotafilter.printername)
51    try :
52        if not backend.isalpha() :
53            # don't trust user input
54            raise ImportError
55        exec "from pykota.accounters import %s as accounterbackend" % backend.lower()   
56    except ImportError :
57        raise PyKotaAccounterError, _("Unsupported accounter backend %s") % backend
58    else :   
59        return getattr(accounterbackend, "Accounter")(kotafilter)
Note: See TracBrowser for help on using the browser.