Changeset 3294 for pykota/trunk/pykota/storages/ldapstorage.py
- Timestamp:
- 01/18/08 23:39:41 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r3291 r3294 42 42 StorageJob, StorageLastJob, StorageUserPQuota, \ 43 43 StorageGroupPQuota, StorageBillingCode 44 45 from pykota.utils import * 44 46 45 47 try : … … 160 162 result = [(base, entry)] 161 163 else : 162 self. tool.logdebug("QUERY : Filter : %s, BaseDN : %s, Scope : %s, Attributes : %s" % (key, base, scope, fields))164 self.querydebug("QUERY : Filter : %s, BaseDN : %s, Scope : %s, Attributes : %s" % (key, base, scope, fields)) 163 165 result = self.database.search_s(base, scope, key, fields) 164 166 except ldap.NO_SUCH_OBJECT, msg : … … 171 173 self.secondStageInit() 172 174 else : 173 self. tool.logdebug("QUERY : Result : %s" % result)175 self.querydebug("QUERY : Result : %s" % result) 174 176 result = [ (dn, cidict(attrs)) for (dn, attrs) in result ] 175 177 if self.useldapcache : 176 178 for (dn, attributes) in result : 177 self. tool.logdebug("LDAP cache store %s => %s" % (dn, attributes))179 self.querydebug("LDAP cache store %s => %s" % (dn, attributes)) 178 180 self.ldapcache[dn] = attributes 179 181 return result … … 186 188 for tryit in range(3) : 187 189 try : 188 self. tool.logdebug("QUERY : ADD(%s, %s)" % (dn, str(fields)))190 self.querydebug("QUERY : ADD(%s, %s)" % (dn, fields)) 189 191 entry = ldap.modlist.addModlist(fields) 190 self. tool.logdebug("%s" % entry)192 self.querydebug("%s" % entry) 191 193 self.database.add_s(dn, entry) 192 194 except ldap.ALREADY_EXISTS, msg : … … 200 202 else : 201 203 if self.useldapcache : 202 self. tool.logdebug("LDAP cache add %s => %s" % (dn, fields))204 self.querydebug("LDAP cache add %s => %s" % (dn, fields)) 203 205 self.ldapcache[dn] = fields 204 206 return dn … … 210 212 for tryit in range(3) : 211 213 try : 212 self. tool.logdebug("QUERY : Delete(%s)" % dn)214 self.querydebug("QUERY : Delete(%s)" % dn) 213 215 self.database.delete_s(dn) 214 216 except ldap.NO_SUCH_OBJECT : … … 223 225 if self.useldapcache : 224 226 try : 225 self. tool.logdebug("LDAP cache del %s" % dn)227 self.querydebug("LDAP cache del %s" % dn) 226 228 del self.ldapcache[dn] 227 229 except KeyError : … … 239 241 if self.ldapcache.has_key(dn) : 240 242 old = self.ldapcache[dn] 241 self. tool.logdebug("LDAP cache hit %s => %s" % (dn, old))243 self.querydebug("LDAP cache hit %s => %s" % (dn, old)) 242 244 oldentry = {} 243 245 for (k, v) in old.items() : … … 245 247 oldentry[k] = v 246 248 else : 247 self. tool.logdebug("LDAP cache miss %s" % dn)249 self.querydebug("LDAP cache miss %s" % dn) 248 250 oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE)[0][1] 249 251 else : … … 254 256 oldvalue = v["convert"](oldentry.get(k, [0])[0]) 255 257 except ValueError : 256 self. tool.logdebug("Error converting %s with %s(%s)" % (oldentry.get(k), k, v))258 self.querydebug("Error converting %s with %s(%s)" % (oldentry.get(k), k, v)) 257 259 oldvalue = 0 258 260 if v["operator"] == '+' : … … 262 264 fields[k] = str(newvalue) 263 265 fields = self.normalizeFields(fields) 264 self. tool.logdebug("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry, fields))266 self.querydebug("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry, fields)) 265 267 entry = ldap.modlist.modifyModlist(oldentry, fields, ignore_oldexistent=ignoreold) 266 268 modentry = [] … … 268 270 if mtyp and (mtyp.lower() != "createtimestamp") : 269 271 modentry.append((mop, mtyp, mval)) 270 self. tool.logdebug("MODIFY : %s ==> %s ==> %s" % (fields, entry, modentry))272 self.querydebug("MODIFY : %s ==> %s ==> %s" % (fields, entry, modentry)) 271 273 if modentry : 272 274 self.database.modify_s(dn, modentry) … … 288 290 except KeyError : 289 291 pass 290 self. tool.logdebug("LDAP cache update %s => %s" % (dn, cachedentry))292 self.querydebug("LDAP cache update %s => %s" % (dn, cachedentry)) 291 293 return dn 292 294 raise PyKotaStorageError, message … … 303 305 self.tool.printInfo("Object %s has no %s attribute !" % (dn, attribute), "error") 304 306 else : 305 attrval = self.databaseToUnicode(attrval)307 attrval = databaseToUnicode(attrval) 306 308 if patterns : 307 309 if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : … … 318 320 result = self.doSearch(ldapfilter, ["pykotaBillingCode"], base=self.info["billingcodebase"]) 319 321 if result : 320 return [ self.databaseToUnicode(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)]322 return [databaseToUnicode(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)] 321 323 else : 322 324 return [] … … 351 353 def getUserNbJobsFromHistory(self, user) : 352 354 """Returns the number of jobs the user has in history.""" 353 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % self.unicodeToDatabase(user.Name), None, base=self.info["jobbase"])355 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % unicodeToDatabase(user.Name), None, base=self.info["jobbase"]) 354 356 return len(result) 355 357 … … 357 359 """Extracts user information given its name.""" 358 360 user = StorageUser(self, username) 359 username = self.unicodeToDatabase(username)361 username = unicodeToDatabase(username) 360 362 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "description"], base=self.info["userbase"]) 361 363 if result : 362 364 fields = result[0][1] 363 365 user.ident = result[0][0] 364 user.Description = self.databaseToUnicode(fields.get("description", [None])[0])366 user.Description = databaseToUnicode(fields.get("description", [None])[0]) 365 367 user.Email = fields.get(self.info["usermail"], [None])[0] 366 368 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] … … 395 397 description = "" 396 398 else : 397 description = self.databaseToUnicode(base64.decodestring(description))399 description = databaseToUnicode(base64.decodestring(description)) 398 400 if amount.endswith(" #") : 399 401 amount = amount[:-2] # TODO : should be catched earlier, the bug is above I think … … 405 407 """Extracts group information given its name.""" 406 408 group = StorageGroup(self, groupname) 407 groupname = self.unicodeToDatabase(groupname)409 groupname = unicodeToDatabase(groupname) 408 410 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), ["pykotaGroupName", "pykotaLimitBy", "description"], base=self.info["groupbase"]) 409 411 if result : 410 412 fields = result[0][1] 411 413 group.ident = result[0][0] 412 group.Name = fields.get("pykotaGroupName", [ self.databaseToUnicode(groupname)])[0]413 group.Description = self.databaseToUnicode(fields.get("description", [None])[0])414 group.Name = fields.get("pykotaGroupName", [databaseToUnicode(groupname)])[0] 415 group.Description = databaseToUnicode(fields.get("description", [None])[0]) 414 416 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 415 417 group.AccountBalance = 0.0 … … 425 427 """Extracts printer information given its name : returns first matching printer.""" 426 428 printer = StoragePrinter(self, printername) 427 printername = self.unicodeToDatabase(printername)429 printername = unicodeToDatabase(printername) 428 430 result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" \ 429 431 % (printername, self.info["printerrdn"], printername), \ … … 435 437 fields = result[0][1] # take only first matching printer, ignore the rest 436 438 printer.ident = result[0][0] 437 printer.Name = fields.get("pykotaPrinterName", [ self.databaseToUnicode(printername)])[0]439 printer.Name = fields.get("pykotaPrinterName", [databaseToUnicode(printername)])[0] 438 440 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 439 441 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) … … 445 447 printer.PassThrough = 0 446 448 printer.uniqueMember = fields.get("uniqueMember", []) 447 printer.Description = self.databaseToUnicode(fields.get("description", [""])[0])449 printer.Description = databaseToUnicode(fields.get("description", [""])[0]) 448 450 printer.Exists = True 449 451 return printer … … 458 460 base = self.info["userquotabase"] 459 461 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % \ 460 ( self.unicodeToDatabase(user.Name), self.unicodeToDatabase(printer.Name)), \462 (unicodeToDatabase(user.Name), unicodeToDatabase(printer.Name)), \ 461 463 ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount", "pykotaMaxJobSize"], \ 462 464 base=base) … … 503 505 base = self.info["groupquotabase"] 504 506 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 505 ( self.unicodeToDatabase(group.Name), self.unicodeToDatabase(printer.Name)), \507 (unicodeToDatabase(group.Name), unicodeToDatabase(printer.Name)), \ 506 508 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaMaxJobSize"], \ 507 509 base=base) … … 535 537 grouppquota.PageCounter = 0 536 538 grouppquota.LifePageCounter = 0 537 usernamesfilter = "".join(["(pykotaUserName=%s)" % self.unicodeToDatabase(member.Name) for member in self.getGroupMembers(group)])539 usernamesfilter = "".join(["(pykotaUserName=%s)" % unicodeToDatabase(member.Name) for member in self.getGroupMembers(group)]) 538 540 if usernamesfilter : 539 541 usernamesfilter = "(|%s)" % usernamesfilter … … 543 545 base = self.info["userquotabase"] 544 546 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % \ 545 ( self.unicodeToDatabase(printer.Name), usernamesfilter), \547 (unicodeToDatabase(printer.Name), usernamesfilter), \ 546 548 ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 547 549 if result : … … 555 557 """Extracts a printer's last job information.""" 556 558 lastjob = StorageLastJob(self, printer) 557 pname = self.unicodeToDatabase(printer.Name)559 pname = unicodeToDatabase(printer.Name) 558 560 result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % \ 559 561 (pname, self.info["printerrdn"], pname), \ … … 591 593 lastjob.ident = result[0][0] 592 594 lastjob.JobId = fields.get("pykotaJobId")[0] 593 lastjob.UserName = self.databaseToUnicode(fields.get("pykotaUserName")[0])595 lastjob.UserName = databaseToUnicode(fields.get("pykotaUserName")[0]) 594 596 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 595 597 try : … … 602 604 lastjob.JobPrice = None 603 605 lastjob.JobAction = fields.get("pykotaAction", [""])[0] 604 lastjob.JobFileName = self.databaseToUnicode(fields.get("pykotaFileName", [""])[0])605 lastjob.JobTitle = self.databaseToUnicode(fields.get("pykotaTitle", [""])[0])606 lastjob.JobFileName = databaseToUnicode(fields.get("pykotaFileName", [""])[0]) 607 lastjob.JobTitle = databaseToUnicode(fields.get("pykotaTitle", [""])[0]) 606 608 lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 607 lastjob.JobOptions = self.databaseToUnicode(fields.get("pykotaOptions", [""])[0])609 lastjob.JobOptions = databaseToUnicode(fields.get("pykotaOptions", [""])[0]) 608 610 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 609 611 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 610 lastjob.JobBillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [None])[0])612 lastjob.JobBillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [None])[0]) 611 613 lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 612 614 lastjob.JobPages = fields.get("pykotaPages", [""])[0] … … 630 632 """Returns the group's members list.""" 631 633 groupmembers = [] 632 gname = self.unicodeToDatabase(group.Name)634 gname = unicodeToDatabase(group.Name) 633 635 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % \ 634 636 (gname, self.info["grouprdn"], gname), \ … … 637 639 if result : 638 640 for username in result[0][1].get(self.info["groupmembers"], []) : 639 groupmembers.append(self.getUser( self.databaseToUnicode(username)))641 groupmembers.append(self.getUser(databaseToUnicode(username))) 640 642 return groupmembers 641 643 … … 643 645 """Returns the user's groups list.""" 644 646 groups = [] 645 uname = self.unicodeToDatabase(user.Name)647 uname = unicodeToDatabase(user.Name) 646 648 result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % \ 647 649 (self.info["groupmembers"], uname), \ … … 650 652 if result : 651 653 for (groupid, fields) in result : 652 groupname = self.databaseToUnicode((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0])654 groupname = databaseToUnicode((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0]) 653 655 group = self.getFromCache("GROUPS", groupname) 654 656 if group is None : … … 681 683 for (printerid, fields) in result : 682 684 if printerid != printer.ident : # In case of integrity violation. 683 parentprinter = self.getPrinter( self.databaseToUnicode(fields.get("pykotaPrinterName")[0]))685 parentprinter = self.getPrinter(databaseToUnicode(fields.get("pykotaPrinterName")[0])) 684 686 if parentprinter.Exists : 685 687 pgroups.append(parentprinter) … … 703 705 patdict[p] = None 704 706 for (printerid, fields) in result : 705 printername = self.databaseToUnicode(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0])707 printername = databaseToUnicode(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0]) 706 708 if patdict.has_key(printername) or self.tool.matchString(printername, patterns) : 707 709 printer = StoragePrinter(self, printername) … … 716 718 printer.PassThrough = 0 717 719 printer.uniqueMember = fields.get("uniqueMember", []) 718 printer.Description = self.databaseToUnicode(fields.get("description", [""])[0])720 printer.Description = databaseToUnicode(fields.get("description", [""])[0]) 719 721 printer.Exists = True 720 722 printers.append(printer) … … 739 741 patdict[p] = None 740 742 for (userid, fields) in result : 741 username = self.databaseToUnicode(fields.get("pykotaUserName", [""])[0] or fields.get(self.info["userrdn"], [""])[0])743 username = databaseToUnicode(fields.get("pykotaUserName", [""])[0] or fields.get(self.info["userrdn"], [""])[0]) 742 744 if patdict.has_key(username) or self.tool.matchString(username, patterns) : 743 745 user = StorageUser(self, username) … … 745 747 user.Email = fields.get(self.info["usermail"], [None])[0] 746 748 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 747 user.Description = self.databaseToUnicode(fields.get("description", [""])[0])748 uname = self.unicodeToDatabase(username)749 user.Description = databaseToUnicode(fields.get("description", [""])[0]) 750 uname = unicodeToDatabase(username) 749 751 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % \ 750 752 (uname, self.info["balancerdn"], uname), \ … … 780 782 description = "" 781 783 else : 782 description = self.databaseToUnicode(base64.decodestring(description))784 description = databaseToUnicode(base64.decodestring(description)) 783 785 if amount.endswith(" #") : 784 786 amount = amount[:-2] # TODO : should be catched earlier, the bug is above I think … … 806 808 patdict[p] = None 807 809 for (groupid, fields) in result : 808 groupname = self.databaseToUnicode(fields.get("pykotaGroupName", [""])[0] or fields.get(self.info["grouprdn"], [""])[0])810 groupname = databaseToUnicode(fields.get("pykotaGroupName", [""])[0] or fields.get(self.info["grouprdn"], [""])[0]) 809 811 if patdict.has_key(groupname) or self.tool.matchString(groupname, patterns) : 810 812 group = StorageGroup(self, groupname) 811 813 group.ident = groupid 812 group.Name = fields.get("pykotaGroupName", [ self.databaseToUnicode(groupname)])[0]814 group.Name = fields.get("pykotaGroupName", [databaseToUnicode(groupname)])[0] 813 815 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 814 group.Description = self.databaseToUnicode(fields.get("description", [""])[0])816 group.Description = databaseToUnicode(fields.get("description", [""])[0]) 815 817 group.AccountBalance = 0.0 816 818 group.LifeTimePaid = 0.0 … … 827 829 """Returns the list of users who uses a given printer, along with their quotas.""" 828 830 usersandquotas = [] 829 pname = self.unicodeToDatabase(printer.Name)830 names = [ self.unicodeToDatabase(n) for n in names]831 pname = unicodeToDatabase(printer.Name) 832 names = [unicodeToDatabase(n) for n in names] 831 833 if self.info["userquotabase"].lower() == "user" : 832 834 base = self.info["userbase"] … … 839 841 if result : 840 842 for (userquotaid, fields) in result : 841 user = self.getUser( self.databaseToUnicode(fields.get("pykotaUserName")[0]))843 user = self.getUser(databaseToUnicode(fields.get("pykotaUserName")[0])) 842 844 userpquota = StorageUserPQuota(self, user, printer) 843 845 userpquota.ident = userquotaid … … 872 874 """Returns the list of groups which uses a given printer, along with their quotas.""" 873 875 groupsandquotas = [] 874 pname = self.unicodeToDatabase(printer.Name)875 names = [ self.unicodeToDatabase(n) for n in names]876 pname = unicodeToDatabase(printer.Name) 877 names = [unicodeToDatabase(n) for n in names] 876 878 if self.info["groupquotabase"].lower() == "group" : 877 879 base = self.info["groupbase"] … … 884 886 if result : 885 887 for (groupquotaid, fields) in result : 886 group = self.getGroup( self.databaseToUnicode(fields.get("pykotaGroupName")[0]))888 group = self.getGroup(databaseToUnicode(fields.get("pykotaGroupName")[0])) 887 889 grouppquota = self.getGroupPQuota(group, printer) 888 890 groupsandquotas.append((group, grouppquota)) … … 895 897 if oldentry.Exists : 896 898 return oldentry # we return the existing entry 897 printername = self.unicodeToDatabase(printer.Name)899 printername = unicodeToDatabase(printer.Name) 898 900 fields = { self.info["printerrdn"] : printername, 899 901 "objectClass" : ["pykotaObject", "pykotaPrinter"], … … 902 904 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 903 905 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 904 "description" : self.unicodeToDatabase(printer.Description or ""),906 "description" : unicodeToDatabase(printer.Description or ""), 905 907 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 906 908 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), … … 916 918 if oldentry.Exists : 917 919 return oldentry # we return the existing entry 918 uname = self.unicodeToDatabase(user.Name)920 uname = unicodeToDatabase(user.Name) 919 921 newfields = { 920 922 "pykotaUserName" : uname, 921 923 "pykotaLimitBy" : (user.LimitBy or "quota"), 922 "description" : self.unicodeToDatabase(user.Description or ""),924 "description" : unicodeToDatabase(user.Description or ""), 923 925 self.info["usermail"] : user.Email or "", 924 926 } … … 991 993 if oldentry.Exists : 992 994 return oldentry # we return the existing entry 993 gname = self.unicodeToDatabase(group.Name)995 gname = unicodeToDatabase(group.Name) 994 996 newfields = { 995 997 "pykotaGroupName" : gname, 996 998 "pykotaLimitBy" : (group.LimitBy or "quota"), 997 "description" : self.unicodeToDatabase(group.Description or "")999 "description" : unicodeToDatabase(group.Description or "") 998 1000 } 999 1001 mustadd = 1 … … 1040 1042 if not fields.has_key(self.info["groupmembers"]) : 1041 1043 fields[self.info["groupmembers"]] = [] 1042 fields[self.info["groupmembers"]].append( self.unicodeToDatabase(user.Name))1044 fields[self.info["groupmembers"]].append(unicodeToDatabase(user.Name)) 1043 1045 self.doModify(group.ident, fields) 1044 1046 group.Members.append(user) … … 1053 1055 fields[self.info["groupmembers"]] = [] 1054 1056 try : 1055 fields[self.info["groupmembers"]].remove( self.unicodeToDatabase(user.Name))1057 fields[self.info["groupmembers"]].remove(unicodeToDatabase(user.Name)) 1056 1058 except ValueError : 1057 1059 pass # TODO : Strange, shouldn't it be there ? … … 1067 1069 return oldentry # we return the existing entry 1068 1070 uuid = self.genUUID() 1069 uname = self.unicodeToDatabase(upq.User.Name)1070 pname = self.unicodeToDatabase(upq.Printer.Name)1071 uname = unicodeToDatabase(upq.User.Name) 1072 pname = unicodeToDatabase(upq.Printer.Name) 1071 1073 fields = { "cn" : uuid, 1072 1074 "objectClass" : ["pykotaObject", "pykotaUserPQuota"], … … 1095 1097 return oldentry # we return the existing entry 1096 1098 uuid = self.genUUID() 1097 gname = self.unicodeToDatabase(gpq.Group.Name)1098 pname = self.unicodeToDatabase(gpq.Printer.Name)1099 gname = unicodeToDatabase(gpq.Group.Name) 1100 pname = unicodeToDatabase(gpq.Printer.Name) 1099 1101 fields = { "cn" : uuid, 1100 1102 "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], … … 1116 1118 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 1117 1119 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 1118 "description" : self.unicodeToDatabase(printer.Description or ""),1120 "description" : unicodeToDatabase(printer.Description or ""), 1119 1121 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 1120 1122 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), … … 1126 1128 newfields = { 1127 1129 "pykotaLimitBy" : (user.LimitBy or "quota"), 1128 "description" : self.unicodeToDatabase(user.Description or ""),1130 "description" : unicodeToDatabase(user.Description or ""), 1129 1131 self.info["usermail"] : user.Email or "", 1130 1132 } … … 1141 1143 newfields = { 1142 1144 "pykotaLimitBy" : (group.LimitBy or "quota"), 1143 "description" : self.unicodeToDatabase(group.Description or ""),1145 "description" : unicodeToDatabase(group.Description or ""), 1144 1146 } 1145 1147 self.doModify(group.ident, newfields) … … 1178 1180 payments = [] 1179 1181 for payment in user.Payments : 1180 payments.append("%s # %s # %s" % (payment[0], str(payment[1]), base64.encodestring( self.unicodeToDatabase(payment[2])).strip()))1181 payments.append("%s # %s # %s" % (str(DateTime.now()), str(amount), base64.encodestring( self.unicodeToDatabase(comment)).strip()))1182 payments.append("%s # %s # %s" % (payment[0], str(payment[1]), base64.encodestring(unicodeToDatabase(payment[2])).strip())) 1183 payments.append("%s # %s # %s" % (str(DateTime.now()), str(amount), base64.encodestring(unicodeToDatabase(comment)).strip())) 1182 1184 fields = { 1183 1185 "pykotaPayments" : payments, … … 1195 1197 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 1196 1198 """Adds a job in a printer's history.""" 1197 uname = self.unicodeToDatabase(user.Name)1198 pname = self.unicodeToDatabase(printer.Name)1199 uname = unicodeToDatabase(user.Name) 1200 pname = unicodeToDatabase(printer.Name) 1199 1201 if (not self.disablehistory) or (not printer.LastJob.Exists) : 1200 1202 uuid = self.genUUID() … … 1214 1216 "pykotaPrinterPageCounter" : str(pagecounter), 1215 1217 "pykotaAction" : action, 1216 "pykotaFileName" : ((filename is None) and "None") or self.unicodeToDatabase(filename),1217 "pykotaTitle" : ((title is None) and "None") or self.unicodeToDatabase(title),1218 "pykotaFileName" : ((filename is None) and "None") or unicodeToDatabase(filename), 1219 "pykotaTitle" : ((title is None) and "None") or unicodeToDatabase(title), 1218 1220 "pykotaCopies" : str(copies), 1219 "pykotaOptions" : ((options is None) and "None") or self.unicodeToDatabase(options),1221 "pykotaOptions" : ((options is None) and "None") or unicodeToDatabase(options), 1220 1222 "pykotaHostName" : str(clienthost), 1221 1223 "pykotaJobSizeBytes" : str(jobsizebytes), 1222 1224 "pykotaMD5Sum" : str(jobmd5sum), 1223 1225 "pykotaPages" : jobpages, # don't add this attribute if it is not set, so no string conversion 1224 "pykotaBillingCode" : self.unicodeToDatabase(jobbilling), # don't add this attribute if it is not set, so no string conversion1226 "pykotaBillingCode" : unicodeToDatabase(jobbilling), # don't add this attribute if it is not set, so no string conversion 1225 1227 "pykotaPrecomputedJobSize" : str(precomputedsize), 1226 1228 "pykotaPrecomputedJobPrice" : str(precomputedprice), … … 1314 1316 where = [] 1315 1317 if user is not None : 1316 where.append("(pykotaUserName=%s)" % self.unicodeToDatabase(user.Name))1318 where.append("(pykotaUserName=%s)" % unicodeToDatabase(user.Name)) 1317 1319 if printer is not None : 1318 where.append("(pykotaPrinterName=%s)" % self.unicodeToDatabase(printer.Name))1320 where.append("(pykotaPrinterName=%s)" % unicodeToDatabase(printer.Name)) 1319 1321 if hostname is not None : 1320 1322 where.append("(pykotaHostName=%s)" % hostname) 1321 1323 if billingcode is not None : 1322 where.append("(pykotaBillingCode=%s)" % self.unicodeToDatabase(billingcode))1324 where.append("(pykotaBillingCode=%s)" % unicodeToDatabase(billingcode)) 1323 1325 if jobid is not None : 1324 where.append("(pykotaJobId=%s)" % jobid) # TODO : jobid is text, so self.unicodeToDatabase(jobid) but do all of them as well.1326 where.append("(pykotaJobId=%s)" % jobid) # TODO : jobid is text, so unicodeToDatabase(jobid) but do all of them as well. 1325 1327 if where : 1326 1328 where = "(&%s)" % "".join([precond] + where) … … 1363 1365 job.JobPrice = None 1364 1366 job.JobAction = fields.get("pykotaAction", [""])[0] 1365 job.JobFileName = self.databaseToUnicode(fields.get("pykotaFileName", [""])[0])1366 job.JobTitle = self.databaseToUnicode(fields.get("pykotaTitle", [""])[0])1367 job.JobFileName = databaseToUnicode(fields.get("pykotaFileName", [""])[0]) 1368 job.JobTitle = databaseToUnicode(fields.get("pykotaTitle", [""])[0]) 1367 1369 job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 1368 job.JobOptions = self.databaseToUnicode(fields.get("pykotaOptions", [""])[0])1370 job.JobOptions = databaseToUnicode(fields.get("pykotaOptions", [""])[0]) 1369 1371 job.JobHostName = fields.get("pykotaHostName", [""])[0] 1370 1372 job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 1371 job.JobBillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [None])[0])1373 job.JobBillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [None])[0]) 1372 1374 job.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 1373 1375 job.JobPages = fields.get("pykotaPages", [""])[0] … … 1389 1391 ((end is None) and (job.JobDate >= start)) or \ 1390 1392 ((job.JobDate >= start) and (job.JobDate <= end)) : 1391 job.UserName = self.databaseToUnicode(fields.get("pykotaUserName")[0])1392 job.PrinterName = self.databaseToUnicode(fields.get("pykotaPrinterName")[0])1393 job.UserName = databaseToUnicode(fields.get("pykotaUserName")[0]) 1394 job.PrinterName = databaseToUnicode(fields.get("pykotaPrinterName")[0]) 1393 1395 job.Exists = True 1394 1396 jobs.append(job) … … 1400 1402 def deleteUser(self, user) : 1401 1403 """Completely deletes an user from the Quota Storage.""" 1402 uname = self.unicodeToDatabase(user.Name)1404 uname = unicodeToDatabase(user.Name) 1403 1405 todelete = [] 1404 1406 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % uname, base=self.info["jobbase"]) … … 1418 1420 # if last job of current printer was printed by the user 1419 1421 # to delete, we also need to delete the printer's last job entry. 1420 printer = self.getPrinter( self.databaseToUnicode(fields["pykotaPrinterName"][0]))1422 printer = self.getPrinter(databaseToUnicode(fields["pykotaPrinterName"][0])) 1421 1423 if printer.LastJob.UserName == user.Name : 1422 1424 todelete.append(printer.LastJob.lastjobident) … … 1453 1455 def deleteGroup(self, group) : 1454 1456 """Completely deletes a group from the Quota Storage.""" 1455 gname = self.unicodeToDatabase(group.Name)1457 gname = unicodeToDatabase(group.Name) 1456 1458 if self.info["groupquotabase"].lower() == "group" : 1457 1459 base = self.info["groupbase"] … … 1524 1526 def deleteUserPQuota(self, upquota) : 1525 1527 """Completely deletes an user print quota entry from the database.""" 1526 uname = self.unicodeToDatabase(upquota.User.Name)1527 pname = self.unicodeToDatabase(upquota.Printer.Name)1528 uname = unicodeToDatabase(upquota.User.Name) 1529 pname = unicodeToDatabase(upquota.Printer.Name) 1528 1530 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s)(pykotaPrinterName=%s))" \ 1529 1531 % (uname, pname), \ … … 1541 1543 def deletePrinter(self, printer) : 1542 1544 """Completely deletes a printer from the Quota Storage.""" 1543 pname = self.unicodeToDatabase(printer.Name)1545 pname = unicodeToDatabase(printer.Name) 1544 1546 result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % pname, base=self.info["lastjobbase"]) 1545 1547 for (ident, fields) in result : … … 1764 1766 """Extracts billing code information given its label : returns first matching billing code.""" 1765 1767 code = StorageBillingCode(self, label) 1766 ulabel = self.unicodeToDatabase(label)1768 ulabel = unicodeToDatabase(label) 1767 1769 result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % \ 1768 1770 ulabel, \ … … 1772 1774 fields = result[0][1] # take only first matching code, ignore the rest 1773 1775 code.ident = result[0][0] 1774 code.BillingCode = self.databaseToUnicode(fields.get("pykotaBillingCode", [ulabel])[0])1776 code.BillingCode = databaseToUnicode(fields.get("pykotaBillingCode", [ulabel])[0]) 1775 1777 code.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 1776 1778 code.Balance = float(fields.get("pykotaBalance", [0.0])[0]) 1777 code.Description = self.databaseToUnicode(fields.get("description", [""])[0])1779 code.Description = databaseToUnicode(fields.get("description", [""])[0]) 1778 1780 code.Exists = True 1779 1781 return code … … 1788 1790 fields = { "objectClass" : ["pykotaObject", "pykotaBilling"], 1789 1791 "cn" : uuid, 1790 "pykotaBillingCode" : self.unicodeToDatabase(bcode.BillingCode),1792 "pykotaBillingCode" : unicodeToDatabase(bcode.BillingCode), 1791 1793 "pykotaPageCounter" : str(bcode.PageCounter or 0), 1792 1794 "pykotaBalance" : str(bcode.Balance or 0.0), 1793 "description" : self.unicodeToDatabase(bcode.Description or ""),1795 "description" : unicodeToDatabase(bcode.Description or ""), 1794 1796 } 1795 1797 self.doAdd(dn, fields) … … 1800 1802 """Sets the new description for a billing code.""" 1801 1803 fields = { 1802 "description" : self.unicodeToDatabase(bcode.Description or ""),1804 "description" : unicodeToDatabase(bcode.Description or ""), 1803 1805 "pykotaPageCounter" : str(bcode.PageCounter or 0), 1804 1806 "pykotaBalance" : str(bcode.Balance or 0.0), … … 1822 1824 patdict[p] = None 1823 1825 for (codeid, fields) in result : 1824 codename = self.databaseToUnicode(fields.get("pykotaBillingCode", [""])[0])1826 codename = databaseToUnicode(fields.get("pykotaBillingCode", [""])[0]) 1825 1827 if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : 1826 1828 code = StorageBillingCode(self, codename) … … 1828 1830 code.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 1829 1831 code.Balance = float(fields.get("pykotaBalance", [0.0])[0]) 1830 code.Description = self.databaseToUnicode(fields.get("description", [""])[0])1832 code.Description = databaseToUnicode(fields.get("description", [""])[0]) 1831 1833 code.Exists = True 1832 1834 codes.append(code)