Changeset 719 for pykota/trunk/pykota/storages/sql.py
- Timestamp:
- 02/06/03 15:28:59 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r713 r719 15 15 # 16 16 # $Log$ 17 # Revision 1.7 2003/02/06 14:28:59 jalet 18 # edpykota should be ok, minus some typos 19 # 17 20 # Revision 1.6 2003/02/06 09:19:02 jalet 18 21 # More robust behavior (hopefully) when the user or printer is not managed … … 40 43 41 44 class SQLStorage : 45 def getMatchingPrinters(self, printerpattern) : 46 """Returns the list of all printer names which match a certain pattern.""" 47 printerslist = [] 48 # We 'could' do a SELECT printername FROM printers WHERE printername LIKE ... 49 # but we don't because other storages semantics may be different, so every 50 # storage should use fnmatch to match patterns and be storage agnostic 51 result = self.doQuery("SELECT printername FROM printers;") 52 result = self.doParseResult() 53 if result is not None : 54 for printer in result : 55 if fnmatch.fnmatchcase(printer["printername"], printerpattern) : 56 printerslist.append(printer["printername"]) 57 return printerslist 58 42 59 def getUserId(self, username) : 60 """Returns a userid given a username.""" 43 61 result = self.doQuery("SELECT id FROM users WHERE username=%s;" % self.doQuote(username)) 44 62 try : … … 48 66 49 67 def getPrinterId(self, printername) : 68 """Returns a printerid given a printername.""" 50 69 result = self.doQuery("SELECT id FROM printers WHERE printername=%s;" % self.doQuote(printername)) 51 70 try : … … 55 74 56 75 def getPrinterPageCounter(self, printername) : 76 """Returns the last page counter value for a printer given its name.""" 57 77 result = self.doQuery("SELECT pagecounter, lastusername FROM printers WHERE printername=%s;" % self.doQuote(printername)) 58 78 try : … … 62 82 63 83 def updatePrinterPageCounter(self, printername, username, pagecount) : 84 """Updates the last page counter information for a printer given its name, last username and pagecount.""" 64 85 return self.doQuery("UPDATE printers SET pagecounter=%s, lastusername=%s WHERE printername=%s;" % (self.doQuote(pagecount), self.doQuote(username), self.doQuote(printername))) 65 86 … … 75 96 76 97 def getUPIds(self, username, printername) : 98 """Returns a tuple (userid, printerid) given a username and a printername.""" 77 99 return (self.getUserId(username), self.getPrinterId(printername)) 78 100 79 101 def getUserPQuota(self, username, printername) : 102 """Returns the Print Quota information for a given (username, printername).""" 80 103 (userid, printerid) = self.getUPIds(username, printername) 81 104 if (userid is not None) and (printerid is not None) : … … 87 110 88 111 def setUserPQuota(self, username, printername, softlimit, hardlimit) : 112 """Sets soft and hard limits for a user quota on a specific printer given (username, printername).""" 89 113 (userid, printerid) = self.getUPIds(username, printername) 90 114 if (userid is not None) and (printerid is not None) : … … 92 116 93 117 def updateUserPQuota(self, username, printername, pagecount) : 118 """Updates the used user Quota information given (username, printername) and a job size in pages.""" 94 119 (userid, printerid) = self.getUPIds(username, printername) 95 120 if (userid is not None) and (printerid is not None) : … … 97 122 98 123 def buyUserPQuota(self, username, printername, pagebought) : 124 """Buys pages for a given (username, printername).""" 99 125 self.updateUserPQuota(username, printername, -pagebought) 100 126