Index: pykota/trunk/pykota/accounters/stupid.py
===================================================================
--- pykota/trunk/pykota/accounters/stupid.py (revision 1000)
+++ pykota/trunk/pykota/accounters/stupid.py (revision 1041)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.4  2003/06/25 14:10:01  jalet
+# Hey, it may work (edpykota --reset excepted) !
+#
 # Revision 1.3  2003/05/27 23:00:21  jalet
 # Big rewrite of external accounting methods.
@@ -39,5 +42,5 @@
 
 class Accounter(AccounterBase) :
-    def doAccounting(self, printerid, userid) :
+    def doAccounting(self, printer, user) :
         """Does print accounting by stupidly counting the 'showpage' postscript instructions in the document.
         
@@ -51,6 +54,5 @@
             
         # get last job information for this printer
-        pgc = self.filter.storage.getPrinterPageCounter(printerid)    
-        if pgc is None :
+        if not printer.LastJob.Exists :
             # The printer hasn't been used yet, from PyKota's point of view
             counterbeforejob = 0
@@ -59,8 +61,9 @@
             # Last lifetime page counter before actual job is 
             # last page counter + last job size
-            counterbeforejob = (pgc["pagecounter"] or 0) + (pgc["jobsize"] or 0)
+            counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)
             
         # Is the current user allowed to print at all ?
-        action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername)
+        userpquota = self.filter.storage.getUserPQuota(user, printer)
+        action = self.filter.warnUserPQuota(userpquota)
         
         # update the quota for the current user on this printer, if allowed to print
@@ -68,8 +71,8 @@
             jobsize = 0
         else :    
-            self.filter.storage.updateUserPQuota(userid, printerid, jobsize)
+            userpquota.increasePagesUsage(jobsize)
         
         # adds the current job to history    
-        self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action, jobsize)
+        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize)
             
         return action
Index: pykota/trunk/pykota/accounters/external.py
===================================================================
--- pykota/trunk/pykota/accounters/external.py (revision 1000)
+++ pykota/trunk/pykota/accounters/external.py (revision 1041)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.4  2003/06/25 14:10:01  jalet
+# Hey, it may work (edpykota --reset excepted) !
+#
 # Revision 1.3  2003/05/27 23:00:21  jalet
 # Big rewrite of external accounting methods.
@@ -41,5 +44,5 @@
 
 class Accounter(AccounterBase) :
-    def doAccounting(self, printerid, userid) :
+    def doAccounting(self, printer, user) :
         """Deletgates the computation of the job size to an external command.
         
@@ -50,6 +53,5 @@
             
         # get last job information for this printer
-        pgc = self.filter.storage.getPrinterPageCounter(printerid)    
-        if pgc is None :
+        if not printer.LastJob.Exists :
             # The printer hasn't been used yet, from PyKota's point of view
             counterbeforejob = 0
@@ -58,8 +60,9 @@
             # Last lifetime page counter before actual job is 
             # last page counter + last job size
-            counterbeforejob = (pgc["pagecounter"] or 0) + (pgc["jobsize"] or 0)
+            counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)
             
         # Is the current user allowed to print at all ?
-        action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername)
+        userpquota = self.filter.storage.getUserPQuota(user, printer)
+        action = self.filter.warnUserPQuota(userpquota)
         
         # update the quota for the current user on this printer, if allowed to print
@@ -67,8 +70,8 @@
             jobsize = 0
         else :    
-            self.filter.storage.updateUserPQuota(userid, printerid, jobsize)
+            userpquota.increasePagesUsage(jobsize)
         
         # adds the current job to history    
-        self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action, jobsize)
+        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize)
             
         return action
@@ -102,7 +105,4 @@
             # launches child process
             command = "%s <%s >%s 2>%s" % (self.arguments, infilename, outfilename, errfilename)
-            o = open("/tmp/comm", "w")
-            o.write("%s\n" % command)
-            o.close()
             retcode = os.system(command)
             
Index: pykota/trunk/pykota/accounters/querying.py
===================================================================
--- pykota/trunk/pykota/accounters/querying.py (revision 988)
+++ pykota/trunk/pykota/accounters/querying.py (revision 1041)
@@ -21,4 +21,7 @@
 #
 # $Log$
+# Revision 1.4  2003/06/25 14:10:01  jalet
+# Hey, it may work (edpykota --reset excepted) !
+#
 # Revision 1.3  2003/05/06 14:55:47  jalet
 # Missing import !
@@ -38,9 +41,9 @@
 from pykota.requester import openRequester, PyKotaRequesterError
 
-MAXTRIES = 6     # maximum number of tries to get the printer's internal page counter
+MAXTRIES = 12    # maximum number of tries to get the printer's internal page counter
 TIMETOSLEEP = 10 # number of seconds to sleep between two tries to get the printer's internal page counter
 
 class Accounter(AccounterBase) :
-    def doAccounting(self, printerid, userid) :
+    def doAccounting(self, printer, user) :
         """Does print accounting and returns if the job status is ALLOW or DENY."""
         # Get the page counter directly from the printer itself
@@ -65,15 +68,14 @@
         
         # get last job information for this printer
-        pgc = self.filter.storage.getPrinterPageCounter(printerid)    
-        if pgc is None :
+        if not printer.LastJob.Exists :
             # The printer hasn't been used yet, from PyKota's point of view
-            lasthistoryid = None
-            lastjobid = self.filter.jobid
-            lastuserid = userid
-            lastusername = self.filter.username
+            lastjob = None
+            lastuser = user
             lastpagecounter = counterbeforejob
         else :    
             # get last values from Quota Storage
-            (lasthistoryid, lastjobid, lastuserid, lastusername, lastpagecounter) = (pgc["id"], pgc["jobid"], pgc["userid"], pgc["username"], pgc["pagecounter"])
+            lastjob = printer.LastJob
+            lastuser = printer.LastJob.User
+            lastpagecounter = printer.LastJob.PrinterPageCounter
             
         # if printer is off then we assume the correct counter value is the last one
@@ -107,21 +109,25 @@
             # For more accurate accounting, don't switch off your HP printers !
             # explanation at : http://web.mit.edu/source/third/lprng/doc/LPRng-HOWTO-15.html
-            self.filter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastusername, self.filter.printername), "error")
+            self.filter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastuser.Name, self.filter.printername), "error")
             jobsize = abs(int((10 - abs(jobsize)) / 2))     # Workaround for HP printers' feature !
             
         # update the quota for the previous user on this printer 
-        self.filter.storage.updateUserPQuota(lastuserid, printerid, jobsize)
+        lastuserquota = self.filter.storage.getUserPQuota(lastuser, printer)
+        if lastuserquota.Exists :
+            lastuserquota.increasePagesUsage(jobsize)
         
         # update the last job size in the history
-        self.filter.storage.updateJobSizeInHistory(lasthistoryid, jobsize)
+        if printer.LastJob.Exists :
+            printer.LastJob.setSize(jobsize)
         
         # warns the last user if he is over quota
-        self.filter.warnUserPQuota(lastusername, self.filter.printername)
+        if lastuserquota.Exists :
+            self.filter.warnUserPQuota(lastuserquota)
             
         # Is the current user allowed to print at all ?
-        action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername)
+        action = self.filter.warnUserPQuota(self.filter.storage.getUserPQuota(user, printer))
         
         # adds the current job to history    
-        self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action)
+        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action)
             
         return action
