Show
Ignore:
Timestamp:
05/28/03 01:00:21 (21 years ago)
Author:
jalet
Message:

Big rewrite of external accounting methods.
Should work well now.

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

Legend:

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

    r995 r1000  
    2121# 
    2222# $Log$ 
     23# Revision 1.3  2003/05/27 23:00:21  jalet 
     24# Big rewrite of external accounting methods. 
     25# Should work well now. 
     26# 
    2327# Revision 1.2  2003/05/13 13:54:20  jalet 
    2428# Better handling of broken pipes 
     
    4246           The command must print the job size on its standard output and exit successfully. 
    4347        """ 
    44         # get the job size     
    45         jobsize = self.getJobSize() 
     48        # get the job size, which is real job size * number of copies. 
     49        jobsize = self.getJobSize() * self.filter.copies 
    4650             
    4751        # get last job information for this printer 
     
    8185             
    8286        # launches external accounter 
     87        infilename = tempfile.mktemp() 
     88        outfilename = tempfile.mktemp() 
     89        errfilename = tempfile.mktemp() 
     90         
    8391        try : 
    84             process = popen2.Popen3("%s" % self.arguments) 
    85          
    8692            # feed it with our data 
     93            fakeinput = open(infilename, "wb") 
    8794            data = infile.read(256*1024)     
    8895            while data : 
    89                 process.tochild.write(data) 
    90                 temporary.write(data) 
     96                fakeinput.write(data) 
     97                if temporary is not None : 
     98                    temporary.write(data) 
    9199                data = infile.read(256*1024) 
    92             process.tochild.close() 
     100            fakeinput.close() 
    93101         
    94             # wait for child process to exit (or die) 
    95             retcode = process.wait() 
     102            # launches child process 
     103            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() 
     107            retcode = os.system(command) 
    96108             
    97109            # check exit status 
    98             if os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode) : 
     110            if (os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode)) or os.stat(errfilename) : 
    99111                # tries to extract the job size from the external accounter's 
    100112                # standard output 
     113                childoutput = open(outfilename, "r") 
    101114                try : 
    102                     pagecount = int(process.fromchild.readline().strip()) 
     115                    pagecount = int(childoutput.readline().strip()) 
    103116                except (AttributeError, ValueError) : 
    104117                    self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 
    105118                    pagecount = 0 
     119                childoutput.close()     
    106120            else : 
    107121                self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 
    108122                pagecount = 0 
    109             process.fromchild.close()     
     123            os.remove(infilename) 
     124            os.remove(outfilename) 
     125            os.remove(errfilename) 
    110126        except IOError, msg :     
     127            # TODO : temporary files may remain on the filesystem... 
    111128            msg = "%s : %s" % (self.arguments, msg)  
    112129            self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % msg) 
  • pykota/trunk/pykota/accounters/stupid.py

    r977 r1000  
    2121# 
    2222# $Log$ 
     23# Revision 1.3  2003/05/27 23:00:21  jalet 
     24# Big rewrite of external accounting methods. 
     25# Should work well now. 
     26# 
    2327# Revision 1.2  2003/04/30 13:40:47  jalet 
    2428# Small fix 
     
    4448         
    4549        # get the job size     
    46         jobsize = self.getJobSize() 
     50        jobsize = self.getJobSize() * self.filter.copies 
    4751             
    4852        # get last job information for this printer 
     
    8690        pagecount = 0 
    8791        for line in infile.xreadlines() : 
    88             if line.startswith("showpage") : 
    89                 pagecount += 1 
     92            pagecount += line.count("showpage") 
    9093            if temporary is not None :     
    9194                temporary.write(line)