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.2 2003/04/27 08:27:34 jalet |
---|
24 | # connection to LDAP backend |
---|
25 | # |
---|
26 | # Revision 1.1 2003/04/27 08:04:15 jalet |
---|
27 | # LDAP storage backend's skeleton added. DOESN'T WORK. |
---|
28 | # |
---|
29 | # |
---|
30 | # |
---|
31 | |
---|
32 | import fnmatch |
---|
33 | |
---|
34 | from pykota.storage import PyKotaStorageError |
---|
35 | |
---|
36 | try : |
---|
37 | import ldap |
---|
38 | except ImportError : |
---|
39 | import sys |
---|
40 | # TODO : to translate or not to translate ? |
---|
41 | raise PyKotaStorageError, "This python version (%s) doesn't seem to have the python-ldap module installed correctly." % sys.version.split()[0] |
---|
42 | |
---|
43 | class Storage : |
---|
44 | def __init__(self, host, dbname, user, passwd) : |
---|
45 | """Opens the LDAP connection.""" |
---|
46 | raise PyKotaStorageError, "Sorry, the LDAP backend for PyKota is not yet implemented !" |
---|
47 | self.closed = 1 |
---|
48 | try : |
---|
49 | self.database = ldap.initialize(host) |
---|
50 | self.database.simple_bind_s(user, passwd) |
---|
51 | # TODO : dbname will be the base dn |
---|
52 | except ldap.SERVER_DOWN : |
---|
53 | raise PyKotaStorageError, "LDAP backend for PyKota seems to be down !" # TODO : translate |
---|
54 | else : |
---|
55 | self.closed = 0 |
---|
56 | |
---|
57 | def __del__(self) : |
---|
58 | """Closes the database connection.""" |
---|
59 | if not self.closed : |
---|
60 | del self.database |
---|
61 | self.closed = 1 |
---|
62 | |
---|
63 | def doQuery(self, query) : |
---|
64 | """Does a query.""" |
---|
65 | pass |
---|
66 | |
---|
67 | def doQuote(self, field) : |
---|
68 | """Quotes a field for use as a string in LDAP queries.""" |
---|
69 | pass |
---|
70 | |
---|
71 | def doParseResult(self, result) : |
---|
72 | """Returns the result as a list of Python mappings.""" |
---|
73 | pass |
---|
74 | |
---|
75 | def getMatchingPrinters(self, printerpattern) : |
---|
76 | """Returns the list of all printers as tuples (id, name) for printer names which match a certain pattern.""" |
---|
77 | pass |
---|
78 | |
---|
79 | def getPrinterId(self, printername) : |
---|
80 | """Returns a printerid given a printername.""" |
---|
81 | pass |
---|
82 | |
---|
83 | def getPrinterPrices(self, printerid) : |
---|
84 | """Returns a printer prices per page and per job given a printerid.""" |
---|
85 | pass |
---|
86 | |
---|
87 | def setPrinterPrices(self, printerid, perpage, perjob) : |
---|
88 | """Sets prices per job and per page for a given printer.""" |
---|
89 | pass |
---|
90 | |
---|
91 | def getUserId(self, username) : |
---|
92 | """Returns a userid given a username.""" |
---|
93 | pass |
---|
94 | |
---|
95 | def getGroupId(self, groupname) : |
---|
96 | """Returns a groupid given a grupname.""" |
---|
97 | pass |
---|
98 | |
---|
99 | def getJobHistoryId(self, jobid, userid, printerid) : |
---|
100 | """Returns the history line's id given a (jobid, userid, printerid).""" |
---|
101 | pass |
---|
102 | |
---|
103 | def getPrinterUsers(self, printerid) : |
---|
104 | """Returns the list of usernames which uses a given printer.""" |
---|
105 | pass |
---|
106 | |
---|
107 | def getPrinterGroups(self, printerid) : |
---|
108 | """Returns the list of groups which uses a given printer.""" |
---|
109 | pass |
---|
110 | |
---|
111 | def getGroupMembersNames(self, groupname) : |
---|
112 | """Returns the list of user's names which are member of this group.""" |
---|
113 | pass |
---|
114 | |
---|
115 | def getUserGroupsNames(self, userid) : |
---|
116 | """Returns the list of groups' names the user is a member of.""" |
---|
117 | pass |
---|
118 | |
---|
119 | def addPrinter(self, printername) : |
---|
120 | """Adds a printer to the quota storage, returns its id.""" |
---|
121 | pass |
---|
122 | |
---|
123 | def addUser(self, username) : |
---|
124 | """Adds a user to the quota storage, returns its id.""" |
---|
125 | pass |
---|
126 | |
---|
127 | def addGroup(self, groupname) : |
---|
128 | """Adds a group to the quota storage, returns its id.""" |
---|
129 | pass |
---|
130 | |
---|
131 | def addUserPQuota(self, username, printerid) : |
---|
132 | """Initializes a user print quota on a printer, adds the user to the quota storage if needed.""" |
---|
133 | pass |
---|
134 | |
---|
135 | def addGroupPQuota(self, groupname, printerid) : |
---|
136 | """Initializes a group print quota on a printer, adds the group to the quota storage if needed.""" |
---|
137 | pass |
---|
138 | |
---|
139 | def increaseUserBalance(self, userid, amount) : |
---|
140 | """Increases (or decreases) an user's account balance by a given amount.""" |
---|
141 | pass |
---|
142 | |
---|
143 | def getUserBalance(self, userid) : |
---|
144 | """Returns the current account balance for a given user.""" |
---|
145 | pass |
---|
146 | |
---|
147 | def getGroupBalance(self, groupid) : |
---|
148 | """Returns the current account balance for a given group, as the sum of each of its users' account balance.""" |
---|
149 | pass |
---|
150 | |
---|
151 | def getUserLimitBy(self, userid) : |
---|
152 | """Returns the way in which user printing is limited.""" |
---|
153 | pass |
---|
154 | |
---|
155 | def getGroupLimitBy(self, groupid) : |
---|
156 | """Returns the way in which group printing is limited.""" |
---|
157 | pass |
---|
158 | |
---|
159 | def setUserBalance(self, userid, balance) : |
---|
160 | """Sets the account balance for a given user to a fixed value.""" |
---|
161 | pass |
---|
162 | |
---|
163 | def limitUserBy(self, userid, limitby) : |
---|
164 | """Limits a given user based either on print quota or on account balance.""" |
---|
165 | pass |
---|
166 | |
---|
167 | def limitGroupBy(self, groupid, limitby) : |
---|
168 | """Limits a given group based either on print quota or on sum of its users' account balances.""" |
---|
169 | pass |
---|
170 | |
---|
171 | def setUserPQuota(self, userid, printerid, softlimit, hardlimit) : |
---|
172 | """Sets soft and hard limits for a user quota on a specific printer given (userid, printerid).""" |
---|
173 | pass |
---|
174 | |
---|
175 | def setGroupPQuota(self, groupid, printerid, softlimit, hardlimit) : |
---|
176 | """Sets soft and hard limits for a group quota on a specific printer given (groupid, printerid).""" |
---|
177 | pass |
---|
178 | |
---|
179 | def resetUserPQuota(self, userid, printerid) : |
---|
180 | """Resets the page counter to zero for a user on a printer. Life time page counter is kept unchanged.""" |
---|
181 | pass |
---|
182 | |
---|
183 | def resetGroupPQuota(self, groupid, printerid) : |
---|
184 | """Resets the page counter to zero for a group on a printer. Life time page counter is kept unchanged.""" |
---|
185 | pass |
---|
186 | |
---|
187 | def updateUserPQuota(self, userid, printerid, pagecount) : |
---|
188 | """Updates the used user Quota information given (userid, printerid) and a job size in pages.""" |
---|
189 | pass |
---|
190 | |
---|
191 | def getUserPQuota(self, userid, printerid) : |
---|
192 | """Returns the Print Quota information for a given (userid, printerid).""" |
---|
193 | pass |
---|
194 | |
---|
195 | def getGroupPQuota(self, groupid, printerid) : |
---|
196 | """Returns the Print Quota information for a given (groupid, printerid).""" |
---|
197 | pass |
---|
198 | |
---|
199 | def setUserDateLimit(self, userid, printerid, datelimit) : |
---|
200 | """Sets the limit date for a soft limit to become an hard one given (userid, printerid).""" |
---|
201 | pass |
---|
202 | |
---|
203 | def setGroupDateLimit(self, groupid, printerid, datelimit) : |
---|
204 | """Sets the limit date for a soft limit to become an hard one given (groupid, printerid).""" |
---|
205 | pass |
---|
206 | |
---|
207 | def addJobToHistory(self, jobid, userid, printerid, pagecounter, action) : |
---|
208 | """Adds a job to the history: (jobid, userid, printerid, last page counter taken from requester).""" |
---|
209 | pass |
---|
210 | |
---|
211 | def updateJobSizeInHistory(self, historyid, jobsize) : |
---|
212 | """Updates a job size in the history given the history line's id.""" |
---|
213 | pass |
---|
214 | |
---|
215 | def getPrinterPageCounter(self, printerid) : |
---|
216 | """Returns the last page counter value for a printer given its id, also returns last username, last jobid and history line id.""" |
---|
217 | pass |
---|
218 | |
---|
219 | def addUserToGroup(self, userid, groupid) : |
---|
220 | """Adds an user to a group.""" |
---|
221 | pass |
---|
222 | |
---|
223 | def deleteUser(self, userid) : |
---|
224 | """Completely deletes an user from the Quota Storage.""" |
---|
225 | pass |
---|
226 | |
---|
227 | def deleteGroup(self, groupid) : |
---|
228 | """Completely deletes an user from the Quota Storage.""" |
---|
229 | pass |
---|
230 | |
---|
231 | def computePrinterJobPrice(self, printerid, jobsize) : |
---|
232 | """Returns the price for a job on a given printer.""" |
---|
233 | # TODO : create a base class with things like this |
---|
234 | prices = self.getPrinterPrices(printerid) |
---|
235 | if prices is None : |
---|
236 | perpage = perjob = 0.0 |
---|
237 | else : |
---|
238 | (perpage, perjob) = prices |
---|
239 | return perjob + (perpage * jobsize) |
---|