Changeset 976

Show
Ignore:
Timestamp:
04/30/03 15:36:40 (22 years ago)
Author:
jalet
Message:

Stupid accounting method was added.

Location:
pykota/trunk
Files:
1 added
13 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pykota

    r975 r976  
    2323# 
    2424# $Log$ 
     25# Revision 1.31  2003/04/30 13:36:39  jalet 
     26# Stupid accounting method was added. 
     27# 
    2528# Revision 1.30  2003/04/29 22:03:38  jalet 
    2629# Better error handling. 
     
    192195        return (None, None, None, None, None, None)   # Unknown printing system           
    193196         
    194     def filterInput(self, inputfile) : 
    195         """Transparent filter.""" 
    196         mustclose = 0     
    197         if inputfile is not None :     
    198             infile = open(inputfile, "rb") 
    199             mustclose = 1 
    200         else :     
    201             infile = sys.stdin 
    202         data = infile.read(256*1024)     
    203         while data : 
    204             sys.stdout.write(data) 
    205             data = infile.read(256*1024) 
    206         if mustclose :     
    207             infile.close() 
    208              
    209197    def acceptJob(self) :         
    210198        """Returns the exit code needed by the printing backend to accept the job and print it.""" 
     
    270258         
    271259    # pass the job untouched to the underlying layer 
    272     kotafilter.filterInput(kotafilter.inputfile)       
     260    kotafilter.accounter.filterInput(kotafilter.inputfile)       
    273261     
    274262    return kotafilter.acceptJob() 
  • pykota/trunk/conf/pykota.conf.sample

    r974 r976  
    5858# 
    5959#    - querying : asks the printer for its lifetime page counter 
     60#                 via either SNMP, AppleTalk, or any external 
     61#                 command. This method is the method used by 
     62#                 default in PyKota since its beginning. 
     63# 
     64#    - stupid : counts the occurences of the 'showpage' postscript 
     65#               statement in the document to be printed, only at 
     66#               the beginning of each line which makes the postscript 
     67#               file. THIS IS NOT RELIABLE. This is just to serve as 
     68#               an example on how to implement your own accounting 
     69#               method. 
     70# 
    6071#    - more to be added in the future 
    6172# 
    6273# This value can be set either globally or on a per printer basis 
    63 # if not set it defaults to 'querying' 
     74# If both are defined, the printer option has priority. 
     75# if not set it defaults to 'querying'. 
    6476accounter: querying 
    6577 
  • pykota/trunk/NEWS

    r975 r976  
    2222PyKota NEWS : 
    2323 
     24    - 1.05alpha3 : 
     25     
     26        - A 'stupid' and unreliable accounting method was 
     27          implemented to serve as an example on how to 
     28          do this sort of things. This method only counts 
     29          the 'showpage' statements in the input data. 
     30          See sample configuration file for details. 
     31          Pluggable accounting methods work, but I advise 
     32          you TO NOT USE THIS ONE WHICH IS JUST AN EXAMPLE. 
     33          It is not reliable enough to be used. 
     34           
    2435    - 1.05alpha2 : 
    2536     
  • pykota/trunk/po/en/pykota.po

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.23  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.22  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    337340msgid "Option requester for printer %s was not set" 
    338341msgstr "" 
     342 
     343msgid "Using the 'stupid' accounting method is unreliable." 
     344msgstr "" 
  • pykota/trunk/po/fr/pykota.po

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.22  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.21  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    349352msgid "Option requester for printer %s was not set" 
    350353msgstr "L'option requester pour l'imprimante %s n'a pas � d�nie" 
     354 
     355msgid "Using the 'stupid' accounting method is unreliable." 
     356msgstr "Utiliser la m�ode 'stupid' n'est pas fiable." 
  • pykota/trunk/po/pykota.pot

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.23  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.22  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    337340msgid "Option requester for printer %s was not set" 
    338341msgstr "" 
     342 
     343msgid "Using the 'stupid' accounting method is unreliable." 
     344msgstr "" 
  • pykota/trunk/pykota/accounter.py

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.2  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.1  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    2629# 
    2730# 
     31 
     32import sys 
    2833 
    2934class PyKotaAccounterError(Exception): 
     
    4247        self.filter = kotafilter 
    4348         
     49    def filterInput(self, inputfile) : 
     50        """Transparent filter.""" 
     51        mustclose = 0     
     52        if inputfile is not None :     
     53            if hasattr(inputfile, "read") : 
     54                infile = inputfile 
     55            else :     
     56                infile = open(inputfile, "rb") 
     57            mustclose = 1 
     58        else :     
     59            infile = sys.stdin 
     60        data = infile.read(256*1024)     
     61        while data : 
     62            sys.stdout.write(data) 
     63            data = infile.read(256*1024) 
     64        if mustclose :     
     65            infile.close() 
     66             
    4467    def doAccounting(self, printerid, userid) :     
    4568        """Does the real accounting.""" 
  • pykota/trunk/pykota/accounters/querying.py

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.2  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.1  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    2730# 
    2831 
     32import sys 
    2933from pykota.accounter import AccounterBase, PyKotaAccounterError 
    3034from pykota.requester import openRequester, PyKotaRequesterError 
     
    118122             
    119123        return action 
     124             
  • pykota/trunk/pykota/config.py

    r973 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.25  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.24  2003/04/29 18:37:54  jalet 
    2427# Pluggable accounting methods (actually doesn't support external scripts) 
     
    197200           for its internal lifetime page counter. 
    198201        """    
    199         validaccounters = [ "querying" ]      
     202        validaccounters = [ "querying", "stupid" ]      
    200203        try : 
    201204            accounter = self.getPrinterOption(printer, "accounter").lower() 
  • pykota/trunk/pykota/storages/postgresql.py

    r967 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.10  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.9  2003/04/27 08:04:15  jalet 
    2427# LDAP storage backend's skeleton added. DOESN'T WORK. 
     
    111114    def doQuote(self, field) : 
    112115        """Quotes a field for use as a string in SQL queries.""" 
    113         if type(field) == type(0) : # TODO : do something safer 
     116        if type(field) in (type(0), type(0.0)) : # TODO : do something safer 
    114117            typ = "decimal" 
    115118        else :     
  • pykota/trunk/pykota/storages/sql.py

    r967 r976  
    2121# 
    2222# $Log$ 
     23# Revision 1.31  2003/04/30 13:36:40  jalet 
     24# Stupid accounting method was added. 
     25# 
    2326# Revision 1.30  2003/04/27 08:04:15  jalet 
    2427# LDAP storage backend's skeleton added. DOESN'T WORK. 
     
    368371        self.doQuery("UPDATE grouppquota SET datelimit=%s::TIMESTAMP WHERE groupid=%s AND printerid=%s" % (self.doQuote("%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second)), self.doQuote(groupid), self.doQuote(printerid))) 
    369372         
    370     def addJobToHistory(self, jobid, userid, printerid, pagecounter, action) : 
     373    def addJobToHistory(self, jobid, userid, printerid, pagecounter, action, jobsize=None) : 
    371374        """Adds a job to the history: (jobid, userid, printerid, last page counter taken from requester).""" 
    372         self.doQuery("INSERT INTO jobhistory (jobid, userid, printerid, pagecounter, action) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(jobid), self.doQuote(userid), self.doQuote(printerid), self.doQuote(pagecounter), self.doQuote(action))) 
     375        self.doQuery("INSERT INTO jobhistory (jobid, userid, printerid, pagecounter, action, jobsize) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(jobid), self.doQuote(userid), self.doQuote(printerid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize))) 
    373376        return self.getJobHistoryId(jobid, userid, printerid) # in case jobid is not sufficient 
    374377     
     
    379382    def getPrinterPageCounter(self, printerid) : 
    380383        """Returns the last page counter value for a printer given its id, also returns last username, last jobid and history line id.""" 
    381         result = self.doQuery("SELECT jobhistory.id, jobid, userid, username, pagecounter FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printerid)) 
     384        result = self.doQuery("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printerid)) 
    382385        try : 
    383386            return self.doParseResult(result)[0] 
  • pykota/trunk/pykota/version.py

    r973 r976  
    2121# 
    2222 
    23 __version__ = "1.05alpha2-unofficial" 
     23__version__ = "1.05alpha3-unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""