root / pykota / trunk / pykota / storages / pgstorage.py @ 1228

Revision 1228, 25.4 kB (checked in by jalet, 20 years ago)

Don't try to retrieve the user print quota information if current printer
doesn't exist.

  • 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 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.24  2003/11/29 22:02:14  jalet
25# Don't try to retrieve the user print quota information if current printer
26# doesn't exist.
27#
28# Revision 1.23  2003/11/23 19:01:37  jalet
29# Job price added to history
30#
31# Revision 1.22  2003/11/21 14:28:46  jalet
32# More complete job history.
33#
34# Revision 1.21  2003/11/12 13:06:38  jalet
35# Bug fix wrt no user/group name command line argument to edpykota
36#
37# Revision 1.20  2003/10/09 21:25:26  jalet
38# Multiple printer names or wildcards can be passed on the command line
39# separated with commas.
40# Beta phase.
41#
42# Revision 1.19  2003/10/08 07:01:20  jalet
43# Job history can be disabled.
44# Some typos in README.
45# More messages in setup script.
46#
47# Revision 1.18  2003/10/07 09:07:30  jalet
48# Character encoding added to please latest version of Python
49#
50# Revision 1.17  2003/10/06 13:12:28  jalet
51# More work on caching
52#
53# Revision 1.16  2003/10/03 18:01:49  jalet
54# Nothing interesting...
55#
56# Revision 1.15  2003/10/03 12:27:03  jalet
57# Several optimizations, especially with LDAP backend
58#
59# Revision 1.14  2003/10/03 08:57:55  jalet
60# Caching mechanism now caches all that's cacheable.
61#
62# Revision 1.13  2003/10/02 20:23:18  jalet
63# Storage caching mechanism added.
64#
65# Revision 1.12  2003/08/17 14:20:25  jalet
66# Bug fix by Oleg Biteryakov
67#
68# Revision 1.11  2003/07/29 20:55:17  jalet
69# 1.14 is out !
70#
71# Revision 1.10  2003/07/16 21:53:08  jalet
72# Really big modifications wrt new configuration file's location and content.
73#
74# Revision 1.9  2003/07/14 17:20:15  jalet
75# Bug in postgresql storage when modifying the prices for a printer
76#
77# Revision 1.8  2003/07/14 14:18:17  jalet
78# Wrong documentation strings
79#
80# Revision 1.7  2003/07/09 20:17:07  jalet
81# Email field added to PostgreSQL schema
82#
83# Revision 1.6  2003/07/07 11:49:24  jalet
84# Lots of small fixes with the help of PyChecker
85#
86# Revision 1.5  2003/07/07 08:33:19  jalet
87# Bug fix due to a typo in LDAP code
88#
89# Revision 1.4  2003/06/30 13:54:21  jalet
90# Sorts by user / group name
91#
92# Revision 1.3  2003/06/25 14:10:01  jalet
93# Hey, it may work (edpykota --reset excepted) !
94#
95# Revision 1.2  2003/06/12 21:09:57  jalet
96# wrongly placed code.
97#
98# Revision 1.1  2003/06/10 16:37:54  jalet
99# Deletion of the second user which is not needed anymore.
100# Added a debug configuration field in /etc/pykota.conf
101# All queries can now be sent to the logger in debug mode, this will
102# greatly help improve performance when time for this will come.
103#
104#
105#
106#
107
108from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
109
110try :
111    import pg
112except ImportError :   
113    import sys
114    # TODO : to translate or not to translate ?
115    raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PygreSQL module installed correctly." % sys.version.split()[0]
116
117class Storage(BaseStorage) :
118    def __init__(self, pykotatool, host, dbname, user, passwd) :
119        """Opens the PostgreSQL database connection."""
120        BaseStorage.__init__(self, pykotatool)
121        try :
122            (host, port) = host.split(":")
123            port = int(port)
124        except ValueError :   
125            port = -1         # Use PostgreSQL's default tcp/ip port (5432).
126       
127        try :
128            self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
129        except pg.error, msg :
130            raise PyKotaStorageError, msg
131        else :   
132            self.closed = 0
133            self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
134           
135    def close(self) :   
136        """Closes the database connection."""
137        if not self.closed :
138            self.database.close()
139            self.closed = 1
140            self.tool.logdebug("Database closed.")
141       
142    def beginTransaction(self) :   
143        """Starts a transaction."""
144        self.database.query("BEGIN;")
145        self.tool.logdebug("Transaction begins...")
146       
147    def commitTransaction(self) :   
148        """Commits a transaction."""
149        self.database.query("COMMIT;")
150        self.tool.logdebug("Transaction committed.")
151       
152    def rollbackTransaction(self) :     
153        """Rollbacks a transaction."""
154        self.database.query("ROLLBACK;")
155        self.tool.logdebug("Transaction aborted.")
156       
157    def doSearch(self, query) :
158        """Does a search query."""
159        query = query.strip()   
160        if not query.endswith(';') :   
161            query += ';'
162        try :
163            self.tool.logdebug("QUERY : %s" % query)
164            result = self.database.query(query)
165        except pg.error, msg :   
166            raise PyKotaStorageError, msg
167        else :   
168            if (result is not None) and (result.ntuples() > 0) : 
169                return result.dictresult()
170           
171    def doModify(self, query) :
172        """Does a (possibly multiple) modify query."""
173        query = query.strip()   
174        if not query.endswith(';') :   
175            query += ';'
176        try :
177            self.tool.logdebug("QUERY : %s" % query)
178            result = self.database.query(query)
179        except pg.error, msg :   
180            raise PyKotaStorageError, msg
181        else :   
182            return result
183           
184    def doQuote(self, field) :
185        """Quotes a field for use as a string in SQL queries."""
186        if type(field) == type(0.0) : 
187            typ = "decimal"
188        elif type(field) == type(0) :   
189            typ = "int"
190        else :   
191            typ = "text"
192        return pg._quote(field, typ)
193       
194    def getAllUsersNames(self) :   
195        """Extracts all user names."""
196        usernames = []
197        result = self.doSearch("SELECT username FROM users;")
198        if result :
199            usernames = [record["username"] for record in result]
200        return usernames
201       
202    def getAllGroupsNames(self) :   
203        """Extracts all group names."""
204        groupnames = []
205        result = self.doSearch("SELECT groupname FROM groups;")
206        if result :
207            groupnames = [record["groupname"] for record in result]
208        return groupnames
209       
210    def getUserFromBackend(self, username) :   
211        """Extracts user information given its name."""
212        user = StorageUser(self, username)
213        result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username))
214        if result :
215            fields = result[0]
216            user.ident = fields.get("id")
217            user.LimitBy = fields.get("limitby")
218            user.AccountBalance = fields.get("balance")
219            user.LifeTimePaid = fields.get("lifetimepaid")
220            user.Email = fields.get("email")
221            user.Exists = 1
222        return user
223       
224    def getGroupFromBackend(self, groupname) :   
225        """Extracts group information given its name."""
226        group = StorageGroup(self, groupname)
227        result = self.doSearch("SELECT * FROM groups WHERE groupname=%s LIMIT 1" % self.doQuote(groupname))
228        if result :
229            fields = result[0]
230            group.ident = fields.get("id")
231            group.LimitBy = fields.get("limitby")
232            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))
233            if result :
234                fields = result[0]
235                group.AccountBalance = fields.get("balance")
236                group.LifeTimePaid = fields.get("lifetimepaid")
237            group.Exists = 1
238        return group
239       
240    def getPrinterFromBackend(self, printername) :       
241        """Extracts printer information given its name."""
242        printer = StoragePrinter(self, printername)
243        result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername))
244        if result :
245            fields = result[0]
246            printer.ident = fields.get("id")
247            printer.PricePerJob = fields.get("priceperjob")
248            printer.PricePerPage = fields.get("priceperpage")
249            printer.LastJob = self.getPrinterLastJob(printer)
250            printer.Exists = 1
251        return printer   
252       
253    def getUserPQuotaFromBackend(self, user, printer) :       
254        """Extracts a user print quota."""
255        userpquota = StorageUserPQuota(self, user, printer)
256        if printer.Exists and user.Exists :
257            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)))
258            if result :
259                fields = result[0]
260                userpquota.ident = fields.get("id")
261                userpquota.PageCounter = fields.get("pagecounter")
262                userpquota.LifePageCounter = fields.get("lifepagecounter")
263                userpquota.SoftLimit = fields.get("softlimit")
264                userpquota.HardLimit = fields.get("hardlimit")
265                userpquota.DateLimit = fields.get("datelimit")
266                userpquota.Exists = 1
267        return userpquota
268       
269    def getGroupPQuotaFromBackend(self, group, printer) :       
270        """Extracts a group print quota."""
271        grouppquota = StorageGroupPQuota(self, group, printer)
272        if group.Exists :
273            result = self.doSearch("SELECT id, softlimit, hardlimit, datelimit FROM grouppquota WHERE groupid=%s AND printerid=%s" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
274            if result :
275                fields = result[0]
276                grouppquota.ident = fields.get("id")
277                grouppquota.SoftLimit = fields.get("softlimit")
278                grouppquota.HardLimit = fields.get("hardlimit")
279                grouppquota.DateLimit = fields.get("datelimit")
280                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)))
281                if result :
282                    fields = result[0]
283                    grouppquota.PageCounter = fields.get("pagecounter")
284                    grouppquota.LifePageCounter = fields.get("lifepagecounter")
285                grouppquota.Exists = 1
286        return grouppquota
287       
288    def getPrinterLastJobFromBackend(self, printer) :       
289        """Extracts a printer's last job information."""
290        lastjob = StorageLastJob(self, printer)
291        result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobprice, filename, title, copies, options, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident))
292        if result :
293            fields = result[0]
294            lastjob.ident = fields.get("id")
295            lastjob.JobId = fields.get("jobid")
296            lastjob.User = self.getUser(fields.get("username"))
297            lastjob.PrinterPageCounter = fields.get("pagecounter")
298            lastjob.JobSize = fields.get("jobsize")
299            lastjob.JobPrice = fields.get("jobprice")
300            lastjob.JobAction = fields.get("action")
301            lastjob.JobFileName = fields.get("filename")
302            lastjob.JobTitle = fields.get("title")
303            lastjob.JobCopies = fields.get("copies")
304            lastjob.JobOptions = fields.get("options")
305            lastjob.JobDate = fields.get("jobdate")
306            lastjob.Exists = 1
307        return lastjob
308           
309    def getGroupMembersFromBackend(self, group) :       
310        """Returns the group's members list."""
311        groupmembers = []
312        result = self.doSearch("SELECT * FROM groupsmembers JOIN users ON groupsmembers.userid=users.id WHERE groupid=%s" % self.doQuote(group.ident))
313        if result :
314            for record in result :
315                user = StorageUser(self, record.get("username"))
316                user.ident = record.get("userid")
317                user.LimitBy = record.get("limitby")
318                user.AccountBalance = record.get("balance")
319                user.LifeTimePaid = record.get("lifetimepaid")
320                user.Email = record.get("email")
321                user.Exists = 1
322                groupmembers.append(user)
323                self.cacheEntry("USERS", user.Name, user)
324        return groupmembers       
325       
326    def getUserGroupsFromBackend(self, user) :       
327        """Returns the user's groups list."""
328        groups = []
329        result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident))
330        if result :
331            for record in result :
332                groups.append(self.getGroup(record.get("groupname")))
333        return groups       
334       
335    def getMatchingPrinters(self, printerpattern) :
336        """Returns the list of all printers for which name matches a certain pattern."""
337        printers = []
338        # We 'could' do a SELECT printername FROM printers WHERE printername LIKE ...
339        # but we don't because other storages semantics may be different, so every
340        # storage should use fnmatch to match patterns and be storage agnostic
341        result = self.doSearch("SELECT * FROM printers")
342        if result :
343            for record in result :
344                if self.tool.matchString(record["printername"], printerpattern.split(",")) :
345                    printer = StoragePrinter(self, record["printername"])
346                    printer.ident = record.get("id")
347                    printer.PricePerJob = record.get("priceperjob")
348                    printer.PricePerPage = record.get("priceperpage")
349                    printer.LastJob = self.getPrinterLastJob(printer)
350                    printer.Exists = 1
351                    printers.append(printer)
352                    self.cacheEntry("PRINTERS", printer.Name, printer)
353        return printers       
354       
355    def getPrinterUsersAndQuotas(self, printer, names=["*"]) :       
356        """Returns the list of users who uses a given printer, along with their quotas."""
357        usersandquotas = []
358        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))
359        if result :
360            for record in result :
361                if self.tool.matchString(record.get("username"), names) :
362                    user = StorageUser(self, record.get("username"))
363                    user.ident = record.get("uid")
364                    user.LimitBy = record.get("limitby")
365                    user.AccountBalance = record.get("balance")
366                    user.LifeTimePaid = record.get("lifetimepaid")
367                    user.Email = record.get("email") 
368                    user.Exists = 1
369                    userpquota = StorageUserPQuota(self, user, printer)
370                    userpquota.ident = record.get("id")
371                    userpquota.PageCounter = record.get("pagecounter")
372                    userpquota.LifePageCounter = record.get("lifepagecounter")
373                    userpquota.SoftLimit = record.get("softlimit")
374                    userpquota.HardLimit = record.get("hardlimit")
375                    userpquota.DateLimit = record.get("datelimit")
376                    userpquota.Exists = 1
377                    usersandquotas.append((user, userpquota))
378                    self.cacheEntry("USERS", user.Name, user)
379                    self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota)
380        return usersandquotas
381               
382    def getPrinterGroupsAndQuotas(self, printer, names=["*"]) :       
383        """Returns the list of groups which uses a given printer, along with their quotas."""
384        groupsandquotas = []
385        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))
386        if result :
387            for record in result :
388                if self.tool.matchString(record.get("groupname"), names) :
389                    group = self.getGroup(record.get("groupname"))
390                    grouppquota = self.getGroupPQuota(group, printer)
391                    groupsandquotas.append((group, grouppquota))
392        return groupsandquotas
393       
394    def addPrinter(self, printername) :       
395        """Adds a printer to the quota storage, returns it."""
396        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(printername))
397        return self.getPrinter(printername)
398       
399    def addUser(self, user) :       
400        """Adds a user to the quota storage, returns its id."""
401        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)))
402        return self.getUser(user.Name)
403       
404    def addGroup(self, group) :       
405        """Adds a group to the quota storage, returns its id."""
406        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy)))
407        return self.getGroup(group.Name)
408
409    def addUserToGroup(self, user, group) :   
410        """Adds an user to a group."""
411        result = self.doSearch("SELECT COUNT(*) AS mexists FROM groupsmembers WHERE groupid=%s AND userid=%s" % (self.doQuote(group.ident), self.doQuote(user.ident)))
412        try :
413            mexists = int(result[0].get("mexists"))
414        except (IndexError, TypeError) :   
415            mexists = 0
416        if not mexists :   
417            self.doModify("INSERT INTO groupsmembers (groupid, userid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(user.ident)))
418           
419    def addUserPQuota(self, user, printer) :
420        """Initializes a user print quota on a printer."""
421        self.doModify("INSERT INTO userpquota (userid, printerid) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident)))
422        return self.getUserPQuota(user, printer)
423       
424    def addGroupPQuota(self, group, printer) :
425        """Initializes a group print quota on a printer."""
426        self.doModify("INSERT INTO grouppquota (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
427        return self.getGroupPQuota(group, printer)
428       
429    def writePrinterPrices(self, printer) :   
430        """Write the printer's prices back into the storage."""
431        self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident)))
432       
433    def writeUserLimitBy(self, user, limitby) :   
434        """Sets the user's limiting factor."""
435        self.doModify("UPDATE users SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(user.ident)))
436       
437    def writeGroupLimitBy(self, group, limitby) :   
438        """Sets the group's limiting factor."""
439        self.doModify("UPDATE groups SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(group.ident)))
440       
441    def writeUserPQuotaDateLimit(self, userpquota, datelimit) :   
442        """Sets the date limit permanently for a user print quota."""
443        self.doModify("UPDATE userpquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(userpquota.ident)))
444           
445    def writeGroupPQuotaDateLimit(self, grouppquota, datelimit) :   
446        """Sets the date limit permanently for a group print quota."""
447        self.doModify("UPDATE grouppquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(grouppquota.ident)))
448       
449    def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :   
450       """Sets the new page counters permanently for a user print quota."""
451       self.doModify("UPDATE userpquota SET pagecounter=%s,lifepagecounter=%s WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident)))
452       
453    def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :   
454       """Sets the new account balance and eventually new lifetime paid."""
455       if newlifetimepaid is not None :
456           self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident)))
457       else :   
458           self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))
459           
460    def writeLastJobSize(self, lastjob, jobsize, jobprice) :       
461        """Sets the last job's size permanently."""
462        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident)))
463       
464    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) :   
465        """Adds a job in a printer's history."""
466        if (not self.disablehistory) or (not printer.LastJob.Exists) :
467            if jobsize is not None :
468                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize, jobprice, filename, title, copies, options) VALUES (%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)))
469            else :   
470                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, filename, title, copies, options) VALUES (%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)))
471        else :       
472            # here we explicitly want to reset jobsize to NULL if needed
473            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, 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(printer.LastJob.ident)))
474           
475    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) :
476        """Sets soft and hard limits for a user quota."""
477        self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident)))
478       
479    def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :
480        """Sets soft and hard limits for a group quota on a specific printer."""
481        self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(grouppquota.ident)))
482
483    def deleteUser(self, user) :   
484        """Completely deletes an user from the Quota Storage."""
485        # TODO : What should we do if we delete the last person who used a given printer ?
486        # TODO : we can't reassign the last job to the previous one, because next user would be
487        # TODO : incorrectly charged (overcharged).
488        for q in [ 
489                    "DELETE FROM groupsmembers WHERE userid=%s" % self.doQuote(user.ident),
490                    "DELETE FROM jobhistory WHERE userid=%s" % self.doQuote(user.ident),
491                    "DELETE FROM userpquota WHERE userid=%s" % self.doQuote(user.ident),
492                    "DELETE FROM users WHERE id=%s" % self.doQuote(user.ident),
493                  ] :
494            self.doModify(q)
495       
496    def deleteGroup(self, group) :   
497        """Completely deletes a group from the Quota Storage."""
498        for q in [
499                   "DELETE FROM groupsmembers WHERE groupid=%s" % self.doQuote(group.ident),
500                   "DELETE FROM grouppquota WHERE groupid=%s" % self.doQuote(group.ident),
501                   "DELETE FROM groups WHERE id=%s" % self.doQuote(group.ident),
502                 ] : 
503            self.doModify(q)
504       
Note: See TracBrowser for help on using the browser.