Show
Ignore:
Timestamp:
06/25/03 16:10:01 (21 years ago)
Author:
jalet
Message:

Hey, it may work (edpykota --reset excepted) !

Location:
pykota/trunk/pykota/accounters
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/external.py

    r1000 r1041  
    2121# 
    2222# $Log$ 
     23# Revision 1.4  2003/06/25 14:10:01  jalet 
     24# Hey, it may work (edpykota --reset excepted) ! 
     25# 
    2326# Revision 1.3  2003/05/27 23:00:21  jalet 
    2427# Big rewrite of external accounting methods. 
     
    4144 
    4245class Accounter(AccounterBase) : 
    43     def doAccounting(self, printerid, userid) : 
     46    def doAccounting(self, printer, user) : 
    4447        """Deletgates the computation of the job size to an external command. 
    4548         
     
    5053             
    5154        # get last job information for this printer 
    52         pgc = self.filter.storage.getPrinterPageCounter(printerid)     
    53         if pgc is None : 
     55        if not printer.LastJob.Exists : 
    5456            # The printer hasn't been used yet, from PyKota's point of view 
    5557            counterbeforejob = 0 
     
    5860            # Last lifetime page counter before actual job is  
    5961            # last page counter + last job size 
    60             counterbeforejob = (pgc["pagecounter"] or 0) + (pgc["jobsize"] or 0) 
     62            counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    6163             
    6264        # Is the current user allowed to print at all ? 
    63         action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername) 
     65        userpquota = self.filter.storage.getUserPQuota(user, printer) 
     66        action = self.filter.warnUserPQuota(userpquota) 
    6467         
    6568        # update the quota for the current user on this printer, if allowed to print 
     
    6770            jobsize = 0 
    6871        else :     
    69             self.filter.storage.updateUserPQuota(userid, printerid, jobsize) 
     72            userpquota.increasePagesUsage(jobsize) 
    7073         
    7174        # adds the current job to history     
    72         self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action, jobsize) 
     75        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize) 
    7376             
    7477        return action 
     
    102105            # launches child process 
    103106            command = "%s <%s >%s 2>%s" % (self.arguments, infilename, outfilename, errfilename) 
    104             o = open("/tmp/comm", "w") 
    105             o.write("%s\n" % command) 
    106             o.close() 
    107107            retcode = os.system(command) 
    108108             
  • pykota/trunk/pykota/accounters/querying.py

    r988 r1041  
    2121# 
    2222# $Log$ 
     23# Revision 1.4  2003/06/25 14:10:01  jalet 
     24# Hey, it may work (edpykota --reset excepted) ! 
     25# 
    2326# Revision 1.3  2003/05/06 14:55:47  jalet 
    2427# Missing import ! 
     
    3841from pykota.requester import openRequester, PyKotaRequesterError 
    3942 
    40 MAXTRIES = 6     # maximum number of tries to get the printer's internal page counter 
     43MAXTRIES = 12    # maximum number of tries to get the printer's internal page counter 
    4144TIMETOSLEEP = 10 # number of seconds to sleep between two tries to get the printer's internal page counter 
    4245 
    4346class Accounter(AccounterBase) : 
    44     def doAccounting(self, printerid, userid) : 
     47    def doAccounting(self, printer, user) : 
    4548        """Does print accounting and returns if the job status is ALLOW or DENY.""" 
    4649        # Get the page counter directly from the printer itself 
     
    6568         
    6669        # get last job information for this printer 
    67         pgc = self.filter.storage.getPrinterPageCounter(printerid)     
    68         if pgc is None : 
     70        if not printer.LastJob.Exists : 
    6971            # The printer hasn't been used yet, from PyKota's point of view 
    70             lasthistoryid = None 
    71             lastjobid = self.filter.jobid 
    72             lastuserid = userid 
    73             lastusername = self.filter.username 
     72            lastjob = None 
     73            lastuser = user 
    7474            lastpagecounter = counterbeforejob 
    7575        else :     
    7676            # get last values from Quota Storage 
    77             (lasthistoryid, lastjobid, lastuserid, lastusername, lastpagecounter) = (pgc["id"], pgc["jobid"], pgc["userid"], pgc["username"], pgc["pagecounter"]) 
     77            lastjob = printer.LastJob 
     78            lastuser = printer.LastJob.User 
     79            lastpagecounter = printer.LastJob.PrinterPageCounter 
    7880             
    7981        # if printer is off then we assume the correct counter value is the last one 
     
    107109            # For more accurate accounting, don't switch off your HP printers ! 
    108110            # explanation at : http://web.mit.edu/source/third/lprng/doc/LPRng-HOWTO-15.html 
    109             self.filter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastusername, self.filter.printername), "error") 
     111            self.filter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastuser.Name, self.filter.printername), "error") 
    110112            jobsize = abs(int((10 - abs(jobsize)) / 2))     # Workaround for HP printers' feature ! 
    111113             
    112114        # update the quota for the previous user on this printer  
    113         self.filter.storage.updateUserPQuota(lastuserid, printerid, jobsize) 
     115        lastuserquota = self.filter.storage.getUserPQuota(lastuser, printer) 
     116        if lastuserquota.Exists : 
     117            lastuserquota.increasePagesUsage(jobsize) 
    114118         
    115119        # update the last job size in the history 
    116         self.filter.storage.updateJobSizeInHistory(lasthistoryid, jobsize) 
     120        if printer.LastJob.Exists : 
     121            printer.LastJob.setSize(jobsize) 
    117122         
    118123        # warns the last user if he is over quota 
    119         self.filter.warnUserPQuota(lastusername, self.filter.printername) 
     124        if lastuserquota.Exists : 
     125            self.filter.warnUserPQuota(lastuserquota) 
    120126             
    121127        # Is the current user allowed to print at all ? 
    122         action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername) 
     128        action = self.filter.warnUserPQuota(self.filter.storage.getUserPQuota(user, printer)) 
    123129         
    124130        # adds the current job to history     
    125         self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action) 
     131        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action) 
    126132             
    127133        return action 
  • pykota/trunk/pykota/accounters/stupid.py

    r1000 r1041  
    2121# 
    2222# $Log$ 
     23# Revision 1.4  2003/06/25 14:10:01  jalet 
     24# Hey, it may work (edpykota --reset excepted) ! 
     25# 
    2326# Revision 1.3  2003/05/27 23:00:21  jalet 
    2427# Big rewrite of external accounting methods. 
     
    3942 
    4043class Accounter(AccounterBase) : 
    41     def doAccounting(self, printerid, userid) : 
     44    def doAccounting(self, printer, user) : 
    4245        """Does print accounting by stupidly counting the 'showpage' postscript instructions in the document. 
    4346         
     
    5154             
    5255        # get last job information for this printer 
    53         pgc = self.filter.storage.getPrinterPageCounter(printerid)     
    54         if pgc is None : 
     56        if not printer.LastJob.Exists : 
    5557            # The printer hasn't been used yet, from PyKota's point of view 
    5658            counterbeforejob = 0 
     
    5961            # Last lifetime page counter before actual job is  
    6062            # last page counter + last job size 
    61             counterbeforejob = (pgc["pagecounter"] or 0) + (pgc["jobsize"] or 0) 
     63            counterbeforejob = int(printer.LastJob.PrinterPageCounter or 0) + int(printer.LastJob.JobSize or 0) 
    6264             
    6365        # Is the current user allowed to print at all ? 
    64         action = self.filter.warnUserPQuota(self.filter.username, self.filter.printername) 
     66        userpquota = self.filter.storage.getUserPQuota(user, printer) 
     67        action = self.filter.warnUserPQuota(userpquota) 
    6568         
    6669        # update the quota for the current user on this printer, if allowed to print 
     
    6871            jobsize = 0 
    6972        else :     
    70             self.filter.storage.updateUserPQuota(userid, printerid, jobsize) 
     73            userpquota.increasePagesUsage(jobsize) 
    7174         
    7275        # adds the current job to history     
    73         self.filter.storage.addJobToHistory(self.filter.jobid, self.filter.storage.getUserId(self.filter.username), printerid, counterbeforejob, action, jobsize) 
     76        printer.addJobToHistory(self.filter.jobid, user, counterbeforejob, action, jobsize) 
    7477             
    7578        return action