449 | | def hasWildCards(self, pattern) : |
450 | | """Returns True if the pattern contains wildcards, else False.""" |
451 | | specialchars = "*?[!" # no need to check for ] since [ would be there first |
452 | | for specialchar in specialchars : |
453 | | if specialchar in pattern : |
454 | | return True |
455 | | return False |
456 | | |
457 | | def getMatchingPrinters(self, printerpattern) : |
458 | | """Returns the list of all printers for which name matches a certain pattern.""" |
459 | | printers = [] |
460 | | # We 'could' do a SELECT printername FROM printers WHERE printername LIKE ... |
461 | | # but we don't because other storages semantics may be different, so every |
462 | | # storage should use fnmatch to match patterns and be storage agnostic |
463 | | result = self.doSearch("SELECT * FROM printers") |
464 | | if result : |
465 | | patterns = printerpattern.split(",") |
466 | | patdict = {}.fromkeys(patterns) |
467 | | for record in result : |
468 | | pname = self.databaseToUserCharset(record["printername"]) |
469 | | if patdict.has_key(pname) or self.tool.matchString(pname, patterns) : |
470 | | printer = self.storagePrinterFromRecord(pname, record) |
471 | | printers.append(printer) |
472 | | self.cacheEntry("PRINTERS", printer.Name, printer) |
473 | | return printers |
474 | | |
475 | | def getMatchingUsers(self, userpattern) : |
476 | | """Returns the list of all users for which name matches a certain pattern.""" |
477 | | users = [] |
478 | | # We 'could' do a SELECT username FROM users WHERE username LIKE ... |
| 449 | def getMatchingStuff(self, pattern, tablename, entrytype, keyname) : |
| 450 | """Returns the list of all entries for which the name matches a certain pattern.""" |
| 451 | entries = [] |
| 452 | # We 'could' do a SELECT xxxxname FROM xxxx WHERE xxxxname LIKE ... |
493 | | uname = self.databaseToUserCharset(record["username"]) |
494 | | if patdict.has_key(uname) or self.tool.matchString(uname, patterns) : |
495 | | user = self.storageUserFromRecord(uname, record) |
496 | | users.append(user) |
497 | | self.cacheEntry("USERS", user.Name, user) |
498 | | else : |
499 | | # Fast route (probably not faster with a few users) |
| 469 | name = self.databaseToUserCharset(record[keyname]) |
| 470 | if patdict.has_key(name) or self.tool.matchString(name, patterns) : |
| 471 | entry = storageEntryFromRecord(name, record) |
| 472 | entries.append(entry) |
| 473 | self.cacheEntry(cachename, entry.Name, entry) |
| 474 | else : |
| 475 | # Fast route (probably not faster with a few entries) |
510 | | uname = self.databaseToUserCharset(record["username"]) |
511 | | user = self.storageUserFromRecord(uname, record) |
512 | | users.append(user) |
513 | | self.cacheEntry("USERS", user.Name, user) |
| 488 | name = self.databaseToUserCharset(record[keyname]) |
| 489 | entry = storageEntryFromRecord(name, record) |
| 490 | entries.append(entry) |
| 491 | self.cacheEntry(cachename, entry.Name, entry) |
515 | | users.sort(key=lambda u : u.Name) # Adds some ordering, we've already lost the cmd line one anyway. |
516 | | return users |
| 493 | entries.sort(key=lambda e : e.Name) # Adds some ordering, we've already lost the cmd line one anyway. |
| 494 | return entries |
| 495 | |
| 496 | def getMatchingPrinters(self, pattern) : |
| 497 | """Returns the list of all printers for which name matches a certain pattern.""" |
| 498 | return self.getMatchingStuff(pattern, "printers", "Printer", "printername") |
| 499 | |
| 500 | def getMatchingUsers(self, pattern) : |
| 501 | """Returns the list of all users for which name matches a certain pattern.""" |
| 502 | return self.getMatchingStuff(pattern, "users", "User", "username") |
| 503 | |
| 504 | def getMatchingBillingCodes(self, pattern) : |
| 505 | """Returns the list of all billing codes for which the label matches a certain pattern.""" |
| 506 | return self.getMatchingStuff(pattern, "billingcodes", "BillingCode", "billingcode") |
535 | | |
536 | | def getMatchingBillingCodes(self, billingcodepattern) : |
537 | | """Returns the list of all billing codes for which the label matches a certain pattern.""" |
538 | | codes = [] |
539 | | result = self.doSearch("SELECT * FROM billingcodes") |
540 | | if result : |
541 | | patterns = billingcodepattern.split(",") |
542 | | patdict = {}.fromkeys(patterns) |
543 | | for record in result : |
544 | | codename = self.databaseToUserCharset(record["billingcode"]) |
545 | | if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : |
546 | | code = self.storageBillingCodeFromRecord(codename, record) |
547 | | codes.append(code) |
548 | | self.cacheEntry("BILLINGCODES", code.BillingCode, code) |
549 | | return codes |