77 | | MEGABYTE = 1024*1024 |
78 | | self.filter.jobdatastream.seek(0) |
79 | | child = popen2.Popen4(self.arguments) |
80 | | try : |
81 | | data = self.filter.jobdatastream.read(MEGABYTE) |
82 | | while data : |
83 | | child.tochild.write(data) |
84 | | data = self.filter.jobdatastream.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 | | |
91 | | pagecounter = None |
92 | | try : |
93 | | answer = child.fromchild.read() |
94 | | except (IOError, OSError), msg : |
95 | | msg = "%s : %s" % (self.arguments, msg) |
96 | | self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) |
97 | | else : |
98 | | lines = [l.strip() for l in answer.split("\n")] |
99 | | for i in range(len(lines)) : |
100 | | try : |
101 | | pagecounter = int(lines[i]) |
102 | | except (AttributeError, ValueError) : |
103 | | self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) |
104 | | else : |
105 | | break |
106 | | child.fromchild.close() |
107 | | |
108 | | 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 : |
113 | | if os.WIFEXITED(status) : |
114 | | status = os.WEXITSTATUS(status) |
115 | | self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) |
| 82 | if not self.arguments : |
| 83 | pagecounter = self.filter.softwareJobSize # Optimize : already computed ! |
| 84 | self.filter.logdebug("Internal software accounter said job is %s pages long." % repr(pagecounter)) |
| 85 | else : |
| 86 | MEGABYTE = 1024*1024 |
| 87 | self.filter.jobdatastream.seek(0) |
| 88 | child = popen2.Popen4(self.arguments) |
| 89 | try : |
| 90 | data = self.filter.jobdatastream.read(MEGABYTE) |
| 91 | while data : |
| 92 | child.tochild.write(data) |
| 93 | data = self.filter.jobdatastream.read(MEGABYTE) |
| 94 | child.tochild.flush() |
| 95 | child.tochild.close() |
| 96 | except (IOError, OSError), msg : |
| 97 | msg = "%s : %s" % (self.arguments, msg) |
| 98 | self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) |
117 | | if pagecounter is None : |
118 | | message = _("Unable to compute job size with accounter %s") % self.arguments |
119 | | if self.onerror == "CONTINUE" : |
120 | | self.filter.printInfo(message, "error") |
121 | | else : |
122 | | raise PyKotaAccounterError, message |
| 100 | pagecounter = None |
| 101 | try : |
| 102 | answer = child.fromchild.read() |
| 103 | except (IOError, OSError), msg : |
| 104 | msg = "%s : %s" % (self.arguments, msg) |
| 105 | self.filter.printInfo(_("Unable to compute job size with accounter %s") % msg) |
| 106 | else : |
| 107 | lines = [l.strip() for l in answer.split("\n")] |
| 108 | for i in range(len(lines)) : |
| 109 | try : |
| 110 | pagecounter = int(lines[i]) |
| 111 | except (AttributeError, ValueError) : |
| 112 | self.filter.printInfo(_("Line [%s] skipped in accounter's output. Trying again...") % lines[i]) |
| 113 | else : |
| 114 | break |
| 115 | child.fromchild.close() |
124 | | self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, repr(pagecounter))) |
| 117 | try : |
| 118 | status = child.wait() |
| 119 | except OSError, msg : |
| 120 | self.filter.printInfo(_("Problem while waiting for software accounter pid %s to exit : %s") % (child.pid, msg)) |
| 121 | else : |
| 122 | if os.WIFEXITED(status) : |
| 123 | status = os.WEXITSTATUS(status) |
| 124 | self.filter.printInfo(_("Software accounter %s exit code is %s") % (self.arguments, str(status))) |
| 125 | |
| 126 | if pagecounter is None : |
| 127 | message = _("Unable to compute job size with accounter %s") % self.arguments |
| 128 | if self.onerror == "CONTINUE" : |
| 129 | self.filter.printInfo(message, "error") |
| 130 | else : |
| 131 | raise PyKotaAccounterError, message |
| 132 | self.filter.logdebug("Software accounter %s said job is %s pages long." % (self.arguments, repr(pagecounter))) |
| 133 | |