Index: /pykota/trunk/pykota/accounters/hardware.py
===================================================================
--- /pykota/trunk/pykota/accounters/hardware.py (revision 1600)
+++ /pykota/trunk/pykota/accounters/hardware.py (revision 1624)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.8  2004/07/22 22:41:48  jalet
+# Hardware accounting for LPRng should be OK now. UNTESTED.
+#
 # Revision 1.7  2004/07/16 12:22:47  jalet
 # LPRng support early version
@@ -72,10 +75,15 @@
         return counter    
         
-    def beginJob(self, userpquota) :    
+    def beginJob(self, printer) :    
         """Saves printer internal page counter at start of job."""
         # save page counter before job
-        self.LastPageCounter = self.counterbefore = self.getPrinterInternalPageCounter()
+        self.LastPageCounter = self.getPrinterInternalPageCounter()
+        self.fakeBeginJob()
         
-    def endJob(self, userpquota) :    
+    def fakeBeginJob(self) :    
+        """Fakes a begining of a job."""
+        self.counterbefore = self.getLastPageCounter()
+        
+    def endJob(self, printer) :    
         """Saves printer internal page counter at end of job."""
         # save page counter after job
Index: /pykota/trunk/pykota/accounter.py
===================================================================
--- /pykota/trunk/pykota/accounter.py (revision 1600)
+++ /pykota/trunk/pykota/accounter.py (revision 1624)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.18  2004/07/22 22:41:48  jalet
+# Hardware accounting for LPRng should be OK now. UNTESTED.
+#
 # Revision 1.17  2004/07/16 12:22:47  jalet
 # LPRng support early version
@@ -103,5 +106,5 @@
             return 0
             
-    def beginJob(self, userpquota) :    
+    def beginJob(self, printer) :    
         """Saves the computed job size."""
         # computes job's size
@@ -113,5 +116,5 @@
         
         # get last job information for this printer
-        if not userpquota.Printer.LastJob.Exists :
+        if not printer.LastJob.Exists :
             # The printer hasn't been used yet, from PyKota's point of view
             self.LastPageCounter = 0
@@ -120,7 +123,11 @@
             # Last lifetime page counter before actual job is 
             # last page counter + last job size
-            self.LastPageCounter = int(userpquota.Printer.LastJob.PrinterPageCounter or 0) + int(userpquota.Printer.LastJob.JobSize or 0)
+            self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0)
         
-    def endJob(self, userpquota) :    
+    def fakeBeginJob(self) :    
+        """Do nothing."""
+        pass
+        
+    def endJob(self, printer) :    
         """Do nothing."""
         pass
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 1582)
+++ /pykota/trunk/pykota/storage.py (revision 1624)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.57  2004/07/22 22:41:48  jalet
+# Hardware accounting for LPRng should be OK now. UNTESTED.
+#
 # Revision 1.56  2004/07/01 17:45:49  jalet
 # Added code to handle the description field for printers
@@ -513,20 +516,4 @@
         self.Printer = printer
         
-    def __getattr__(self, name) :    
-        """Delays data retrieval until it's really needed."""
-        if name == "User" : 
-            self.User = self.parent.getUser(self.UserName)
-            return self.User
-        else :    
-            raise AttributeError, name
-        
-    def setSize(self, userpquota, jobsize) :
-        """Sets the last job's size."""
-        jobprice = userpquota.computeJobPrice(jobsize)
-        self.parent.writeLastJobSize(self, jobsize, jobprice)
-        self.JobSize = jobsize
-        self.JobPrice = jobprice
-        return jobprice
-        
 class BaseStorage :
     def __init__(self, pykotatool) :
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1606)
+++ /pykota/trunk/bin/cupspykota (revision 1624)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.69  2004/07/22 22:41:47  jalet
+# Hardware accounting for LPRng should be OK now. UNTESTED.
+#
 # Revision 1.68  2004/07/20 22:19:44  jalet
 # Sanitized a bit + use of gettext
@@ -400,5 +403,5 @@
             
             self.printInfo(_("Job accounting begins."))
-            self.accounter.beginJob(userpquota)
+            self.accounter.beginJob(printer)
         else :    
             action = "ALLOW"
@@ -419,5 +422,5 @@
             
             # stops accounting. 
-            self.accounter.endJob(userpquota)
+            self.accounter.endJob(printer)
             self.printInfo(_("Job accounting ends."))
                 
Index: /pykota/trunk/bin/lprngpykota
===================================================================
--- /pykota/trunk/bin/lprngpykota (revision 1611)
+++ /pykota/trunk/bin/lprngpykota (revision 1624)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.4  2004/07/22 22:41:48  jalet
+# Hardware accounting for LPRng should be OK now. UNTESTED.
+#
 # Revision 1.3  2004/07/21 09:35:48  jalet
 # Software accounting seems to be OK with LPRng support now
@@ -84,5 +87,10 @@
             # and that the second pass didn't work or wasn't even launched
             # we know have to act just as if we were in second pass
-            raise PyKotaToolError, "Not implemented yet !"
+            # for previous user on this printer, then we will continue
+            # with normal processing of current user.
+            self.secondPass(policy, printer, None, None)
+        
+        # export user info with initial values
+        self.exportUserInfo(userpquota)
         
         # tries to extract job-originating-hostname 
@@ -119,9 +127,9 @@
         
         self.logdebug("Job accounting begins.")
-        self.accounter.beginJob(userpquota)
+        self.accounter.beginJob(printer)
         
         jobsize = None
         if self.accounter.isSoftware :
-            self.accounter.endJob(userpquota)
+            self.accounter.endJob(printer)
             jobsize = self.accounter.getJobSize()
             self.logdebug("Job accounting ends.")
@@ -131,5 +139,5 @@
             self.logdebug("Job size forced to 0 because printing was denied.")
             
-        if jobsize is not None :    
+        if self.accounter.isSoftware :    
             # update the quota for the current user on this printer 
             self.logdebug("Job size : %i" % jobsize)
@@ -180,15 +188,49 @@
                 raise PyKotaToolError, _("Hardware accounting already finished ! This should be impossible, please report this problem ASAP.")
                 
+            # here if user and userpquota are both None
+            # then it's a special second pass for a job
+            # which should have had one but didn't, so
+            # we need to get the last user, not the current one.
+            if (user is None) and (userpquota is None) :
+                user = printer.LastJob.User
+                userpquota = self.storage.getUserPQuota(user, printer)
+                
+            # exports user info for last user    
+            self.exportUserInfo(userpquota)
+            
             # indicate phase change
             os.environ["PYKOTAPHASE"] = "AFTER"
             
+            # fakes beginning of job with old page counter
+            self.accounter.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0)
+            self.accounter.fakeBeginJob()
+            self.logdebug("Fakes beginning of job with LastPageCounter: %s" % self.accounter.getLastPageCounter())
+            
             # stops accounting. 
-            self.accounter.endJob(userpquota)
+            self.accounter.endJob(printer)
             self.logdebug("Job accounting ends.")
                 
             # retrieve the job size    
             jobsize = self.accounter.getJobSize()
+            
             self.logdebug("Job size : %i" % jobsize)
-            raise PyKotaToolError, "Not implemented !"
+            self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name))
+            jobprice = userpquota.increasePagesUsage(jobsize)
+            
+            self.storage.writeLastJobSize(printer.LastJob, jobsize, jobprice)
+            self.logdebug("Job size and price now set in history.")
+            
+            # exports some new environment variables
+            os.environ["PYKOTAPHASE"] = "AFTER"
+            os.environ["PYKOTAJOBSIZE"] = str(jobsize)
+            os.environ["PYKOTAJOBPRICE"] = str(jobprice)
+            
+            # then re-export user information with new value
+            self.exportUserInfo(userpquota)
+            
+            # Launches the post hook
+            self.posthook(userpquota)
+            
+            # here hardware accounting was completed.
         return self.acceptJob()
         
@@ -204,7 +246,4 @@
             return self.acceptJob()
         else :    
-            # exports user information with initial values
-            self.exportUserInfo(userpquota)
-            
             if (not printer.LastJob.Exists) or (printer.LastJob.JobId != self.jobid) :
                 # Last job for current printer has a different JobId than
