Changeset 1030
- Timestamp:
- 06/16/03 00:26:52 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/repykota
r1021 r1030 23 23 # 24 24 # $Log$ 25 # Revision 1.38 2003/06/15 22:26:52 jalet 26 # More work on LDAP 27 # 25 28 # Revision 1.37 2003/06/10 16:37:54 jalet 26 29 # Deletion of the second user which is not needed anymore. … … 225 228 print _("Group used soft hard balance grace total paid") 226 229 print "------------------------------------------------------------------------------" 227 for (ident, name) in self.storage.getPrinterGroups(printerid) :230 for (ident, name) in (self.storage.getPrinterGroups(printerid) or []) : 228 231 quota = self.storage.getGroupPQuota(ident, printerid) 229 232 balance = self.storage.getGroupBalance(ident) … … 236 239 print _("User used soft hard balance grace total paid") 237 240 print "------------------------------------------------------------------------------" 238 for (ident, name) in self.storage.getPrinterUsers(printerid) :241 for (ident, name) in (self.storage.getPrinterUsers(printerid) or []) : 239 242 quota = self.storage.getUserPQuota(ident, printerid) 240 243 balance = self.storage.getUserBalance(ident) -
pykota/trunk/po/en/pykota.po
r980 r1030 21 21 # 22 22 # $Log$ 23 # Revision 1.25 2003/06/15 22:26:52 jalet 24 # More work on LDAP 25 # 23 26 # Revision 1.24 2003/04/30 19:53:58 jalet 24 27 # 1.05 … … 352 355 msgid "Unable to compute job size with external accounter %s" 353 356 msgstr "" 357 358 msgid "Search for %s(%s) from %s(scope=%s) returned no answer." 359 msgstr "" 360 361 msgid "Problem adding LDAP entry (%s, %s)" 362 msgstr "" 363 364 msgid "Problem modifying LDAP entry (%s, %s)" 365 msgstr "" -
pykota/trunk/po/fr/pykota.po
r980 r1030 21 21 # 22 22 # $Log$ 23 # Revision 1.24 2003/06/15 22:26:52 jalet 24 # More work on LDAP 25 # 23 26 # Revision 1.23 2003/04/30 19:53:58 jalet 24 27 # 1.05 … … 364 367 msgid "Unable to compute job size with external accounter %s" 365 368 msgstr "Impossible de calculer la taille du job avec le compteur externe %s" 369 370 msgid "Search for %s(%s) from %s(scope=%s) returned no answer." 371 msgstr "La recherche de %s(%s) depuis %s(scope=%s) n'a renvoy�ucun r�ltat." 372 373 msgid "Problem adding LDAP entry (%s, %s)" 374 msgstr "Probl� durant l'ajout de l'entr�LDAP (%s, %s)" 375 376 msgid "Problem modifying LDAP entry (%s, %s)" 377 msgstr "Probl� durant la modification de l'entr�LDAP (%s, %s)" -
pykota/trunk/po/pykota.pot
r980 r1030 21 21 # 22 22 # $Log$ 23 # Revision 1.25 2003/06/15 22:26:52 jalet 24 # More work on LDAP 25 # 23 26 # Revision 1.24 2003/04/30 19:53:58 jalet 24 27 # 1.05 … … 352 355 msgid "Unable to compute job size with external accounter %s" 353 356 msgstr "" 357 358 msgid "Search for %s(%s) from %s(scope=%s) returned no answer." 359 msgstr "" 360 361 msgid "Problem adding LDAP entry (%s, %s)" 362 msgstr "" 363 364 msgid "Problem modifying LDAP entry (%s, %s)" 365 msgstr "" -
pykota/trunk/pykota/storages/ldapstorage.py
r1029 r1030 21 21 # 22 22 # $Log$ 23 # Revision 1.8 2003/06/15 22:26:52 jalet 24 # More work on LDAP 25 # 23 26 # Revision 1.7 2003/06/14 22:44:21 jalet 24 27 # More work on LDAP storage backend. … … 55 58 # 56 59 60 import time 61 import md5 57 62 import fnmatch 58 63 … … 61 66 try : 62 67 import ldap 68 from ldap import modlist 63 69 except ImportError : 64 70 import sys … … 93 99 self.tool.logger.log_message("Database closed.", "debug") 94 100 95 def doSearch(self, key, fields, base="", scope=ldap.SCOPE_SUBTREE) : 101 def genUUID(self) : 102 """Generates an unique identifier. 103 104 TODO : this one is not unique accross several print servers, but should be sufficient for testing. 105 """ 106 return md5.md5("%s" % time.time()).hexdigest() 107 108 def doSearch(self, key, fields=None, base="", scope=ldap.SCOPE_SUBTREE) : 96 109 """Does an LDAP search query.""" 97 110 try : 98 # prepends something more restrictive at the beginning of the basedn111 base = base or self.basedn 99 112 if self.debug : 100 self.tool.logger.log_message("QUERY : BaseDN : %s, Scope : %s, Filter : %s, Attributes : %s" % ( (base or self.basedn), scope, key, fields), "debug")113 self.tool.logger.log_message("QUERY : BaseDN : %s, Scope : %s, Filter : %s, Attributes : %s" % (base, scope, key, fields), "debug") 101 114 result = self.database.search_s(base or self.basedn, scope, key, fields) 102 except ldap. NO_SUCH_OBJECT:103 r eturn115 except ldap.LDAPError : 116 raise PyKotaStorageError, _("Search for %s(%s) from %s(scope=%s) returned no answer.") % (key, fields, base, scope) 104 117 else : 105 118 return result 119 120 def doAdd(self, dn, fields) : 121 """Adds an entry in the LDAP directory.""" 122 try : 123 if self.debug : 124 self.tool.logger.log_message("QUERY : ADD(%s, %s)" % (dn, str(fields)), "debug") 125 self.database.add_s(dn, modlist.addModlist(fields)) 126 except ldap.LDAPError : 127 raise PyKotaStorageError, _("Problem adding LDAP entry (%s, %s)") % (dn, str(fields)) 128 else : 129 return dn 130 131 def doModify(self, dn, fields) : 132 """Modifies an entry in the LDAP directory.""" 133 try : 134 oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE) 135 if self.debug : 136 self.tool.logger.log_message("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry[0][1], fields), "debug") 137 self.database.modify_s(dn, modlist.modifyModlist(oldentry[0][1], fields, ignore_oldexistent=1)) 138 except ldap.LDAPError : 139 raise PyKotaStorageError, _("Problem modifying LDAP entry (%s, %s)") % (dn, fields) 140 else : 141 return dn 106 142 107 143 def getMatchingPrinters(self, printerpattern) : … … 116 152 if result : 117 153 return result[0][0] 154 155 def getPrinterName(self, printerid) : 156 """Returns a printerid given a printer id.""" 157 result = self.doSearch("objectClass=*", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 158 if result : 159 return result[0][1]["pykotaPrinterName"][0] 118 160 119 161 def getPrinterPrices(self, printerid) : … … 182 224 def addPrinter(self, printername) : 183 225 """Adds a printer to the quota storage, returns its id.""" 184 raise PyKotaStorageError, "Not implemented !" 226 fields = { self.info["printerrdn"] : printername, 227 "objectClass" : ["pykotaObject", "pykotaPrinter"], 228 "pykotaPrinterName" : printername, 229 "pykotaPricePerPage" : "0.0", 230 "pykotaPricePerJob" : "0.0", 231 } 232 dn = "%s=%s,%s" % (self.info["printerrdn"], printername, self.info["printerbase"]) 233 return self.doAdd(dn, fields) 185 234 186 235 def addUser(self, username) : 187 236 """Adds a user to the quota storage, returns its id.""" 188 raise PyKotaStorageError, "Not implemented !" 237 fields = { self.info["userrdn"] : username, 238 "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"], 239 "pykotaUserName" : username, 240 "pykotaLimitBy" : "quota", 241 "pykotaBalance" : "0.0", 242 "pykotaLifeTimePaid" : "0.0", 243 } 244 dn = "%s=%s,%s" % (self.info["userrdn"], username, self.info["userbase"]) 245 return self.doAdd(dn, fields) 189 246 190 247 def addGroup(self, groupname) : 191 248 """Adds a group to the quota storage, returns its id.""" 192 raise PyKotaStorageError, "Not implemented !" 249 fields = { self.info["grouprdn"] : groupname, 250 "objectClass" : ["pykotaObject", "pykotaGroup"], 251 "pykotaGroupName" : groupname, 252 "pykotaLimitBy" : "quota", 253 } 254 dn = "%s=%s,%s" % (self.info["grouprdn"], groupname, self.info["groupbase"]) 255 return self.doAdd(dn, fields) 193 256 194 257 def addUserPQuota(self, username, printerid) : 195 258 """Initializes a user print quota on a printer, adds the user to the quota storage if needed.""" 196 raise PyKotaStorageError, "Not implemented !" 259 uuid = self.genUUID() 260 fields = { "objectClass" : ["pykotaObject", "pykotaUserPQuota"], 261 "cn" : uuid, 262 "pykotaUserName" : username, 263 "pykotaPrinterName" : self.getPrinterName(printerid), 264 "pykotaPageCounter" : "0", 265 "pykotaLifePageCounter" : "0", 266 "pykotaSoftLimit" : "0", 267 "pykotaHardLimit" : "0", 268 "pykotaDateLimit" : "None", 269 } 270 dn = "cn=%s,%s" % (uuid, self.info["userquotabase"]) 271 return self.doAdd(dn, fields) 197 272 198 273 def addGroupPQuota(self, groupname, printerid) : 199 274 """Initializes a group print quota on a printer, adds the group to the quota storage if needed.""" 200 raise PyKotaStorageError, "Not implemented !" 275 uuid = self.genUUID() 276 fields = { "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], 277 "cn" : uuid, 278 "pykotaGroupName" : groupname, 279 "pykotaPrinterName" : self.getPrinterName(printerid), 280 "pykotaSoftLimit" : "0", 281 "pykotaHardLimit" : "0", 282 "pykotaDateLimit" : "None", 283 } 284 dn = "cn=%s,%s" % (uuid, self.info["groupquotabase"]) 285 return self.doAdd(dn, fields) 201 286 202 287 def increaseUserBalance(self, userid, amount) : … … 276 361 raise PyKotaStorageError, "Not implemented !" 277 362 278 def setUserPQuota(self, user id, printerid, softlimit, hardlimit) :363 def setUserPQuota(self, userquotaid, printerid, softlimit, hardlimit) : 279 364 """Sets soft and hard limits for a user quota on a specific printer given (userid, printerid).""" 280 raise PyKotaStorageError, "Not implemented !" 281 282 def setGroupPQuota(self, groupid, printerid, softlimit, hardlimit) : 365 fields = { 366 "pykotaSoftLimit" : str(softlimit), 367 "pykotaHardLimit" : str(hardlimit), 368 } 369 return self.doModify(userquotaid, fields) 370 371 def setGroupPQuota(self, groupquotaid, printerid, softlimit, hardlimit) : 283 372 """Sets soft and hard limits for a group quota on a specific printer given (groupid, printerid).""" 284 raise PyKotaStorageError, "Not implemented !" 373 fields = { 374 "pykotaSoftLimit" : str(softlimit), 375 "pykotaHardLimit" : str(hardlimit), 376 } 377 return self.doModify(groupquotaid, fields) 285 378 286 379 def resetUserPQuota(self, userid, printerid) : -
pykota/trunk/pykota/version.py
r1029 r1030 21 21 # 22 22 23 __version__ = "1.09alpha 1_unofficial"23 __version__ = "1.09alpha2_unofficial" 24 24 25 25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""