Changeset 2749 for pykota/trunk/pykota/storages/ldapstorage.py
- Timestamp:
- 02/23/06 11:58:05 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r2735 r2749 191 191 self.tool.logdebug("%s" % entry) 192 192 self.database.add_s(dn, entry) 193 except ldap.ALREADY_EXISTS, msg : 194 raise PyKotaStorageError 193 195 except ldap.LDAPError, msg : 194 196 message = (_("Problem adding LDAP entry (%s, %s)") % (dn, str(fields))) + " : %s" % str(msg) … … 454 456 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % \ 455 457 (self.userCharsetToDatabase(user.Name), self.userCharsetToDatabase(printer.Name)), \ 456 ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount" ], \458 ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount", "pykotaMaxJobSize"], \ 457 459 base=base) 458 460 if result : … … 480 482 else : 481 483 userpquota.DateLimit = userpquota.DateLimit[0] 484 userpquota.MaxJobSize = fields.get("pykotaMaxJobSize") 485 if userpquota.MaxJobSize is not None : 486 if userpquota.MaxJobSize[0].upper() == "NONE" : 487 userpquota.MaxJobSize = None 488 else : 489 userpquota.MaxJobSize = int(userpquota.MaxJobSize[0]) 482 490 userpquota.Exists = 1 483 491 return userpquota … … 493 501 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 494 502 (self.userCharsetToDatabase(group.Name), self.userCharsetToDatabase(printer.Name)), \ 495 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit" ], \503 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaMaxJobSize"], \ 496 504 base=base) 497 505 if result : … … 516 524 else : 517 525 grouppquota.DateLimit = grouppquota.DateLimit[0] 526 grouppquota.MaxJobSize = fields.get("pykotaMaxJobSize") 527 if grouppquota.MaxJobSize is not None : 528 if grouppquota.MaxJobSize[0].upper() == "NONE" : 529 grouppquota.MaxJobSize = None 530 else : 531 grouppquota.MaxJobSize = int(grouppquota.MaxJobSize[0]) 518 532 grouppquota.PageCounter = 0 519 533 grouppquota.LifePageCounter = 0 … … 1018 1032 raise "Not Implemented !" # TODO !!! 1019 1033 1020 def addUserPQuota(self, u ser, printer) :1034 def addUserPQuota(self, upq) : 1021 1035 """Initializes a user print quota on a printer.""" 1036 # first check if an entry already exists 1037 oldentry = self.getUserPQuota(upq.User, upq.Printer) 1038 if oldentry.Exists : 1039 return oldentry # we return the existing entry 1022 1040 uuid = self.genUUID() 1023 uname = self.userCharsetToDatabase(u ser.Name)1024 pname = self.userCharsetToDatabase( printer.Name)1041 uname = self.userCharsetToDatabase(upq.User.Name) 1042 pname = self.userCharsetToDatabase(upq.Printer.Name) 1025 1043 fields = { "cn" : uuid, 1026 1044 "objectClass" : ["pykotaObject", "pykotaUserPQuota"], 1027 1045 "pykotaUserName" : uname, 1028 1046 "pykotaPrinterName" : pname, 1029 "pykotaDateLimit" : "None", 1030 "pykotaPageCounter" : "0", 1031 "pykotaLifePageCounter" : "0", 1032 "pykotaWarnCount" : "0", 1047 "pykotaSoftLimit" : str(upq.SoftLimit), 1048 "pykotaHardLimit" : str(upq.HardLimit), 1049 "pykotaDateLimit" : str(upq.DateLimit), 1050 "pykotaPageCounter" : str(upq.PageCounter or 0), 1051 "pykotaLifePageCounter" : str(upq.LifePageCounter or 0), 1052 "pykotaWarnCount" : str(upq.WarnCount or 0), 1053 "pykotaMaxJobSize" : str(upq.MaxJobSize or 0), 1033 1054 } 1034 1055 if self.info["userquotabase"].lower() == "user" : 1035 dn = "cn=%s,%s" % (uuid, u ser.ident)1056 dn = "cn=%s,%s" % (uuid, upq.User.ident) 1036 1057 else : 1037 1058 dn = "cn=%s,%s" % (uuid, self.info["userquotabase"]) 1038 1059 self.doAdd(dn, fields) 1039 return self.getUserPQuota(user, printer) 1040 1041 def addGroupPQuota(self, group, printer) : 1060 upq.isDirty = False 1061 return None # the entry created doesn't need further modification 1062 1063 def addGroupPQuota(self, gpq) : 1042 1064 """Initializes a group print quota on a printer.""" 1065 oldentry = self.getGroupPQuota(gpq.Group, gpq.Printer) 1066 if oldentry.Exists : 1067 return oldentry # we return the existing entry 1043 1068 uuid = self.genUUID() 1044 gname = self.userCharsetToDatabase(g roup.Name)1045 pname = self.userCharsetToDatabase( printer.Name)1069 gname = self.userCharsetToDatabase(gpq.Group.Name) 1070 pname = self.userCharsetToDatabase(gpq.Printer.Name) 1046 1071 fields = { "cn" : uuid, 1047 1072 "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], … … 1051 1076 } 1052 1077 if self.info["groupquotabase"].lower() == "group" : 1053 dn = "cn=%s,%s" % (uuid, g roup.ident)1078 dn = "cn=%s,%s" % (uuid, gpq.Group.ident) 1054 1079 else : 1055 1080 dn = "cn=%s,%s" % (uuid, self.info["groupquotabase"]) 1056 1081 self.doAdd(dn, fields) 1057 return self.getGroupPQuota(group, printer) 1082 gpq.isDirty = False 1083 return None # the entry created doesn't need further modification 1058 1084 1059 1085 def savePrinter(self, printer) : … … 1204 1230 "pykotaHardLimit" : str(userpquota.HardLimit), 1205 1231 "pykotaDateLimit" : str(userpquota.DateLimit), 1206 "pykotaWarnCount" : str(userpquota.WarnCount), 1207 "pykotaPageCounter" : str(userpquota.PageCounter), 1208 "pykotaLifePageCounter" : str(userpquota.LifePageCounter), 1232 "pykotaWarnCount" : str(userpquota.WarnCount or 0), 1233 "pykotaPageCounter" : str(userpquota.PageCounter or 0), 1234 "pykotaLifePageCounter" : str(userpquota.LifePageCounter or 0), 1235 "pykotaMaxJobSize" : str(userpquota.MaxJobSize or 0), 1209 1236 } 1210 1237 self.doModify(userpquota.ident, fields) … … 1230 1257 "pykotaHardLimit" : str(grouppquota.HardLimit), 1231 1258 "pykotaDateLimit" : str(grouppquota.DateLimit), 1259 "pykotaMaxJobSize" : str(userpquota.MaxJobSize or 0), 1232 1260 } 1233 1261 self.doModify(grouppquota.ident, fields) … … 1427 1455 self.doDelete(group.ident) 1428 1456 1457 def deleteManyUserPQuotas(self, printers, users) : 1458 """Deletes many user print quota entries.""" 1459 # TODO : grab all with a single (possibly VERY huge) filter if possible (might depend on the LDAP server !) 1460 for printer in printers : 1461 for user in users : 1462 upq = self.getUserPQuota(user, printer) 1463 if upq.Exists : 1464 upq.delete() 1465 1466 def deleteManyGroupPQuotas(self, printers, groups) : 1467 """Deletes many group print quota entries.""" 1468 # TODO : grab all with a single (possibly VERY huge) filter if possible (might depend on the LDAP server !) 1469 for printer in printers : 1470 for group in groups : 1471 gpq = self.getGroupPQuota(group, printer) 1472 if gpq.Exists : 1473 gpq.delete() 1474 1429 1475 def deleteUserPQuota(self, upquota) : 1430 1476 """Completely deletes an user print quota entry from the database."""