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