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

Revision 1249, 26.3 kB (checked in by jalet, 20 years ago)

Printer groups should be cached now, if caching is enabled.

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