Revision c04bc777 scripts/gnt-job
b/scripts/gnt-job | ||
---|---|---|
200 | 200 |
@return: the desired exit code |
201 | 201 |
|
202 | 202 |
""" |
203 |
def format(level, text): |
|
203 |
def format_msg(level, text):
|
|
204 | 204 |
"""Display the text indented.""" |
205 | 205 |
ToStdout("%s%s", " " * level, text) |
206 | 206 |
|
... | ... | |
222 | 222 |
|
223 | 223 |
for idx, entry in enumerate(result): |
224 | 224 |
if not first: |
225 |
format(0, "") |
|
225 |
format_msg(0, "")
|
|
226 | 226 |
else: |
227 | 227 |
first = False |
228 | 228 |
|
229 | 229 |
if entry is None: |
230 | 230 |
if idx <= len(args): |
231 |
format(0, "Job ID %s not found" % args[idx]) |
|
231 |
format_msg(0, "Job ID %s not found" % args[idx])
|
|
232 | 232 |
else: |
233 | 233 |
# this should not happen, when we don't pass args it will be a |
234 | 234 |
# valid job returned |
235 |
format(0, "Job ID requested as argument %s not found" % (idx + 1)) |
|
235 |
format_msg(0, "Job ID requested as argument %s not found" % (idx + 1))
|
|
236 | 236 |
continue |
237 | 237 |
|
238 | 238 |
(job_id, status, ops, opresult, opstatus, oplog, |
239 | 239 |
opstart, opexec, opend, recv_ts, start_ts, end_ts) = entry |
240 |
format(0, "Job ID: %s" % job_id) |
|
240 |
format_msg(0, "Job ID: %s" % job_id)
|
|
241 | 241 |
if status in _USER_JOB_STATUS: |
242 | 242 |
status = _USER_JOB_STATUS[status] |
243 | 243 |
else: |
244 | 244 |
raise errors.ProgrammerError("Unknown job status code '%s'" % status) |
245 | 245 |
|
246 |
format(1, "Status: %s" % status) |
|
246 |
format_msg(1, "Status: %s" % status)
|
|
247 | 247 |
|
248 | 248 |
if recv_ts is not None: |
249 |
format(1, "Received: %s" % FormatTimestamp(recv_ts)) |
|
249 |
format_msg(1, "Received: %s" % FormatTimestamp(recv_ts))
|
|
250 | 250 |
else: |
251 |
format(1, "Missing received timestamp (%s)" % str(recv_ts)) |
|
251 |
format_msg(1, "Missing received timestamp (%s)" % str(recv_ts))
|
|
252 | 252 |
|
253 | 253 |
if start_ts is not None: |
254 | 254 |
if recv_ts is not None: |
... | ... | |
256 | 256 |
delta = " (delta %.6fs)" % d1 |
257 | 257 |
else: |
258 | 258 |
delta = "" |
259 |
format(1, "Processing start: %s%s" % (FormatTimestamp(start_ts), delta)) |
|
259 |
format_msg(1, "Processing start: %s%s" % |
|
260 |
(FormatTimestamp(start_ts), delta)) |
|
260 | 261 |
else: |
261 |
format(1, "Processing start: unknown (%s)" % str(start_ts)) |
|
262 |
format_msg(1, "Processing start: unknown (%s)" % str(start_ts))
|
|
262 | 263 |
|
263 | 264 |
if end_ts is not None: |
264 | 265 |
if start_ts is not None: |
... | ... | |
266 | 267 |
delta = " (delta %.6fs)" % d2 |
267 | 268 |
else: |
268 | 269 |
delta = "" |
269 |
format(1, "Processing end: %s%s" % (FormatTimestamp(end_ts), delta)) |
|
270 |
format_msg(1, "Processing end: %s%s" % |
|
271 |
(FormatTimestamp(end_ts), delta)) |
|
270 | 272 |
else: |
271 |
format(1, "Processing end: unknown (%s)" % str(end_ts)) |
|
273 |
format_msg(1, "Processing end: unknown (%s)" % str(end_ts))
|
|
272 | 274 |
|
273 | 275 |
if end_ts is not None and recv_ts is not None: |
274 | 276 |
d3 = end_ts[0] - recv_ts[0] + (end_ts[1] - recv_ts[1]) / 1000000.0 |
275 |
format(1, "Total processing time: %.6f seconds" % d3) |
|
277 |
format_msg(1, "Total processing time: %.6f seconds" % d3)
|
|
276 | 278 |
else: |
277 |
format(1, "Total processing time: N/A") |
|
278 |
format(1, "Opcodes:") |
|
279 |
format_msg(1, "Total processing time: N/A")
|
|
280 |
format_msg(1, "Opcodes:")
|
|
279 | 281 |
for (opcode, result, status, log, s_ts, x_ts, e_ts) in \ |
280 | 282 |
zip(ops, opresult, opstatus, oplog, opstart, opexec, opend): |
281 |
format(2, "%s" % opcode["OP_ID"]) |
|
282 |
format(3, "Status: %s" % status) |
|
283 |
format_msg(2, "%s" % opcode["OP_ID"])
|
|
284 |
format_msg(3, "Status: %s" % status)
|
|
283 | 285 |
if isinstance(s_ts, (tuple, list)): |
284 |
format(3, "Processing start: %s" % FormatTimestamp(s_ts)) |
|
286 |
format_msg(3, "Processing start: %s" % FormatTimestamp(s_ts))
|
|
285 | 287 |
else: |
286 |
format(3, "No processing start time") |
|
288 |
format_msg(3, "No processing start time")
|
|
287 | 289 |
if isinstance(x_ts, (tuple, list)): |
288 |
format(3, "Execution start: %s" % FormatTimestamp(x_ts)) |
|
290 |
format_msg(3, "Execution start: %s" % FormatTimestamp(x_ts))
|
|
289 | 291 |
else: |
290 |
format(3, "No execution start time") |
|
292 |
format_msg(3, "No execution start time")
|
|
291 | 293 |
if isinstance(e_ts, (tuple, list)): |
292 |
format(3, "Processing end: %s" % FormatTimestamp(e_ts)) |
|
294 |
format_msg(3, "Processing end: %s" % FormatTimestamp(e_ts))
|
|
293 | 295 |
else: |
294 |
format(3, "No processing end time") |
|
295 |
format(3, "Input fields:") |
|
296 |
format_msg(3, "No processing end time")
|
|
297 |
format_msg(3, "Input fields:")
|
|
296 | 298 |
for key, val in opcode.iteritems(): |
297 | 299 |
if key == "OP_ID": |
298 | 300 |
continue |
299 | 301 |
if isinstance(val, (tuple, list)): |
300 | 302 |
val = ",".join([str(item) for item in val]) |
301 |
format(4, "%s: %s" % (key, val)) |
|
303 |
format_msg(4, "%s: %s" % (key, val))
|
|
302 | 304 |
if result is None: |
303 |
format(3, "No output data") |
|
305 |
format_msg(3, "No output data")
|
|
304 | 306 |
elif isinstance(result, (tuple, list)): |
305 | 307 |
if not result: |
306 |
format(3, "Result: empty sequence") |
|
308 |
format_msg(3, "Result: empty sequence")
|
|
307 | 309 |
else: |
308 |
format(3, "Result:") |
|
310 |
format_msg(3, "Result:")
|
|
309 | 311 |
for elem in result: |
310 |
format(4, result_helper(elem)) |
|
312 |
format_msg(4, result_helper(elem))
|
|
311 | 313 |
elif isinstance(result, dict): |
312 | 314 |
if not result: |
313 |
format(3, "Result: empty dictionary") |
|
315 |
format_msg(3, "Result: empty dictionary")
|
|
314 | 316 |
else: |
315 | 317 |
for key, val in result.iteritems(): |
316 |
format(4, "%s: %s" % (key, result_helper(val))) |
|
318 |
format_msg(4, "%s: %s" % (key, result_helper(val)))
|
|
317 | 319 |
else: |
318 |
format(3, "Result: %s" % result) |
|
319 |
format(3, "Execution log:") |
|
320 |
format_msg(3, "Result: %s" % result)
|
|
321 |
format_msg(3, "Execution log:")
|
|
320 | 322 |
for serial, log_ts, log_type, log_msg in log: |
321 | 323 |
time_txt = FormatTimestamp(log_ts) |
322 | 324 |
encoded = utils.SafeEncode(log_msg) |
323 |
format(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded)) |
|
325 |
format_msg(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
|
|
324 | 326 |
return 0 |
325 | 327 |
|
326 | 328 |
|
Also available in: Unified diff