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