Changeset 1624 for pykota/trunk/bin

Show
Ignore:
Timestamp:
07/23/04 00:41:48 (20 years ago)
Author:
jalet
Message:

Hardware accounting for LPRng should be OK now. UNTESTED.

Location:
pykota/trunk/bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1606 r1624  
    2424# 
    2525# $Log$ 
     26# Revision 1.69  2004/07/22 22:41:47  jalet 
     27# Hardware accounting for LPRng should be OK now. UNTESTED. 
     28# 
    2629# Revision 1.68  2004/07/20 22:19:44  jalet 
    2730# Sanitized a bit + use of gettext 
     
    400403             
    401404            self.printInfo(_("Job accounting begins.")) 
    402             self.accounter.beginJob(userpquota) 
     405            self.accounter.beginJob(printer) 
    403406        else :     
    404407            action = "ALLOW" 
     
    419422             
    420423            # stops accounting.  
    421             self.accounter.endJob(userpquota) 
     424            self.accounter.endJob(printer) 
    422425            self.printInfo(_("Job accounting ends.")) 
    423426                 
  • pykota/trunk/bin/lprngpykota

    r1611 r1624  
    2424# 
    2525# $Log$ 
     26# Revision 1.4  2004/07/22 22:41:48  jalet 
     27# Hardware accounting for LPRng should be OK now. UNTESTED. 
     28# 
    2629# Revision 1.3  2004/07/21 09:35:48  jalet 
    2730# Software accounting seems to be OK with LPRng support now 
     
    8487            # and that the second pass didn't work or wasn't even launched 
    8588            # we know have to act just as if we were in second pass 
    86             raise PyKotaToolError, "Not implemented yet !" 
     89            # for previous user on this printer, then we will continue 
     90            # with normal processing of current user. 
     91            self.secondPass(policy, printer, None, None) 
     92         
     93        # export user info with initial values 
     94        self.exportUserInfo(userpquota) 
    8795         
    8896        # tries to extract job-originating-hostname  
     
    119127         
    120128        self.logdebug("Job accounting begins.") 
    121         self.accounter.beginJob(userpquota) 
     129        self.accounter.beginJob(printer) 
    122130         
    123131        jobsize = None 
    124132        if self.accounter.isSoftware : 
    125             self.accounter.endJob(userpquota) 
     133            self.accounter.endJob(printer) 
    126134            jobsize = self.accounter.getJobSize() 
    127135            self.logdebug("Job accounting ends.") 
     
    131139            self.logdebug("Job size forced to 0 because printing was denied.") 
    132140             
    133         if jobsize is not None :     
     141        if self.accounter.isSoftware :     
    134142            # update the quota for the current user on this printer  
    135143            self.logdebug("Job size : %i" % jobsize) 
     
    180188                raise PyKotaToolError, _("Hardware accounting already finished ! This should be impossible, please report this problem ASAP.") 
    181189                 
     190            # here if user and userpquota are both None 
     191            # then it's a special second pass for a job 
     192            # which should have had one but didn't, so 
     193            # we need to get the last user, not the current one. 
     194            if (user is None) and (userpquota is None) : 
     195                user = printer.LastJob.User 
     196                userpquota = self.storage.getUserPQuota(user, printer) 
     197                 
     198            # exports user info for last user     
     199            self.exportUserInfo(userpquota) 
     200             
    182201            # indicate phase change 
    183202            os.environ["PYKOTAPHASE"] = "AFTER" 
    184203             
     204            # fakes beginning of job with old page counter 
     205            self.accounter.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) 
     206            self.accounter.fakeBeginJob() 
     207            self.logdebug("Fakes beginning of job with LastPageCounter: %s" % self.accounter.getLastPageCounter()) 
     208             
    185209            # stops accounting.  
    186             self.accounter.endJob(userpquota) 
     210            self.accounter.endJob(printer) 
    187211            self.logdebug("Job accounting ends.") 
    188212                 
    189213            # retrieve the job size     
    190214            jobsize = self.accounter.getJobSize() 
     215             
    191216            self.logdebug("Job size : %i" % jobsize) 
    192             raise PyKotaToolError, "Not implemented !" 
     217            self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 
     218            jobprice = userpquota.increasePagesUsage(jobsize) 
     219             
     220            self.storage.writeLastJobSize(printer.LastJob, jobsize, jobprice) 
     221            self.logdebug("Job size and price now set in history.") 
     222             
     223            # exports some new environment variables 
     224            os.environ["PYKOTAPHASE"] = "AFTER" 
     225            os.environ["PYKOTAJOBSIZE"] = str(jobsize) 
     226            os.environ["PYKOTAJOBPRICE"] = str(jobprice) 
     227             
     228            # then re-export user information with new value 
     229            self.exportUserInfo(userpquota) 
     230             
     231            # Launches the post hook 
     232            self.posthook(userpquota) 
     233             
     234            # here hardware accounting was completed. 
    193235        return self.acceptJob() 
    194236         
     
    204246            return self.acceptJob() 
    205247        else :     
    206             # exports user information with initial values 
    207             self.exportUserInfo(userpquota) 
    208              
    209248            if (not printer.LastJob.Exists) or (printer.LastJob.JobId != self.jobid) : 
    210249                # Last job for current printer has a different JobId than