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