Changeset 2652
- Timestamp:
- 02/08/06 13:24:06 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r2622 r2652 287 287 raise PyKotaStorageError, message 288 288 289 def filterNames(self, records, attribute ) :289 def filterNames(self, records, attribute, patterns=None) : 290 290 """Returns a list of 'attribute' from a list of records. 291 291 … … 297 297 if attrval is None : 298 298 self.tool.printInfo("Object %s has no %s attribute !" % (dn, attribute), "error") 299 else : 300 result.append(attrval) 299 else : 300 if patterns : 301 if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : 302 patterns = [ patterns ] 303 patterns = [self.userCharsetToDatabase(p) for p in patterns] 304 if self.tool.matchString(attrval, patterns) : 305 result.append(attrval) 306 else : 307 result.append(attrval) 301 308 return result 302 309 303 310 def getAllBillingCodes(self, billingcode=None) : 304 311 """Extracts all billing codes or only the billing codes matching the optional parameter.""" 305 billingcodes = []306 312 ldapfilter = "objectClass=pykotaBilling" 307 if billingcode :308 ldapfilter = "(&(%s)(pykotaBillingCode=%s))" % (ldapfilter, self.userCharsetToDatabase(billingcode))309 313 result = self.doSearch(ldapfilter, ["pykotaBillingCode"], base=self.info["billingcodebase"]) 310 314 if result : 311 billingcodes = [self.databaseToUserCharset(bc) for bc in self.filterNames(result, "pykotaBillingCode")] 312 return billingcodes 315 return [self.databaseToUserCharset(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)] 316 else : 317 return [] 313 318 314 319 def getAllPrintersNames(self, printername=None) : 315 320 """Extracts all printer names or only the printers' names matching the optional parameter.""" 316 printernames = []317 321 ldapfilter = "objectClass=pykotaPrinter" 318 if printername :319 ldapfilter = "(&(%s)(pykotaPrinterName=%s))" % (ldapfilter, printername)320 322 result = self.doSearch(ldapfilter, ["pykotaPrinterName"], base=self.info["printerbase"]) 321 323 if result : 322 printernames = self.filterNames(result, "pykotaPrinterName") 323 return printernames 324 return self.filterNames(result, "pykotaPrinterName", printername) 325 else : 326 return [] 324 327 325 328 def getAllUsersNames(self, username=None) : 326 329 """Extracts all user names or only the users' names matching the optional parameter.""" 327 usernames = []328 330 ldapfilter = "objectClass=pykotaAccount" 329 if username :330 ldapfilter = "(&(%s)(pykotaUserName=%s))" % (ldapfilter, username)331 331 result = self.doSearch(ldapfilter, ["pykotaUserName"], base=self.info["userbase"]) 332 332 if result : 333 usernames = self.filterNames(result, "pykotaUserName") 334 return usernames 333 return self.filterNames(result, "pykotaUserName", username) 334 else : 335 return [] 335 336 336 337 def getAllGroupsNames(self, groupname=None) : 337 338 """Extracts all group names or only the groups' names matching the optional parameter.""" 338 groupnames = []339 339 ldapfilter = "objectClass=pykotaGroup" 340 if groupname :341 ldapfilter = "(&(%s)(pykotaGroupName=%s))" % (ldapfilter, groupname)342 340 result = self.doSearch(ldapfilter, ["pykotaGroupName"], base=self.info["groupbase"]) 343 341 if result : 344 groupnames = self.filterNames(result, "pykotaGroupName") 345 return groupnames 342 return self.filterNames(result, "pykotaGroupName", groupname) 343 else : 344 return [] 346 345 347 346 def getUserNbJobsFromHistory(self, user) : 348 347 """Returns the number of jobs the user has in history.""" 349 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % user.Name, None, base=self.info["jobbase"])348 result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % self.userCharsetToDatabase(user.Name), None, base=self.info["jobbase"]) 350 349 return len(result) 351 350 … … 353 352 """Extracts user information given its name.""" 354 353 user = StorageUser(self, username) 354 username = self.userCharsetToDatabase(username) 355 355 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "pykotaOverCharge"], base=self.info["userbase"]) 356 356 if result : 357 357 fields = result[0][1] 358 358 user.ident = result[0][0] 359 user.Name = fields.get("pykotaUserName", [ username])[0]359 user.Name = fields.get("pykotaUserName", [self.databaseToUserCharset(username)])[0] 360 360 user.Email = fields.get(self.info["usermail"], [None])[0] 361 361 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] … … 398 398 """Extracts group information given its name.""" 399 399 group = StorageGroup(self, groupname) 400 groupname = self.userCharsetToDatabase(groupname) 400 401 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), ["pykotaGroupName", "pykotaLimitBy"], base=self.info["groupbase"]) 401 402 if result : 402 403 fields = result[0][1] 403 404 group.ident = result[0][0] 404 group.Name = fields.get("pykotaGroupName", [ groupname])[0]405 group.Name = fields.get("pykotaGroupName", [self.databaseToUserCharset(groupname)])[0] 405 406 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 406 407 group.AccountBalance = 0.0 … … 416 417 """Extracts printer information given its name : returns first matching printer.""" 417 418 printer = StoragePrinter(self, printername) 419 printername = self.userCharsetToDatabase(printername) 418 420 result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" \ 419 421 % (printername, self.info["printerrdn"], printername), \ … … 425 427 fields = result[0][1] # take only first matching printer, ignore the rest 426 428 printer.ident = result[0][0] 427 printer.Name = fields.get("pykotaPrinterName", [ printername])[0]429 printer.Name = fields.get("pykotaPrinterName", [self.databaseToUserCharset(printername)])[0] 428 430 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 429 431 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) … … 447 449 else : 448 450 base = self.info["userquotabase"] 449 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 451 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % \ 452 (self.userCharsetToDatabase(user.Name), self.userCharsetToDatabase(printer.Name)), \ 453 ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], \ 454 base=base) 450 455 if result : 451 456 fields = result[0][1] … … 483 488 else : 484 489 base = self.info["groupquotabase"] 485 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % (group.Name, printer.Name), ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=base) 490 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 491 (self.userCharsetToDatabase(group.Name), self.userCharsetToDatabase(printer.Name)), \ 492 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], \ 493 base=base) 486 494 if result : 487 495 fields = result[0][1] … … 507 515 grouppquota.PageCounter = 0 508 516 grouppquota.LifePageCounter = 0 509 usernamesfilter = "".join(["(pykotaUserName=%s)" % member.Namefor member in self.getGroupMembers(group)])517 usernamesfilter = "".join(["(pykotaUserName=%s)" % self.userCharsetToDatabase(member.Name) for member in self.getGroupMembers(group)]) 510 518 if usernamesfilter : 511 519 usernamesfilter = "(|%s)" % usernamesfilter … … 514 522 else : 515 523 base = self.info["userquotabase"] 516 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % (printer.Name, usernamesfilter), ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 524 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % \ 525 (self.userCharsetToDatabase(printer.Name), usernamesfilter), \ 526 ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 517 527 if result : 518 528 for userpquota in result : … … 525 535 """Extracts a printer's last job information.""" 526 536 lastjob = StorageLastJob(self, printer) 527 result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % (printer.Name, self.info["printerrdn"], printer.Name), ["pykotaLastJobIdent"], base=self.info["lastjobbase"]) 537 pname = self.userCharsetToDatabase(printer.Name) 538 result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % \ 539 (pname, self.info["printerrdn"], pname), \ 540 ["pykotaLastJobIdent"], \ 541 base=self.info["lastjobbase"]) 528 542 if result : 529 543 lastjob.lastjobident = result[0][0] … … 557 571 lastjob.ident = result[0][0] 558 572 lastjob.JobId = fields.get("pykotaJobId")[0] 559 lastjob.UserName = fields.get("pykotaUserName")[0]573 lastjob.UserName = self.databaseToUserCharset(fields.get("pykotaUserName")[0]) 560 574 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 561 575 try : … … 596 610 """Returns the group's members list.""" 597 611 groupmembers = [] 598 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (group.Name, self.info["grouprdn"], group.Name), [self.info["groupmembers"]], base=self.info["groupbase"]) 612 gname = self.userCharsetToDatabase(group.Name) 613 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % \ 614 (gname, self.info["grouprdn"], gname), \ 615 [self.info["groupmembers"]], \ 616 base=self.info["groupbase"]) 599 617 if result : 600 618 for username in result[0][1].get(self.info["groupmembers"], []) : 601 groupmembers.append(self.getUser( username))619 groupmembers.append(self.getUser(self.databaseToUserCharset(username))) 602 620 return groupmembers 603 621 … … 605 623 """Returns the user's groups list.""" 606 624 groups = [] 607 result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % (self.info["groupmembers"], user.Name), [self.info["grouprdn"], "pykotaGroupName", "pykotaLimitBy"], base=self.info["groupbase"]) 625 uname = self.userCharsetToDatabase(user.Name) 626 result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % \ 627 (self.info["groupmembers"], uname), \ 628 [self.info["grouprdn"], "pykotaGroupName", "pykotaLimitBy"], \ 629 base=self.info["groupbase"]) 608 630 if result : 609 631 for (groupid, fields) in result : 610 groupname = (fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0]632 groupname = self.databaseToUserCharset((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0]) 611 633 group = self.getFromCache("GROUPS", groupname) 612 634 if group is None : … … 632 654 """Get all the printer groups this printer is a member of.""" 633 655 pgroups = [] 634 result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % printer.ident, ["pykotaPrinterName"], base=self.info["printerbase"]) 656 result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % \ 657 printer.ident, \ 658 ["pykotaPrinterName"], \ 659 base=self.info["printerbase"]) 635 660 if result : 636 661 for (printerid, fields) in result : 637 662 if printerid != printer.ident : # In case of integrity violation. 638 parentprinter = self.getPrinter( fields.get("pykotaPrinterName")[0])663 parentprinter = self.getPrinter(self.databaseToUserCharset(fields.get("pykotaPrinterName")[0])) 639 664 if parentprinter.Exists : 640 665 pgroups.append(parentprinter) … … 645 670 printers = [] 646 671 # see comment at the same place in pgstorage.py 647 result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "pykotaMaxJobSize", "pykotaPassThrough", "uniqueMember", "description"], base=self.info["printerbase"]) 672 printerpattern = [self.userCharsetToDatabase(p) for p in printerpattern.split(",")] 673 result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % \ 674 "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern]), \ 675 ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "pykotaMaxJobSize", "pykotaPassThrough", "uniqueMember", "description"], \ 676 base=self.info["printerbase"]) 648 677 if result : 649 678 for (printerid, fields) in result : 650 printername = fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0]679 printername = self.databaseToUserCharset(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0]) 651 680 printer = StoragePrinter(self, printername) 652 681 printer.ident = printerid … … 669 698 """Returns the list of users who uses a given printer, along with their quotas.""" 670 699 usersandquotas = [] 700 pname = self.userCharsetToDatabase(printer.Name) 701 names = [self.userCharsetToDatabase(n) for n in names] 671 702 if self.info["userquotabase"].lower() == "user" : 672 703 base = self.info["userbase"] 673 704 else : 674 705 base = self.info["userquotabase"] 675 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 706 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % \ 707 (pname, "".join(["(pykotaUserName=%s)" % uname for uname in names])), \ 708 ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], \ 709 base=base) 676 710 if result : 677 711 for (userquotaid, fields) in result : 678 user = self.getUser( fields.get("pykotaUserName")[0])712 user = self.getUser(self.databaseToUserCharset(fields.get("pykotaUserName")[0])) 679 713 userpquota = StorageUserPQuota(self, user, printer) 680 714 userpquota.ident = userquotaid … … 709 743 """Returns the list of groups which uses a given printer, along with their quotas.""" 710 744 groupsandquotas = [] 745 pname = self.userCharsetToDatabase(printer.Name) 746 names = [self.userCharsetToDatabase(n) for n in names] 711 747 if self.info["groupquotabase"].lower() == "group" : 712 748 base = self.info["groupbase"] 713 749 else : 714 750 base = self.info["groupquotabase"] 715 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), ["pykotaGroupName"], base=base) 751 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % \ 752 (pname, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), \ 753 ["pykotaGroupName"], \ 754 base=base) 716 755 if result : 717 756 for (groupquotaid, fields) in result : 718 group = self.getGroup( fields.get("pykotaGroupName")[0])757 group = self.getGroup(self.databaseToUserCharset(fields.get("pykotaGroupName")[0])) 719 758 grouppquota = self.getGroupPQuota(group, printer) 720 759 groupsandquotas.append((group, grouppquota)) … … 724 763 def addPrinter(self, printername) : 725 764 """Adds a printer to the quota storage, returns it.""" 765 printername = self.userCharsetToDatabase(printername) 726 766 fields = { self.info["printerrdn"] : printername, 727 767 "objectClass" : ["pykotaObject", "pykotaPrinter"], … … 739 779 def addUser(self, user) : 740 780 """Adds a user to the quota storage, returns it.""" 781 uname = self.userCharsetToDatabase(user.Name) 741 782 newfields = { 742 "pykotaUserName" : u ser.Name,783 "pykotaUserName" : uname, 743 784 "pykotaLimitBy" : (user.LimitBy or "quota"), 744 785 "pykotaOverCharge" : str(user.OverCharge), … … 753 794 except ValueError : 754 795 (where, action) = (self.info["newuser"].strip(), "fail") 755 result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["userrdn"], user.Name), None, base=self.info["userbase"]) 796 result = self.doSearch("(&(objectClass=%s)(%s=%s))" % \ 797 (where, self.info["userrdn"], uname), \ 798 None, \ 799 base=self.info["userbase"]) 756 800 if result : 757 801 (dn, fields) = result[0] … … 772 816 if mustadd : 773 817 if self.info["userbase"] == self.info["balancebase"] : 774 fields = { self.info["userrdn"] : u ser.Name,818 fields = { self.info["userrdn"] : uname, 775 819 "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"], 776 "cn" : u ser.Name,820 "cn" : uname, 777 821 "pykotaBalance" : str(user.AccountBalance or 0.0), 778 822 "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0), 779 823 } 780 824 else : 781 fields = { self.info["userrdn"] : u ser.Name,825 fields = { self.info["userrdn"] : uname, 782 826 "objectClass" : ["pykotaObject", "pykotaAccount"], 783 "cn" : u ser.Name,827 "cn" : uname, 784 828 } 785 829 fields.update(newfields) 786 dn = "%s=%s,%s" % (self.info["userrdn"], u ser.Name, self.info["userbase"])830 dn = "%s=%s,%s" % (self.info["userrdn"], uname, self.info["userbase"]) 787 831 self.doAdd(dn, fields) 788 832 if self.info["userbase"] != self.info["balancebase"] : 789 fields = { self.info["balancerdn"] : u ser.Name,833 fields = { self.info["balancerdn"] : uname, 790 834 "objectClass" : ["pykotaObject", "pykotaAccountBalance"], 791 "cn" : u ser.Name,835 "cn" : uname, 792 836 "pykotaBalance" : str(user.AccountBalance or 0.0), 793 837 "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0), 794 838 } 795 dn = "%s=%s,%s" % (self.info["balancerdn"], u ser.Name, self.info["balancebase"])839 dn = "%s=%s,%s" % (self.info["balancerdn"], uname, self.info["balancebase"]) 796 840 self.doAdd(dn, fields) 797 841 … … 800 844 def addGroup(self, group) : 801 845 """Adds a group to the quota storage, returns it.""" 846 gname = self.userCharsetToDatabase(group.Name) 802 847 newfields = { 803 "pykotaGroupName" : g roup.Name,848 "pykotaGroupName" : gname, 804 849 "pykotaLimitBy" : (group.LimitBy or "quota"), 805 850 } … … 810 855 except ValueError : 811 856 (where, action) = (self.info["newgroup"].strip(), "fail") 812 result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["grouprdn"], group.Name), None, base=self.info["groupbase"]) 857 result = self.doSearch("(&(objectClass=%s)(%s=%s))" % \ 858 (where, self.info["grouprdn"], gname), \ 859 None, \ 860 base=self.info["groupbase"]) 813 861 if result : 814 862 (dn, fields) = result[0] … … 826 874 827 875 if mustadd : 828 fields = { self.info["grouprdn"] : g roup.Name,876 fields = { self.info["grouprdn"] : gname, 829 877 "objectClass" : ["pykotaObject", "pykotaGroup"], 830 "cn" : g roup.Name,878 "cn" : gname, 831 879 } 832 880 fields.update(newfields) 833 dn = "%s=%s,%s" % (self.info["grouprdn"], g roup.Name, self.info["groupbase"])881 dn = "%s=%s,%s" % (self.info["grouprdn"], gname, self.info["groupbase"]) 834 882 self.doAdd(dn, fields) 835 883 return self.getGroup(group.Name) … … 843 891 if not fields.has_key(self.info["groupmembers"]) : 844 892 fields[self.info["groupmembers"]] = [] 845 fields[self.info["groupmembers"]].append( user.Name)893 fields[self.info["groupmembers"]].append(self.userCharsetToDatabase(user.Name)) 846 894 self.doModify(group.ident, fields) 847 895 group.Members.append(user) … … 850 898 """Initializes a user print quota on a printer.""" 851 899 uuid = self.genUUID() 900 uname = self.userCharsetToDatabase(user.Name) 901 pname = self.userCharsetToDatabase(printer.Name) 852 902 fields = { "cn" : uuid, 853 903 "objectClass" : ["pykotaObject", "pykotaUserPQuota"], 854 "pykotaUserName" : u ser.Name,855 "pykotaPrinterName" : p rinter.Name,904 "pykotaUserName" : uname, 905 "pykotaPrinterName" : pname, 856 906 "pykotaDateLimit" : "None", 857 907 "pykotaPageCounter" : "0", … … 869 919 """Initializes a group print quota on a printer.""" 870 920 uuid = self.genUUID() 921 gname = self.userCharsetToDatabase(group.Name) 922 pname = self.userCharsetToDatabase(printer.Name) 871 923 fields = { "cn" : uuid, 872 924 "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], 873 "pykotaGroupName" : g roup.Name,874 "pykotaPrinterName" : p rinter.Name,925 "pykotaGroupName" : gname, 926 "pykotaPrinterName" : pname, 875 927 "pykotaDateLimit" : "None", 876 928 } … … 1002 1054 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) : 1003 1055 """Adds a job in a printer's history.""" 1056 uname = self.userCharsetToDatabase(user.Name) 1057 pname = self.userCharsetToDatabase(printer.Name) 1004 1058 if (not self.disablehistory) or (not printer.LastJob.Exists) : 1005 1059 uuid = self.genUUID() … … 1014 1068 "objectClass" : ["pykotaObject", "pykotaJob"], 1015 1069 "cn" : uuid, 1016 "pykotaUserName" : u ser.Name,1017 "pykotaPrinterName" : p rinter.Name,1070 "pykotaUserName" : uname, 1071 "pykotaPrinterName" : pname, 1018 1072 "pykotaJobId" : jobid, 1019 1073 "pykotaPrinterPageCounter" : str(pagecounter), … … 1051 1105 "objectClass" : ["pykotaObject", "pykotaLastJob"], 1052 1106 "cn" : lastjuuid, 1053 "pykotaPrinterName" : p rinter.Name,1107 "pykotaPrinterName" : pname, 1054 1108 "pykotaLastJobIdent" : uuid, 1055 1109 } … … 1115 1169 where = [] 1116 1170 if user is not None : 1117 where.append("(pykotaUserName=%s)" % user.Name)1171 where.append("(pykotaUserName=%s)" % self.userCharsetToDatabase(user.Name)) 1118 1172 if printer is not None : 1119 where.append("(pykotaPrinterName=%s)" % printer.Name)1173 where.append("(pykotaPrinterName=%s)" % self.userCharsetToDatabase(printer.Name)) 1120 1174 if hostname is not None : 1121 1175 where.append("(pykotaHostName=%s)" % hostname) … … 1188 1242 ((end is None) and (job.JobDate >= start)) or \ 1189 1243 ((job.JobDate >= start) and (job.JobDate <= end)) : 1190 job.UserName = fields.get("pykotaUserName")[0]1191 job.PrinterName = fields.get("pykotaPrinterName")[0]1244 job.UserName = self.databaseToUserCharset(fields.get("pykotaUserName")[0]) 1245 job.PrinterName = self.databaseToUserCharset(fields.get("pykotaPrinterName")[0]) 1192 1246 job.Exists = 1 1193 1247 jobs.append(job) … … 1199 1253 def deleteUser(self, user) : 1200 1254 """Completely deletes an user from the Quota Storage.""" 1255 uname = self.userCharsetToDatabase(user.Name) 1201 1256 todelete = [] 1202 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % u ser.Name, base=self.info["jobbase"])1257 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % uname, base=self.info["jobbase"]) 1203 1258 for (ident, fields) in result : 1204 1259 todelete.append(ident) … … 1207 1262 else : 1208 1263 base = self.info["userquotabase"] 1209 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % user.Name, ["pykotaPrinterName", "pykotaUserName"], base=base) 1264 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % uname, \ 1265 ["pykotaPrinterName", "pykotaUserName"], \ 1266 base=base) 1210 1267 for (ident, fields) in result : 1211 1268 # ensure the user print quota entry will be deleted … … 1214 1271 # if last job of current printer was printed by the user 1215 1272 # to delete, we also need to delete the printer's last job entry. 1216 printername = fields["pykotaPrinterName"][0] 1217 printer = self.getPrinter(printername) 1273 printer = self.getPrinter(self.databaseToUserCharset(fields["pykotaPrinterName"][0])) 1218 1274 if printer.LastJob.UserName == user.Name : 1219 1275 todelete.append(printer.LastJob.lastjobident) … … 1241 1297 else : 1242 1298 self.doDelete(user.ident) 1243 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % user.Name, ["pykotaUserName"], base=self.info["balancebase"]) 1299 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % \ 1300 uname, \ 1301 ["pykotaUserName"], \ 1302 base=self.info["balancebase"]) 1244 1303 for (ident, fields) in result : 1245 1304 self.doDelete(ident) … … 1247 1306 def deleteGroup(self, group) : 1248 1307 """Completely deletes a group from the Quota Storage.""" 1308 gname = self.userCharsetToDatabase(group.Name) 1249 1309 if self.info["groupquotabase"].lower() == "group" : 1250 1310 base = self.info["groupbase"] 1251 1311 else : 1252 1312 base = self.info["groupquotabase"] 1253 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s))" % group.Name, ["pykotaGroupName"], base=base) 1313 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s))" % \ 1314 gname, \ 1315 ["pykotaGroupName"], \ 1316 base=base) 1254 1317 for (ident, fields) in result : 1255 1318 self.doDelete(ident) … … 1276 1339 def deletePrinter(self, printer) : 1277 1340 """Completely deletes a printer from the Quota Storage.""" 1278 result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % printer.Name, base=self.info["lastjobbase"]) 1341 pname = self.userCharsetToDatabase(printer.Name) 1342 result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % pname, base=self.info["lastjobbase"]) 1279 1343 for (ident, fields) in result : 1280 1344 self.doDelete(ident) 1281 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaPrinterName=%s))" % p rinter.Name, base=self.info["jobbase"])1345 result = self.doSearch("(&(objectClass=pykotaJob)(pykotaPrinterName=%s))" % pname, base=self.info["jobbase"]) 1282 1346 for (ident, fields) in result : 1283 1347 self.doDelete(ident) … … 1286 1350 else : 1287 1351 base = self.info["groupquotabase"] 1288 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % p rinter.Name, base=base)1352 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % pname, base=base) 1289 1353 for (ident, fields) in result : 1290 1354 self.doDelete(ident) … … 1293 1357 else : 1294 1358 base = self.info["userquotabase"] 1295 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % p rinter.Name, base=base)1359 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % pname, base=base) 1296 1360 for (ident, fields) in result : 1297 1361 self.doDelete(ident) … … 1443 1507 code = StorageBillingCode(self, label) 1444 1508 ulabel = self.userCharsetToDatabase(label) 1445 result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % ulabel, ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], base=self.info["billingcodebase"]) 1509 result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % \ 1510 ulabel, \ 1511 ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], \ 1512 base=self.info["billingcodebase"]) 1446 1513 if result : 1447 1514 fields = result[0][1] # take only first matching code, ignore the rest … … 1478 1545 """Returns the list of all billing codes which match a certain pattern.""" 1479 1546 codes = [] 1480 result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \ 1547 billingcodepattern = [self.userCharsetToDatabase(b) for b in billingcodepattern.split(",")] 1548 result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % \ 1549 "".join(["(pykotaBillingCode=%s)" % bcode for bcode in billingcodepattern]), \ 1481 1550 ["pykotaBillingCode", "description", "pykotaPageCounter", "pykotaBalance"], \ 1482 1551 base=self.info["billingcodebase"])