Changeset 1000 for pykota/trunk/pykota/accounters
- Timestamp:
- 05/28/03 01:00:21 (21 years ago)
- Location:
- pykota/trunk/pykota/accounters
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounters/external.py
r995 r1000 21 21 # 22 22 # $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 # 23 27 # Revision 1.2 2003/05/13 13:54:20 jalet 24 28 # Better handling of broken pipes … … 42 46 The command must print the job size on its standard output and exit successfully. 43 47 """ 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 46 50 47 51 # get last job information for this printer … … 81 85 82 86 # launches external accounter 87 infilename = tempfile.mktemp() 88 outfilename = tempfile.mktemp() 89 errfilename = tempfile.mktemp() 90 83 91 try : 84 process = popen2.Popen3("%s" % self.arguments)85 86 92 # feed it with our data 93 fakeinput = open(infilename, "wb") 87 94 data = infile.read(256*1024) 88 95 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) 91 99 data = infile.read(256*1024) 92 process.tochild.close()100 fakeinput.close() 93 101 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) 96 108 97 109 # 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) : 99 111 # tries to extract the job size from the external accounter's 100 112 # standard output 113 childoutput = open(outfilename, "r") 101 114 try : 102 pagecount = int( process.fromchild.readline().strip())115 pagecount = int(childoutput.readline().strip()) 103 116 except (AttributeError, ValueError) : 104 117 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 105 118 pagecount = 0 119 childoutput.close() 106 120 else : 107 121 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 108 122 pagecount = 0 109 process.fromchild.close() 123 os.remove(infilename) 124 os.remove(outfilename) 125 os.remove(errfilename) 110 126 except IOError, msg : 127 # TODO : temporary files may remain on the filesystem... 111 128 msg = "%s : %s" % (self.arguments, msg) 112 129 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % msg) -
pykota/trunk/pykota/accounters/stupid.py
r977 r1000 21 21 # 22 22 # $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 # 23 27 # Revision 1.2 2003/04/30 13:40:47 jalet 24 28 # Small fix … … 44 48 45 49 # get the job size 46 jobsize = self.getJobSize() 50 jobsize = self.getJobSize() * self.filter.copies 47 51 48 52 # get last job information for this printer … … 86 90 pagecount = 0 87 91 for line in infile.xreadlines() : 88 if line.startswith("showpage") : 89 pagecount += 1 92 pagecount += line.count("showpage") 90 93 if temporary is not None : 91 94 temporary.write(line)