Changeset 1031
- Timestamp:
- 06/16/03 13:59:09 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r1023 r1031 23 23 # 24 24 # $Log$ 25 # Revision 1.46 2003/06/16 11:59:09 jalet 26 # More work on LDAP 27 # 25 28 # Revision 1.45 2003/06/11 19:32:00 jalet 26 29 # Severe bug wrt account balance setting should be corrected. … … 428 431 else : 429 432 if options["groups"] : 430 allidnames = self.storage.getPrinterGroups(printerid) 433 allidnames = self.storage.getPrinterGroups(printerid) or [] 431 434 else : 432 allidnames = self.storage.getPrinterUsers(printerid) 435 allidnames = self.storage.getPrinterUsers(printerid) or [] 433 436 for (ident, name) in [(i, n) for (i, n) in allidnames if self.matchString(n, names)]: 434 437 if options["groups"] : 435 if not gwaschanged.has_key( ident) :436 gwaschanged[ ident] = {}438 if not gwaschanged.has_key(name) : 439 gwaschanged[name] = {} 437 440 quota = self.storage.getGroupPQuota(ident, printerid) 438 441 else : 439 if not uwaschanged.has_key( ident) :440 uwaschanged[ ident] = {"ingroups": []}442 if not uwaschanged.has_key(name) : 443 uwaschanged[name] = {"ingroups": []} 441 444 quota = self.storage.getUserPQuota(ident, printerid) 442 445 if quota is None : … … 474 477 self.storage.resetGroupPQuota(ident, printerid) 475 478 if limitby : 476 if gwaschanged[ ident].get("limitby") is None :479 if gwaschanged[name].get("limitby") is None : 477 480 self.storage.limitGroupBy(ident, limitby) 478 gwaschanged[ ident]["limitby"] = limitby481 gwaschanged[name]["limitby"] = limitby 479 482 self.warnGroupPQuota(name, printer) 480 483 else : … … 484 487 self.storage.resetUserPQuota(ident, printerid) 485 488 if limitby : 486 if uwaschanged[ ident].get("limitby") is None :489 if uwaschanged[name].get("limitby") is None : 487 490 self.storage.limitUserBy(ident, limitby) 488 uwaschanged[ ident]["limitby"] = limitby491 uwaschanged[name]["limitby"] = limitby 489 492 if balance : 490 if uwaschanged[ ident].get("balance") is None :493 if uwaschanged[name].get("balance") is None : 491 494 if balance.startswith("+") or balance.startswith("-") : 492 495 self.storage.increaseUserBalance(ident, balancevalue) 493 496 else : 494 497 self.storage.setUserBalance(ident, balancevalue) 495 uwaschanged[ ident]["balance"] = balance498 uwaschanged[name]["balance"] = balance 496 499 for groupname in groupnames : 497 if groupname not in uwaschanged[ ident]["ingroups"] :500 if groupname not in uwaschanged[name]["ingroups"] : 498 501 groupid = self.storage.getGroupId(groupname) 499 502 if groupid is not None : 500 503 self.storage.addUserToGroup(ident, groupid) 501 uwaschanged[ ident]["ingroups"].append(groupname)504 uwaschanged[name]["ingroups"].append(groupname) 502 505 else : 503 506 self.logger.log_message(_("Group %s not found in the PyKota Storage.") % groupname) -
pykota/trunk/pykota/storages/ldapstorage.py
r1030 r1031 21 21 # 22 22 # $Log$ 23 # Revision 1.9 2003/06/16 11:59:09 jalet 24 # More work on LDAP 25 # 23 26 # Revision 1.8 2003/06/15 22:26:52 jalet 24 27 # More work on LDAP … … 86 89 except ldap.SERVER_DOWN : 87 90 raise PyKotaStorageError, "LDAP backend for PyKota seems to be down !" # TODO : translate 91 except ldap.LDAPError : 92 raise PyKotaStorageError, "Unable to connect to LDAP server %s as %s." % (host, user) # TODO : translate 88 93 else : 89 94 self.closed = 0 … … 116 121 raise PyKotaStorageError, _("Search for %s(%s) from %s(scope=%s) returned no answer.") % (key, fields, base, scope) 117 122 else : 123 if self.debug : 124 self.tool.logger.log_message("QUERY : Result : %s" % result, "debug") 118 125 return result 119 126 … … 155 162 def getPrinterName(self, printerid) : 156 163 """Returns a printerid given a printer id.""" 157 result = self.doSearch("objectClass= *", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE)164 result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 158 165 if result : 159 166 return result[0][1]["pykotaPrinterName"][0] … … 167 174 def setPrinterPrices(self, printerid, perpage, perjob) : 168 175 """Sets prices per job and per page for a given printer.""" 169 raise PyKotaStorageError, "Not implemented !" 176 fields = { 177 "pykotaPricePerPage" : str(perpage), 178 "pykotaPricePerJob" : str(perjob), 179 } 180 return self.doModify(printerid, fields) 170 181 171 182 def getUserId(self, username) : … … 174 185 if result : 175 186 return result[0][0] 187 188 def getUserName(self, userid) : 189 """Returns a username given a userid.""" 190 result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName"], base=userid, scope=ldap.SCOPE_BASE) 191 if result : 192 return result[0][1]["pykotaUserName"][0] 176 193 177 194 def getGroupId(self, groupname) : … … 220 237 def getUserGroupsNames(self, userid) : 221 238 """Returns the list of groups' names the user is a member of.""" 222 raise PyKotaStorageError, "Not implemented !" 239 username = self.getUserName(userid) 240 if username : 241 result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % (self.info["groupmembers"], username), [self.info["grouprdn"]], base=self.info["groupbase"]) 242 if result : 243 return [v[self.info["grouprdn"]][0] for (k, v) in result] 223 244 224 245 def addPrinter(self, printername) : … … 269 290 } 270 291 dn = "cn=%s,%s" % (uuid, self.info["userquotabase"]) 271 return self.doAdd(dn, fields) 292 self.doAdd(dn, fields) 293 return (dn, printerid) 272 294 273 295 def addGroupPQuota(self, groupname, printerid) : … … 283 305 } 284 306 dn = "cn=%s,%s" % (uuid, self.info["groupquotabase"]) 285 return self.doAdd(dn, fields) 286 287 def increaseUserBalance(self, userid, amount) : 307 self.doAdd(dn, fields) 308 return (dn, printerid) 309 310 def increaseUserBalance(self, userquotaid, amount) : 288 311 """Increases (or decreases) an user's account balance by a given amount.""" 289 raise PyKotaStorageError, "Not implemented !" 312 balance = self.getUserBalance(userquotaid) 313 if balance : 314 (newbal, newpaid) = [(float(v) + float(amount)) for v in balance] 315 result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName"], base=userquotaid, scope=ldap.SCOPE_BASE) 316 if result : 317 username = result[0][1]["pykotaUserName"][0] 318 if username : 319 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username , [ "pykotaBalance", "pykotaLifeTimePaid"]) 320 fields = { 321 "pykotaBalance" : str(newbal), 322 "pykotaLifeTimePaid" : str(newpaid), 323 } 324 return self.doModify(result[0][0], fields) 290 325 291 326 def getUserBalance(self, userquotaid) : … … 349 384 return result[0][1]["pykotaLimitBy"][0] 350 385 351 def setUserBalance(self, user id, balance) :386 def setUserBalance(self, userquotaid, balance) : 352 387 """Sets the account balance for a given user to a fixed value.""" 353 raise PyKotaStorageError, "Not implemented !" 354 355 def limitUserBy(self, userid, limitby) : 388 oldbalance = self.getUserBalance(userquotaid) 389 if oldbalance : 390 (oldbal, oldpaid) = oldbalance 391 difference = balance - oldbal 392 return self.increaseUserBalance(userquotaid, difference) 393 394 def limitUserBy(self, userquotaid, limitby) : 356 395 """Limits a given user based either on print quota or on account balance.""" 357 raise PyKotaStorageError, "Not implemented !" 358 359 def limitGroupBy(self, groupid, limitby) : 396 result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName"], base=userquotaid, scope=ldap.SCOPE_BASE) 397 if result : 398 username = result[0][1]["pykotaUserName"][0] 399 fields = { 400 "pykotaLimitBy" : limitby, 401 } 402 self.doModify(self.getUserId(username), fields) 403 404 def limitGroupBy(self, groupquotaid, limitby) : 360 405 """Limits a given group based either on print quota or on sum of its users' account balances.""" 361 raise PyKotaStorageError, "Not implemented !" 406 result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName"], base=groupquotaid, scope=ldap.SCOPE_BASE) 407 if result : 408 groupname = result[0][1]["pykotaGroupName"][0] 409 fields = { 410 "pykotaLimitBy" : limitby, 411 } 412 self.doModify(self.getGroupId(groupname), fields) 362 413 363 414 def setUserPQuota(self, userquotaid, printerid, softlimit, hardlimit) : … … 377 428 return self.doModify(groupquotaid, fields) 378 429 379 def resetUserPQuota(self, user id, printerid) :430 def resetUserPQuota(self, userquotaid, printerid) : 380 431 """Resets the page counter to zero for a user on a printer. Life time page counter is kept unchanged.""" 381 raise PyKotaStorageError, "Not implemented !" 382 383 def resetGroupPQuota(self, groupid, printerid) : 432 fields = { 433 "pykotaPageCounter" : "0", 434 "pykotaDateLimit" : "None", 435 } 436 return self.doModify(userquotaid, fields) 437 438 def resetGroupPQuota(self, groupquotaid, printerid) : 384 439 """Resets the page counter to zero for a group on a printer. Life time page counter is kept unchanged.""" 385 raise PyKotaStorageError, "Not implemented !" 386 387 def updateUserPQuota(self, userid, printerid, pagecount) : 440 fields = { 441 "pykotaPageCounter" : "0", 442 "pykotaDateLimit" : "None", 443 } 444 return self.doModify(groupquotaid, fields) 445 446 def updateUserPQuota(self, userquotaid, printerid, pagecount) : 388 447 """Updates the used user Quota information given (userid, printerid) and a job size in pages.""" 389 raise PyKotaStorageError, "Not implemented !" 448 jobprice = self.computePrinterJobPrice(printerid, pagecount) 449 result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaPageCounter", "pykotaLifePageCounter"], base=userquotaid, scope=ldap.SCOPE_BASE) 450 if result : 451 oldfields = result[0][1] 452 fields = { 453 "pykotaPageCounter" : str(pagecount + int(oldfields["pykotaPageCounter"][0])), 454 "pykotaLifePageCounter" : str(pagecount + int(oldfields["pykotaLifePageCounter"][0])), 455 } 456 return self.doModify(userquotaid, fields) 390 457 391 458 def getUserPQuota(self, userquotaid, printerid) : … … 432 499 return quota 433 500 434 def setUserDateLimit(self, user id, printerid, datelimit) :501 def setUserDateLimit(self, userquotaid, printerid, datelimit) : 435 502 """Sets the limit date for a soft limit to become an hard one given (userid, printerid).""" 436 raise PyKotaStorageError, "Not implemented !" 437 438 def setGroupDateLimit(self, groupid, printerid, datelimit) : 503 fields = { 504 "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second), 505 } 506 return self.doModify(userquotaid, fields) 507 508 def setGroupDateLimit(self, groupquotaid, printerid, datelimit) : 439 509 """Sets the limit date for a soft limit to become an hard one given (groupid, printerid).""" 440 raise PyKotaStorageError, "Not implemented !" 510 fields = { 511 "pykotaDateLimit" : "%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second), 512 } 513 return self.doModify(groupquotaid, fields) 441 514 442 515 def addJobToHistory(self, jobid, userid, printerid, pagecounter, action) :