root / pykota / trunk / pykota / storage.py @ 759

Revision 759, 3.8 kB (checked in by jalet, 21 years ago)

Added preliminary base class for all storages

  • 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
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# You're welcome to redistribute this software under the
7# terms of the GNU General Public Licence version 2.0
8# or, at your option, any higher version.
9#
10# You can read the complete GNU GPL in the file COPYING
11# which should come along with this software, or visit
12# the Free Software Foundation's WEB site http://www.fsf.org
13#
14# $Id$
15#
16# $Log$
17# Revision 1.4  2003/02/08 09:59:59  jalet
18# Added preliminary base class for all storages
19#
20# Revision 1.3  2003/02/05 22:10:29  jalet
21# Typos
22#
23# Revision 1.2  2003/02/05 22:02:22  jalet
24# __import__ statement didn't work as expected
25#
26# Revision 1.1  2003/02/05 21:28:17  jalet
27# Initial import into CVS
28#
29#
30#
31
32class PyKotaStorageError(Exception):
33    """An exception for Quota Storage related stuff."""
34    def __init__(self, message = ""):
35        self.message = message
36        Exception.__init__(self, message)
37    def __repr__(self):
38        return self.message
39    __str__ = __repr__
40   
41class BaseStorage :   
42    """Base class for all storages."""
43    def getMatchingPrinters(self, printerpattern) :
44        """Returns the list of all printer names which match a certain pattern."""
45        pass
46           
47    def addPrinter(self, printername) :       
48        """Adds a printer to the quota storage."""
49        pass
50       
51    def getPrinterUsers(self, printername) :       
52        """Returns the list of usernames which uses a given printer."""
53        pass
54       
55    def getPrinterGroups(self, printername) :       
56        """Returns the list of groups which uses a given printer."""
57        pass
58       
59    def getPrinterPageCounter(self, printername) :
60        """Returns the last page counter value for a printer given its name."""
61        pass
62       
63    def updatePrinterPageCounter(self, printername, username, pagecount) :
64        """Updates the last page counter information for a printer given its name, last username and pagecount."""
65        pass
66       
67    def addUserPQuota(self, username, printername) :
68        """Adds a tuple (user, printer) to the Quota Storage, both are also added individually if needed."""
69        pass
70       
71    def getUPIds(self, username, printername) :   
72        """Returns a tuple (userid, printerid) given a username and a printername."""
73        pass
74       
75    def getUserPQuota(self, username, printername) :
76        """Returns the Print Quota information for a given (username, printername)."""
77        pass
78       
79    def setUserPQuota(self, username, printername, softlimit, hardlimit) :
80        """Sets soft and hard limits for a user quota on a specific printer given (username, printername)."""
81        pass
82       
83    def setDateLimit(self, username, printername, datelimit) :
84        """Sets the limit date for a soft limit to become an hard one given (username, printername)."""
85        pass
86       
87    def updateUserPQuota(self, username, printername, pagecount) :
88        """Updates the used user Quota information given (username, printername) and a job size in pages."""
89        pass
90       
91    def buyUserPQuota(self, username, printername, pagebought) :
92        """Buys pages for a given (username, printername)."""
93        pass
94       
95def openConnection(config, asadmin=0) :
96    """Returns a connection handle to the appropriate Quota Storage Database."""
97    (backend, host, database, admin, user) = config.getStorageBackend()
98    try :
99        if not backend.isalpha() :
100            # don't trust user input
101            raise ImportError
102        exec "from pykota.storages import %s as storagebackend" % backend.lower()   
103    except ImportError :
104        raise PyKotaStorageError, "Unsupported quota storage backend %s" % backend
105    else :   
106        return getattr(storagebackend, "Storage")(host, database, (asadmin and admin) or user)
Note: See TracBrowser for help on using the browser.