Show
Ignore:
Timestamp:
01/31/06 12:32:34 (18 years ago)
Author:
jerome
Message:

Introduced the 'preaccounter' directive.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounter.py

    r2622 r2635  
    3636class AccounterBase :     
    3737    """A class to account print usage by querying printers.""" 
    38     def __init__(self, kotafilter, arguments) : 
     38    def __init__(self, kotafilter, arguments, ispreaccounter=0) : 
    3939        """Sets instance vars depending on the current printer.""" 
    4040        self.filter = kotafilter 
     
    4242        self.onerror = self.filter.config.getPrinterOnAccounterError(self.filter.PrinterName) 
    4343        self.isSoftware = 1 # by default software accounting 
     44        self.isPreAccounter = ispreaccounter  
    4445         
    4546    def getLastPageCounter(self) :     
     
    5859         
    5960        # get last job information for this printer 
    60         if not printer.LastJob.Exists : 
    61             # The printer hasn't been used yet, from PyKota's point of view 
    62             self.LastPageCounter = 0 
    63         else :     
    64             # get last job size and page counter from Quota Storage 
    65             # Last lifetime page counter before actual job is  
    66             # last page counter + last job size 
    67             self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
     61        if not self.isPreAccounter : 
     62            # TODO : check if this code is still needed 
     63            if not printer.LastJob.Exists : 
     64                # The printer hasn't been used yet, from PyKota's point of view 
     65                self.LastPageCounter = 0 
     66            else :     
     67                # get last job size and page counter from Quota Storage 
     68                # Last lifetime page counter before actual job is  
     69                # last page counter + last job size 
     70                self.LastPageCounter = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    6871         
    6972    def fakeBeginJob(self) :     
     
    8689        raise RuntimeError, "AccounterBase.computeJobSize() must be overriden !" 
    8790         
    88 def openAccounter(kotafilter) : 
     91def openAccounter(kotafilter, ispreaccounter=0) : 
    8992    """Returns a connection handle to the appropriate accounter.""" 
    90     (backend, args) = kotafilter.config.getAccounterBackend(kotafilter.PrinterName) 
     93    if ispreaccounter : 
     94        (backend, args) = kotafilter.config.getPreAccounterBackend(kotafilter.PrinterName) 
     95    else : 
     96        (backend, args) = kotafilter.config.getAccounterBackend(kotafilter.PrinterName) 
    9197    try : 
    9298        exec "from pykota.accounters import %s as accounterbackend" % backend.lower() 
     
    94100        raise PyKotaAccounterError, _("Unsupported accounter backend %s") % backend 
    95101    else :     
    96         return accounterbackend.Accounter(kotafilter, args) 
     102        return accounterbackend.Accounter(kotafilter, args, ispreaccounter)