Changeset 3285 for pykota/trunk

Show
Ignore:
Timestamp:
01/09/08 00:17:47 (16 years ago)
Author:
jerome
Message:

Now external preaccounter/accounter scripts must read the print job's datas
from the file pointed to by the PYKOTADATAFILE environment variable, instead
of from their stdin.

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r3275 r3285  
    600600# languages, but may occasionally fail for some printer drivers. 
    601601# You can however use any other command, provided it can read the datas to 
    602 # parse from its standard input, and prints a single integer on its standard 
     602# parse from the file pointed to by the PYKOTADATAFILE environment 
     603# variable, and prints a single integer on its standard 
    603604# output, representing the number of pages in the print job. 
    604605# Software accounting unfortunately may overcharge users in case of paper 
     
    647648# accounter : hardware(/opt/local/net-snmp/bin/snmpwalk -v 1 -Cc -c public %(printer)s | grep mib-2.43.10.2.1.4.1.1 | cut -d " " -f4) 
    648649# accounter : hardware(/opt/local/net-snmp/bin/snmpwalk -v 1 -Cc -c public -Ov %(printer)s | grep Counter32 | tail -2 | head -1 | cut -d " " -f2) 
    649 # accounter : software(/usr/bin/pkpgcounter)  
     650# accounter : software(/usr/bin/pkpgcounter "$PYKOTADATAFILE")  
    650651# accounter : software() 
    651652# accounter : ink(cmyk, 150) 
     
    718719# reasons. If unset, "software()" is assumed. If you use your own script,  
    719720# ensure that it only prints the job's number of pages (or an estimation  
    720 # of it) on its standard output. 
     721# of it) on its standard output, and that it reads the print job's datas 
     722# from the file pointed to by the PYKOTADATAFILE environment variable. 
    721723# 
    722724# You may want to define for example 'preaccounter : software(/bin/echo 1)' 
  • pykota/trunk/pykota/accounters/software.py

    r3275 r3285  
    7575        """Does software accounting through an external script.""" 
    7676        self.filter.printInfo(_("Launching SOFTWARE(%s)...") % self.arguments) 
    77         MEGABYTE = 1024*1024 
    78         infile = open(self.filter.DataFile, "rb") 
    79         child = popen2.Popen4(self.arguments) 
     77        pagecounter = None 
     78        child = os.popen(self.arguments, "r") 
    8079        try : 
    81             data = infile.read(MEGABYTE)     
    82             while data : 
    83                 child.tochild.write(data) 
    84                 data = infile.read(MEGABYTE) 
    85             child.tochild.flush() 
    86             child.tochild.close()     
    87         except (IOError, OSError), msg :     
    88             msg = "%s : %s" % (self.arguments, msg)  
    89             self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) 
    90         infile.close() 
    91         pagecounter = None 
    92         try : 
    93             answer = child.fromchild.read() 
     80            answer = child.read() 
    9481        except (IOError, OSError), msg :     
    9582            msg = "%s : %s" % (self.arguments, msg)  
     
    10491                else :     
    10592                    break 
    106         child.fromchild.close() 
    107          
     93                     
     94        status = child.close() 
    10895        try : 
    109             status = child.wait() 
    110         except OSError, msg :     
    111             self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg)) 
    112         else :     
    11396            if os.WIFEXITED(status) : 
    11497                status = os.WEXITSTATUS(status) 
    115             self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) 
     98        except TypeError :         
     99            pass # None means no error occured. 
     100        self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) 
    116101             
    117102        if pagecounter is None :