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