root / pykota / trunk / pykota / storages / sql.py @ 1502

Revision 1502, 25.7 kB (checked in by jalet, 20 years ago)

First try at saving the job-originating-hostname in the database

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2# -*- coding: ISO-8859-15 -*-
3#
4# PyKota : Print Quotas for CUPS and LPRng
5#
6# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20#
21# $Id$
22#
23# $Log$
24# Revision 1.39  2004/05/26 14:50:12  jalet
25# First try at saving the job-originating-hostname in the database
26#
27# Revision 1.38  2004/05/06 12:37:47  jalet
28# pkpgcounter : comments
29# pkprinters : when --add is used, existing printers are now skipped.
30#
31# Revision 1.37  2004/02/23 22:53:21  jalet
32# Don't retrieve data when it's not needed, to avoid database queries
33#
34# Revision 1.36  2004/02/04 13:24:41  jalet
35# pkprinters can now remove printers from printers groups.
36#
37# Revision 1.35  2004/02/04 11:17:00  jalet
38# pkprinters command line tool added.
39#
40# Revision 1.34  2004/02/02 22:44:16  jalet
41# Preliminary work on Relationnal Database Independance via DB-API 2.0
42#
43#
44#
45
46from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
47
48class SQLStorage :
49    def getAllUsersNames(self) :   
50        """Extracts all user names."""
51        usernames = []
52        result = self.doSearch("SELECT username FROM users")
53        if result :
54            usernames = [record["username"] for record in result]
55        return usernames
56       
57    def getAllGroupsNames(self) :   
58        """Extracts all group names."""
59        groupnames = []
60        result = self.doSearch("SELECT groupname FROM groups")
61        if result :
62            groupnames = [record["groupname"] for record in result]
63        return groupnames
64       
65    def getUserFromBackend(self, username) :   
66        """Extracts user information given its name."""
67        user = StorageUser(self, username)
68        result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username))
69        if result :
70            fields = result[0]
71            user.ident = fields.get("id")
72            user.Name = fields.get("username", username)
73            user.LimitBy = fields.get("limitby")
74            user.AccountBalance = fields.get("balance")
75            user.LifeTimePaid = fields.get("lifetimepaid")
76            user.Email = fields.get("email")
77            user.Exists = 1
78        return user
79       
80    def getGroupFromBackend(self, groupname) :   
81        """Extracts group information given its name."""
82        group = StorageGroup(self, groupname)
83        result = self.doSearch("SELECT * FROM groups WHERE groupname=%s LIMIT 1" % self.doQuote(groupname))
84        if result :
85            fields = result[0]
86            group.ident = fields.get("id")
87            group.Name = fields.get("groupname", groupname)
88            group.LimitBy = fields.get("limitby")
89            result = self.doSearch("SELECT SUM(balance) AS balance, SUM(lifetimepaid) AS lifetimepaid FROM users WHERE id IN (SELECT userid FROM groupsmembers WHERE groupid=%s)" % self.doQuote(group.ident))
90            if result :
91                fields = result[0]
92                group.AccountBalance = fields.get("balance")
93                group.LifeTimePaid = fields.get("lifetimepaid")
94            group.Exists = 1
95        return group
96       
97    def getPrinterFromBackend(self, printername) :       
98        """Extracts printer information given its name."""
99        printer = StoragePrinter(self, printername)
100        result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername))
101        if result :
102            fields = result[0]
103            printer.ident = fields.get("id")
104            printer.Name = fields.get("printername", printername)
105            printer.PricePerJob = fields.get("priceperjob")
106            printer.PricePerPage = fields.get("priceperpage")
107            printer.Exists = 1
108        return printer   
109       
110    def getUserPQuotaFromBackend(self, user, printer) :       
111        """Extracts a user print quota."""
112        userpquota = StorageUserPQuota(self, user, printer)
113        if printer.Exists and user.Exists :
114            result = self.doSearch("SELECT id, lifepagecounter, pagecounter, softlimit, hardlimit, datelimit FROM userpquota WHERE userid=%s AND printerid=%s" % (self.doQuote(user.ident), self.doQuote(printer.ident)))
115            if result :
116                fields = result[0]
117                userpquota.ident = fields.get("id")
118                userpquota.PageCounter = fields.get("pagecounter")
119                userpquota.LifePageCounter = fields.get("lifepagecounter")
120                userpquota.SoftLimit = fields.get("softlimit")
121                userpquota.HardLimit = fields.get("hardlimit")
122                userpquota.DateLimit = fields.get("datelimit")
123                userpquota.Exists = 1
124        return userpquota
125       
126    def getGroupPQuotaFromBackend(self, group, printer) :       
127        """Extracts a group print quota."""
128        grouppquota = StorageGroupPQuota(self, group, printer)
129        if group.Exists :
130            result = self.doSearch("SELECT id, softlimit, hardlimit, datelimit FROM grouppquota WHERE groupid=%s AND printerid=%s" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
131            if result :
132                fields = result[0]
133                grouppquota.ident = fields.get("id")
134                grouppquota.SoftLimit = fields.get("softlimit")
135                grouppquota.HardLimit = fields.get("hardlimit")
136                grouppquota.DateLimit = fields.get("datelimit")
137                result = self.doSearch("SELECT SUM(lifepagecounter) AS lifepagecounter, SUM(pagecounter) AS pagecounter FROM userpquota WHERE printerid=%s AND userid IN (SELECT userid FROM groupsmembers WHERE groupid=%s)" % (self.doQuote(printer.ident), self.doQuote(group.ident)))
138                if result :
139                    fields = result[0]
140                    grouppquota.PageCounter = fields.get("pagecounter")
141                    grouppquota.LifePageCounter = fields.get("lifepagecounter")
142                grouppquota.Exists = 1
143        return grouppquota
144       
145    def getPrinterLastJobFromBackend(self, printer) :       
146        """Extracts a printer's last job information."""
147        lastjob = StorageLastJob(self, printer)
148        result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, hostname, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident))
149        if result :
150            fields = result[0]
151            lastjob.ident = fields.get("id")
152            lastjob.JobId = fields.get("jobid")
153            lastjob.UserName = fields.get("username")
154            lastjob.PrinterPageCounter = fields.get("pagecounter")
155            lastjob.JobSize = fields.get("jobsize")
156            lastjob.JobPrice = fields.get("jobprice")
157            lastjob.JobAction = fields.get("action")
158            lastjob.JobFileName = fields.get("filename")
159            lastjob.JobTitle = fields.get("title")
160            lastjob.JobCopies = fields.get("copies")
161            lastjob.JobOptions = fields.get("options")
162            lastjob.JobDate = fields.get("jobdate")
163            lastjob.JobHostName = fields.get("hostname")
164            lastjob.Exists = 1
165        return lastjob
166           
167    def getGroupMembersFromBackend(self, group) :       
168        """Returns the group's members list."""
169        groupmembers = []
170        result = self.doSearch("SELECT * FROM groupsmembers JOIN users ON groupsmembers.userid=users.id WHERE groupid=%s" % self.doQuote(group.ident))
171        if result :
172            for record in result :
173                user = StorageUser(self, record.get("username"))
174                user.ident = record.get("userid")
175                user.LimitBy = record.get("limitby")
176                user.AccountBalance = record.get("balance")
177                user.LifeTimePaid = record.get("lifetimepaid")
178                user.Email = record.get("email")
179                user.Exists = 1
180                groupmembers.append(user)
181                self.cacheEntry("USERS", user.Name, user)
182        return groupmembers       
183       
184    def getUserGroupsFromBackend(self, user) :       
185        """Returns the user's groups list."""
186        groups = []
187        result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident))
188        if result :
189            for record in result :
190                groups.append(self.getGroup(record.get("groupname")))
191        return groups       
192       
193    def getParentPrintersFromBackend(self, printer) :   
194        """Get all the printer groups this printer is a member of."""
195        pgroups = []
196        result = self.doSearch("SELECT groupid,printername FROM printergroupsmembers JOIN printers ON groupid=id WHERE printerid=%s" % self.doQuote(printer.ident))
197        if result :
198            for record in result :
199                if record["groupid"] != printer.ident : # in case of integrity violation
200                    parentprinter = self.getPrinter(record.get("printername"))
201                    if parentprinter.Exists :
202                        pgroups.append(parentprinter)
203        return pgroups
204       
205    def getMatchingPrinters(self, printerpattern) :
206        """Returns the list of all printers for which name matches a certain pattern."""
207        printers = []
208        # We 'could' do a SELECT printername FROM printers WHERE printername LIKE ...
209        # but we don't because other storages semantics may be different, so every
210        # storage should use fnmatch to match patterns and be storage agnostic
211        result = self.doSearch("SELECT * FROM printers")
212        if result :
213            for record in result :
214                if self.tool.matchString(record["printername"], printerpattern.split(",")) :
215                    printer = StoragePrinter(self, record["printername"])
216                    printer.ident = record.get("id")
217                    printer.PricePerJob = record.get("priceperjob")
218                    printer.PricePerPage = record.get("priceperpage")
219                    printer.Exists = 1
220                    printers.append(printer)
221                    self.cacheEntry("PRINTERS", printer.Name, printer)
222        return printers       
223       
224    def getPrinterUsersAndQuotas(self, printer, names=["*"]) :       
225        """Returns the list of users who uses a given printer, along with their quotas."""
226        usersandquotas = []
227        result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident))
228        if result :
229            for record in result :
230                if self.tool.matchString(record.get("username"), names) :
231                    user = StorageUser(self, record.get("username"))
232                    user.ident = record.get("uid")
233                    user.LimitBy = record.get("limitby")
234                    user.AccountBalance = record.get("balance")
235                    user.LifeTimePaid = record.get("lifetimepaid")
236                    user.Email = record.get("email") 
237                    user.Exists = 1
238                    userpquota = StorageUserPQuota(self, user, printer)
239                    userpquota.ident = record.get("id")
240                    userpquota.PageCounter = record.get("pagecounter")
241                    userpquota.LifePageCounter = record.get("lifepagecounter")
242                    userpquota.SoftLimit = record.get("softlimit")
243                    userpquota.HardLimit = record.get("hardlimit")
244                    userpquota.DateLimit = record.get("datelimit")
245                    userpquota.Exists = 1
246                    usersandquotas.append((user, userpquota))
247                    self.cacheEntry("USERS", user.Name, user)
248                    self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota)
249        return usersandquotas
250               
251    def getPrinterGroupsAndQuotas(self, printer, names=["*"]) :       
252        """Returns the list of groups which uses a given printer, along with their quotas."""
253        groupsandquotas = []
254        result = self.doSearch("SELECT groupname FROM groups JOIN grouppquota ON groups.id=grouppquota.groupid AND printerid=%s ORDER BY groupname ASC" % self.doQuote(printer.ident))
255        if result :
256            for record in result :
257                if self.tool.matchString(record.get("groupname"), names) :
258                    group = self.getGroup(record.get("groupname"))
259                    grouppquota = self.getGroupPQuota(group, printer)
260                    groupsandquotas.append((group, grouppquota))
261        return groupsandquotas
262       
263    def addPrinter(self, printername) :       
264        """Adds a printer to the quota storage, returns it."""
265        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(printername))
266        return self.getPrinter(printername)
267       
268    def addUser(self, user) :       
269        """Adds a user to the quota storage, returns its id."""
270        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy), self.doQuote(user.AccountBalance), self.doQuote(user.LifeTimePaid), self.doQuote(user.Email)))
271        return self.getUser(user.Name)
272       
273    def addGroup(self, group) :       
274        """Adds a group to the quota storage, returns its id."""
275        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy)))
276        return self.getGroup(group.Name)
277
278    def addUserToGroup(self, user, group) :   
279        """Adds an user to a group."""
280        result = self.doSearch("SELECT COUNT(*) AS mexists FROM groupsmembers WHERE groupid=%s AND userid=%s" % (self.doQuote(group.ident), self.doQuote(user.ident)))
281        try :
282            mexists = int(result[0].get("mexists"))
283        except (IndexError, TypeError) :   
284            mexists = 0
285        if not mexists :   
286            self.doModify("INSERT INTO groupsmembers (groupid, userid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(user.ident)))
287           
288    def addUserPQuota(self, user, printer) :
289        """Initializes a user print quota on a printer."""
290        self.doModify("INSERT INTO userpquota (userid, printerid) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident)))
291        return self.getUserPQuota(user, printer)
292       
293    def addGroupPQuota(self, group, printer) :
294        """Initializes a group print quota on a printer."""
295        self.doModify("INSERT INTO grouppquota (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
296        return self.getGroupPQuota(group, printer)
297       
298    def writePrinterPrices(self, printer) :   
299        """Write the printer's prices back into the storage."""
300        self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident)))
301       
302    def writeUserLimitBy(self, user, limitby) :   
303        """Sets the user's limiting factor."""
304        self.doModify("UPDATE users SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(user.ident)))
305       
306    def writeGroupLimitBy(self, group, limitby) :   
307        """Sets the group's limiting factor."""
308        self.doModify("UPDATE groups SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(group.ident)))
309       
310    def writeUserPQuotaDateLimit(self, userpquota, datelimit) :   
311        """Sets the date limit permanently for a user print quota."""
312        self.doModify("UPDATE userpquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(userpquota.ident)))
313           
314    def writeGroupPQuotaDateLimit(self, grouppquota, datelimit) :   
315        """Sets the date limit permanently for a group print quota."""
316        self.doModify("UPDATE grouppquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(grouppquota.ident)))
317       
318    def increaseUserPQuotaPagesCounters(self, userpquota, nbpages) :   
319        """Increase page counters for a user print quota."""
320        self.doModify("UPDATE userpquota SET pagecounter=pagecounter+%s,lifepagecounter=lifepagecounter+%s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident)))
321       
322    def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :   
323        """Sets the new page counters permanently for a user print quota."""
324        self.doModify("UPDATE userpquota SET pagecounter=%s,lifepagecounter=%s WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident)))
325       
326    def decreaseUserAccountBalance(self, user, amount) :   
327        """Decreases user's account balance from an amount."""
328        self.doModify("UPDATE users SET balance=balance-%s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident)))
329       
330    def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :   
331        """Sets the new account balance and eventually new lifetime paid."""
332        if newlifetimepaid is not None :
333            self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident)))
334        else :   
335            self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))
336           
337    def writeLastJobSize(self, lastjob, jobsize, jobprice) :       
338        """Sets the last job's size permanently."""
339        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident)))
340       
341    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None) :   
342        """Adds a job in a printer's history."""
343        if (not self.disablehistory) or (not printer.LastJob.Exists) :
344            if jobsize is not None :
345                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost)))
346            else :   
347                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options, hostname) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost)))
348        else :       
349            # here we explicitly want to reset jobsize to NULL if needed
350            self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(printer.LastJob.ident)))
351           
352    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) :
353        """Sets soft and hard limits for a user quota."""
354        self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident)))
355       
356    def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :
357        """Sets soft and hard limits for a group quota on a specific printer."""
358        self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(grouppquota.ident)))
359
360    def writePrinterToGroup(self, pgroup, printer) :
361        """Puts a printer into a printer group."""
362        children = []
363        result = self.doSearch("SELECT printerid FROM printergroupsmembers WHERE groupid=%s" % self.doQuote(pgroup.ident))
364        if result :
365            for record in result :
366                children.append(record.get("printerid")) # TODO : put this into the database integrity rules
367        if printer.ident not in children :       
368            self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
369       
370    def removePrinterFromGroup(self, pgroup, printer) :
371        """Removes a printer from a printer group."""
372        self.doModify("DELETE FROM printergroupsmembers WHERE groupid=%s AND printerid=%s" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
373       
374    def retrieveHistory(self, user=None, printer=None, datelimit=None, hostname=None, limit=100) :   
375        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
376        query = "SELECT jobhistory.*,username,printername FROM jobhistory,users,printers WHERE users.id=userid AND printers.id=printerid"
377        where = []
378        if (user is not None) and user.Exists :
379            where.append("userid=%s" % self.doQuote(user.ident))
380        if (printer is not None) and printer.Exists :
381            where.append("printerid=%s" % self.doQuote(printer.ident))
382        if hostname is not None :   
383            where.append("hostname=%s" % self.doQuote(hostname))
384        if datelimit is not None :   
385            where.append("jobdate<=%s" % self.doQuote(datelimit))
386        if where :   
387            query += " AND %s" % " AND ".join(where)
388        query += " ORDER BY id DESC"
389        if limit :
390            query += " LIMIT %s" % self.doQuote(int(limit))
391        jobs = []   
392        result = self.doSearch(query)   
393        if result :
394            for fields in result :
395                job = StorageJob(self)
396                job.ident = fields.get("id")
397                job.JobId = fields.get("jobid")
398                job.PrinterPageCounter = fields.get("pagecounter")
399                job.JobSize = fields.get("jobsize")
400                job.JobPrice = fields.get("jobprice")
401                job.JobAction = fields.get("action")
402                job.JobFileName = fields.get("filename")
403                job.JobTitle = fields.get("title")
404                job.JobCopies = fields.get("copies")
405                job.JobOptions = fields.get("options")
406                job.JobDate = fields.get("jobdate")
407                job.JobHostName = fields.get("hostname")
408                job.UserName = fields.get("username")
409                job.PrinterName = fields.get("printername")
410                job.Exists = 1
411                jobs.append(job)
412        return jobs
413       
414    def deleteUser(self, user) :   
415        """Completely deletes an user from the Quota Storage."""
416        # TODO : What should we do if we delete the last person who used a given printer ?
417        # TODO : we can't reassign the last job to the previous one, because next user would be
418        # TODO : incorrectly charged (overcharged).
419        for q in [ 
420                    "DELETE FROM groupsmembers WHERE userid=%s" % self.doQuote(user.ident),
421                    "DELETE FROM jobhistory WHERE userid=%s" % self.doQuote(user.ident),
422                    "DELETE FROM userpquota WHERE userid=%s" % self.doQuote(user.ident),
423                    "DELETE FROM users WHERE id=%s" % self.doQuote(user.ident),
424                  ] :
425            self.doModify(q)
426       
427    def deleteGroup(self, group) :   
428        """Completely deletes a group from the Quota Storage."""
429        for q in [
430                   "DELETE FROM groupsmembers WHERE groupid=%s" % self.doQuote(group.ident),
431                   "DELETE FROM grouppquota WHERE groupid=%s" % self.doQuote(group.ident),
432                   "DELETE FROM groups WHERE id=%s" % self.doQuote(group.ident),
433                 ] : 
434            self.doModify(q)
435           
436    def deletePrinter(self, printer) :   
437        """Completely deletes a printer from the Quota Storage."""
438        for q in [ 
439                    "DELETE FROM printergroupsmembers WHERE groupid=%s OR printerid=%s" % (self.doQuote(printer.ident), self.doQuote(printer.ident)),
440                    "DELETE FROM jobhistory WHERE printerid=%s" % self.doQuote(printer.ident),
441                    "DELETE FROM grouppquota WHERE printerid=%s" % self.doQuote(printer.ident),
442                    "DELETE FROM userpquota WHERE printerid=%s" % self.doQuote(printer.ident),
443                    "DELETE FROM printers WHERE id=%s" % self.doQuote(printer.ident),
444                  ] :
445            self.doModify(q)
446       
Note: See TracBrowser for help on using the browser.