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

Revision 768, 4.1 kB (checked in by jalet, 21 years ago)

--reset command line option added

  • 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.5  2003/02/08 22:39:46  jalet
18# --reset command line option added
19#
20# Revision 1.4  2003/02/08 09:59:59  jalet
21# Added preliminary base class for all storages
22#
23# Revision 1.3  2003/02/05 22:10:29  jalet
24# Typos
25#
26# Revision 1.2  2003/02/05 22:02:22  jalet
27# __import__ statement didn't work as expected
28#
29# Revision 1.1  2003/02/05 21:28:17  jalet
30# Initial import into CVS
31#
32#
33#
34
35class PyKotaStorageError(Exception):
36    """An exception for Quota Storage related stuff."""
37    def __init__(self, message = ""):
38        self.message = message
39        Exception.__init__(self, message)
40    def __repr__(self):
41        return self.message
42    __str__ = __repr__
43   
44class BaseStorage :   
45    """Base class for all storages."""
46    def getMatchingPrinters(self, printerpattern) :
47        """Returns the list of all printer names which match a certain pattern."""
48        pass
49           
50    def addPrinter(self, printername) :       
51        """Adds a printer to the quota storage."""
52        pass
53       
54    def getPrinterUsers(self, printername) :       
55        """Returns the list of usernames which uses a given printer."""
56        pass
57       
58    def getPrinterGroups(self, printername) :       
59        """Returns the list of groups which uses a given printer."""
60        pass
61       
62    def getPrinterPageCounter(self, printername) :
63        """Returns the last page counter value for a printer given its name."""
64        pass
65       
66    def updatePrinterPageCounter(self, printername, username, pagecount) :
67        """Updates the last page counter information for a printer given its name, last username and pagecount."""
68        pass
69       
70    def addUserPQuota(self, username, printername) :
71        """Initializes a user print quota on a printer, adds the printer and the user to the quota storage if needed."""
72        pass
73       
74    def getUPIds(self, username, printername) :   
75        """Returns a tuple (userid, printerid) given a username and a printername."""
76        pass
77       
78    def getUserPQuota(self, username, printername) :
79        """Returns the Print Quota information for a given (username, printername)."""
80        pass
81       
82    def setUserPQuota(self, username, printername, softlimit, hardlimit) :
83        """Sets soft and hard limits for a user quota on a specific printer given (username, printername)."""
84        pass
85       
86    def resetUserPQuota(self, username, printername) :   
87        """Resets the page counter to zero. Life time page counter is kept unchanged."""
88        pass
89       
90    def setDateLimit(self, username, printername, datelimit) :
91        """Sets the limit date for a soft limit to become an hard one given (username, printername)."""
92        pass
93       
94    def updateUserPQuota(self, username, printername, pagecount) :
95        """Updates the used user Quota information given (username, printername) and a job size in pages."""
96        pass
97       
98    def buyUserPQuota(self, username, printername, pagebought) :
99        """Buys pages for a given (username, printername)."""
100        pass
101       
102def openConnection(config, asadmin=0) :
103    """Returns a connection handle to the appropriate Quota Storage Database."""
104    (backend, host, database, admin, user) = config.getStorageBackend()
105    try :
106        if not backend.isalpha() :
107            # don't trust user input
108            raise ImportError
109        exec "from pykota.storages import %s as storagebackend" % backend.lower()   
110    except ImportError :
111        raise PyKotaStorageError, "Unsupported quota storage backend %s" % backend
112    else :   
113        return getattr(storagebackend, "Storage")(host, database, (asadmin and admin) or user)
Note: See TracBrowser for help on using the browser.