Changeset 1624 for pykota/trunk

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
Files:
5 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 
  • pykota/trunk/pykota/accounter.py

    r1600 r1624  
    2222# 
    2323# $Log$ 
     24# Revision 1.18  2004/07/22 22:41:48  jalet 
     25# Hardware accounting for LPRng should be OK now. UNTESTED. 
     26# 
    2427# Revision 1.17  2004/07/16 12:22:47  jalet 
    2528# LPRng support early version 
     
    103106            return 0 
    104107             
    105     def beginJob(self, userpquota) :     
     108    def beginJob(self, printer) :     
    106109        """Saves the computed job size.""" 
    107110        # computes job's size 
     
    113116         
    114117        # get last job information for this printer 
    115         if not userpquota.Printer.LastJob.Exists : 
     118        if not printer.LastJob.Exists : 
    116119            # The printer hasn't been used yet, from PyKota's point of view 
    117120            self.LastPageCounter = 0 
     
    120123            # Last lifetime page counter before actual job is  
    121124            # last page counter + last job size 
    122             self.LastPageCounter = int(userpquota.Printer.LastJob.PrinterPageCounter or 0) + int(userpquota.Printer.LastJob.JobSize or 0) 
     125            self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    123126         
    124     def endJob(self, userpquota) :     
     127    def fakeBeginJob(self) :     
     128        """Do nothing.""" 
     129        pass 
     130         
     131    def endJob(self, printer) :     
    125132        """Do nothing.""" 
    126133        pass 
  • pykota/trunk/pykota/accounters/hardware.py

    r1600 r1624  
    2222# 
    2323# $Log$ 
     24# Revision 1.8  2004/07/22 22:41:48  jalet 
     25# Hardware accounting for LPRng should be OK now. UNTESTED. 
     26# 
    2427# Revision 1.7  2004/07/16 12:22:47  jalet 
    2528# LPRng support early version 
     
    7275        return counter     
    7376         
    74     def beginJob(self, userpquota) :     
     77    def beginJob(self, printer) :     
    7578        """Saves printer internal page counter at start of job.""" 
    7679        # save page counter before job 
    77         self.LastPageCounter = self.counterbefore = self.getPrinterInternalPageCounter() 
     80        self.LastPageCounter = self.getPrinterInternalPageCounter() 
     81        self.fakeBeginJob() 
    7882         
    79     def endJob(self, userpquota) :     
     83    def fakeBeginJob(self) :     
     84        """Fakes a begining of a job.""" 
     85        self.counterbefore = self.getLastPageCounter() 
     86         
     87    def endJob(self, printer) :     
    8088        """Saves printer internal page counter at end of job.""" 
    8189        # save page counter after job 
  • pykota/trunk/pykota/storage.py

    r1582 r1624  
    2222# 
    2323# $Log$ 
     24# Revision 1.57  2004/07/22 22:41:48  jalet 
     25# Hardware accounting for LPRng should be OK now. UNTESTED. 
     26# 
    2427# Revision 1.56  2004/07/01 17:45:49  jalet 
    2528# Added code to handle the description field for printers 
     
    513516        self.Printer = printer 
    514517         
    515     def __getattr__(self, name) :     
    516         """Delays data retrieval until it's really needed.""" 
    517         if name == "User" :  
    518             self.User = self.parent.getUser(self.UserName) 
    519             return self.User 
    520         else :     
    521             raise AttributeError, name 
    522          
    523     def setSize(self, userpquota, jobsize) : 
    524         """Sets the last job's size.""" 
    525         jobprice = userpquota.computeJobPrice(jobsize) 
    526         self.parent.writeLastJobSize(self, jobsize, jobprice) 
    527         self.JobSize = jobsize 
    528         self.JobPrice = jobprice 
    529         return jobprice 
    530          
    531518class BaseStorage : 
    532519    def __init__(self, pykotatool) :