Changeset 1680 for pykota/trunk/pykota/accounters/hardware.py
- Timestamp:
- 08/26/04 00:34:39 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounters/hardware.py
r1624 r1680 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2004/08/25 22:34:39 jalet 25 # Now both software and hardware accounting raise an exception when no valid 26 # result can be extracted from the subprocess' output. 27 # Hardware accounting now reads subprocess' output until an integer is read 28 # or data is exhausted : it now behaves just like software accounting in this 29 # aspect. 30 # 24 31 # Revision 1.8 2004/07/22 22:41:48 jalet 25 32 # Hardware accounting for LPRng should be OK now. UNTESTED. … … 122 129 raise PyKotaAccounterError, _("Unknown printer address in HARDWARE(%s) for printer %s") % (commandline, self.filter.printername) 123 130 self.filter.printInfo(_("Launching HARDWARE(%s)...") % commandline) 124 error = 1125 131 pagecounter = None 126 132 child = popen2.Popen4(commandline) 127 133 try : 128 line = child.fromchild.readline() 129 pagecounter = int(line.strip()) 130 except ValueError : 131 self.filter.printInfo(_("Incorrect answer : %s") % repr(line), "error") 134 answer = child.fromchild.read() 132 135 except IOError : 133 136 # we were interrupted by a signal, certainely a SIGTERM … … 139 142 self.filter.printInfo(_("SIGTERM was sent to hardware accounter %s (pid: %s)") % (commandline, child.pid)) 140 143 else : 141 error = 0 144 lines = [l.strip() for l in answer.split("\n")] 145 for i in range(len(lines)) : 146 try : 147 pagecounter = int(lines[i]) 148 except (AttributeError, ValueError) : 149 self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) 150 else : 151 break 142 152 child.fromchild.close() 143 153 child.tochild.close() … … 146 156 except OSError, msg : 147 157 self.filter.logdebug("Error while waiting for hardware accounter pid %s : %s" % (child.pid, msg)) 148 error = 1 149 if (not error) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 158 if (pagecounter is not None) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 150 159 return pagecounter 151 160 else :