Commit c04bc777 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix warnings with Python 2.6



'format' is a new built-in function, and 'bytes' is a new builtin type.
We rename this to make pylint happy (and remove potential bugs).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 035f40fc
...@@ -959,17 +959,17 @@ class BaseDRBD(BlockDev): # pylint: disable-msg=W0223 ...@@ -959,17 +959,17 @@ class BaseDRBD(BlockDev): # pylint: disable-msg=W0223
sectors = int(result.stdout) sectors = int(result.stdout)
except (TypeError, ValueError): except (TypeError, ValueError):
_ThrowError("Invalid output from blockdev: '%s'", result.stdout) _ThrowError("Invalid output from blockdev: '%s'", result.stdout)
bytes = sectors * 512 num_bytes = sectors * 512
if bytes < 128 * 1024 * 1024: # less than 128MiB if num_bytes < 128 * 1024 * 1024: # less than 128MiB
_ThrowError("Meta device too small (%.2fMib)", (bytes / 1024 / 1024)) _ThrowError("Meta device too small (%.2fMib)", (num_bytes / 1024 / 1024))
# the maximum *valid* size of the meta device when living on top # the maximum *valid* size of the meta device when living on top
# of LVM is hard to compute: it depends on the number of stripes # of LVM is hard to compute: it depends on the number of stripes
# and the PE size; e.g. a 2-stripe, 64MB PE will result in a 128MB # and the PE size; e.g. a 2-stripe, 64MB PE will result in a 128MB
# (normal size), but an eight-stripe 128MB PE will result in a 1GB # (normal size), but an eight-stripe 128MB PE will result in a 1GB
# size meta device; as such, we restrict it to 1GB (a little bit # size meta device; as such, we restrict it to 1GB (a little bit
# too generous, but making assumptions about PE size is hard) # too generous, but making assumptions about PE size is hard)
if bytes > 1024 * 1024 * 1024: if num_bytes > 1024 * 1024 * 1024:
_ThrowError("Meta device too big (%.2fMiB)", (bytes / 1024 / 1024)) _ThrowError("Meta device too big (%.2fMiB)", (num_bytes / 1024 / 1024))
def Rename(self, new_id): def Rename(self, new_id):
"""Rename a device. """Rename a device.
......
...@@ -2000,9 +2000,9 @@ def GenerateTable(headers, fields, separator, data, ...@@ -2000,9 +2000,9 @@ def GenerateTable(headers, fields, separator, data,
if separator is None: if separator is None:
mlens = [0 for name in fields] mlens = [0 for name in fields]
format = ' '.join(format_fields) format_str = ' '.join(format_fields)
else: else:
format = separator.replace("%", "%%").join(format_fields) format_str = separator.replace("%", "%%").join(format_fields)
for row in data: for row in data:
if row is None: if row is None:
...@@ -2028,7 +2028,7 @@ def GenerateTable(headers, fields, separator, data, ...@@ -2028,7 +2028,7 @@ def GenerateTable(headers, fields, separator, data,
mlens[idx] = max(mlens[idx], len(hdr)) mlens[idx] = max(mlens[idx], len(hdr))
args.append(mlens[idx]) args.append(mlens[idx])
args.append(hdr) args.append(hdr)
result.append(format % tuple(args)) result.append(format_str % tuple(args))
if separator is None: if separator is None:
assert len(mlens) == len(fields) assert len(mlens) == len(fields)
...@@ -2044,7 +2044,7 @@ def GenerateTable(headers, fields, separator, data, ...@@ -2044,7 +2044,7 @@ def GenerateTable(headers, fields, separator, data,
if separator is None: if separator is None:
args.append(mlens[idx]) args.append(mlens[idx])
args.append(line[idx]) args.append(line[idx])
result.append(format % tuple(args)) result.append(format_str % tuple(args))
return result return result
......
...@@ -200,7 +200,7 @@ def ShowJobs(opts, args): ...@@ -200,7 +200,7 @@ def ShowJobs(opts, args):
@return: the desired exit code @return: the desired exit code
""" """
def format(level, text): def format_msg(level, text):
"""Display the text indented.""" """Display the text indented."""
ToStdout("%s%s", " " * level, text) ToStdout("%s%s", " " * level, text)
...@@ -222,33 +222,33 @@ def ShowJobs(opts, args): ...@@ -222,33 +222,33 @@ def ShowJobs(opts, args):
for idx, entry in enumerate(result): for idx, entry in enumerate(result):
if not first: if not first:
format(0, "") format_msg(0, "")
else: else:
first = False first = False
if entry is None: if entry is None:
if idx <= len(args): if idx <= len(args):
format(0, "Job ID %s not found" % args[idx]) format_msg(0, "Job ID %s not found" % args[idx])
else: else:
# this should not happen, when we don't pass args it will be a # this should not happen, when we don't pass args it will be a
# valid job returned # valid job returned
format(0, "Job ID requested as argument %s not found" % (idx + 1)) format_msg(0, "Job ID requested as argument %s not found" % (idx + 1))
continue continue
(job_id, status, ops, opresult, opstatus, oplog, (job_id, status, ops, opresult, opstatus, oplog,
opstart, opexec, opend, recv_ts, start_ts, end_ts) = entry opstart, opexec, opend, recv_ts, start_ts, end_ts) = entry
format(0, "Job ID: %s" % job_id) format_msg(0, "Job ID: %s" % job_id)
if status in _USER_JOB_STATUS: if status in _USER_JOB_STATUS:
status = _USER_JOB_STATUS[status] status = _USER_JOB_STATUS[status]
else: else:
raise errors.ProgrammerError("Unknown job status code '%s'" % status) raise errors.ProgrammerError("Unknown job status code '%s'" % status)
format(1, "Status: %s" % status) format_msg(1, "Status: %s" % status)
if recv_ts is not None: if recv_ts is not None:
format(1, "Received: %s" % FormatTimestamp(recv_ts)) format_msg(1, "Received: %s" % FormatTimestamp(recv_ts))
else: else:
format(1, "Missing received timestamp (%s)" % str(recv_ts)) format_msg(1, "Missing received timestamp (%s)" % str(recv_ts))
if start_ts is not None: if start_ts is not None:
if recv_ts is not None: if recv_ts is not None:
...@@ -256,9 +256,10 @@ def ShowJobs(opts, args): ...@@ -256,9 +256,10 @@ def ShowJobs(opts, args):
delta = " (delta %.6fs)" % d1 delta = " (delta %.6fs)" % d1
else: else:
delta = "" delta = ""
format(1, "Processing start: %s%s" % (FormatTimestamp(start_ts), delta)) format_msg(1, "Processing start: %s%s" %
(FormatTimestamp(start_ts), delta))
else: else:
format(1, "Processing start: unknown (%s)" % str(start_ts)) format_msg(1, "Processing start: unknown (%s)" % str(start_ts))
if end_ts is not None: if end_ts is not None:
if start_ts is not None: if start_ts is not None:
...@@ -266,61 +267,62 @@ def ShowJobs(opts, args): ...@@ -266,61 +267,62 @@ def ShowJobs(opts, args):
delta = " (delta %.6fs)" % d2 delta = " (delta %.6fs)" % d2
else: else:
delta = "" delta = ""
format(1, "Processing end: %s%s" % (FormatTimestamp(end_ts), delta)) format_msg(1, "Processing end: %s%s" %
(FormatTimestamp(end_ts), delta))
else: else:
format(1, "Processing end: unknown (%s)" % str(end_ts)) format_msg(1, "Processing end: unknown (%s)" % str(end_ts))
if end_ts is not None and recv_ts is not None: if end_ts is not None and recv_ts is not None:
d3 = end_ts[0] - recv_ts[0] + (end_ts[1] - recv_ts[1]) / 1000000.0 d3 = end_ts[0] - recv_ts[0] + (end_ts[1] - recv_ts[1]) / 1000000.0
format(1, "Total processing time: %.6f seconds" % d3) format_msg(1, "Total processing time: %.6f seconds" % d3)
else: else:
format(1, "Total processing time: N/A") format_msg(1, "Total processing time: N/A")
format(1, "Opcodes:") format_msg(1, "Opcodes:")
for (opcode, result, status, log, s_ts, x_ts, e_ts) in \ for (opcode, result, status, log, s_ts, x_ts, e_ts) in \
zip(ops, opresult, opstatus, oplog, opstart, opexec, opend): zip(ops, opresult, opstatus, oplog, opstart, opexec, opend):
format(2, "%s" % opcode["OP_ID"]) format_msg(2, "%s" % opcode["OP_ID"])
format(3, "Status: %s" % status) format_msg(3, "Status: %s" % status)
if isinstance(s_ts, (tuple, list)): if isinstance(s_ts, (tuple, list)):
format(3, "Processing start: %s" % FormatTimestamp(s_ts)) format_msg(3, "Processing start: %s" % FormatTimestamp(s_ts))
else: else:
format(3, "No processing start time") format_msg(3, "No processing start time")
if isinstance(x_ts, (tuple, list)): if isinstance(x_ts, (tuple, list)):
format(3, "Execution start: %s" % FormatTimestamp(x_ts)) format_msg(3, "Execution start: %s" % FormatTimestamp(x_ts))
else: else:
format(3, "No execution start time") format_msg(3, "No execution start time")
if isinstance(e_ts, (tuple, list)): if isinstance(e_ts, (tuple, list)):
format(3, "Processing end: %s" % FormatTimestamp(e_ts)) format_msg(3, "Processing end: %s" % FormatTimestamp(e_ts))
else: else:
format(3, "No processing end time") format_msg(3, "No processing end time")
format(3, "Input fields:") format_msg(3, "Input fields:")
for key, val in opcode.iteritems(): for key, val in opcode.iteritems():
if key == "OP_ID": if key == "OP_ID":
continue continue
if isinstance(val, (tuple, list)): if isinstance(val, (tuple, list)):
val = ",".join([str(item) for item in val]) val = ",".join([str(item) for item in val])
format(4, "%s: %s" % (key, val)) format_msg(4, "%s: %s" % (key, val))
if result is None: if result is None:
format(3, "No output data") format_msg(3, "No output data")
elif isinstance(result, (tuple, list)): elif isinstance(result, (tuple, list)):
if not result: if not result:
format(3, "Result: empty sequence") format_msg(3, "Result: empty sequence")
else: else:
format(3, "Result:") format_msg(3, "Result:")
for elem in result: for elem in result:
format(4, result_helper(elem)) format_msg(4, result_helper(elem))
elif isinstance(result, dict): elif isinstance(result, dict):
if not result: if not result:
format(3, "Result: empty dictionary") format_msg(3, "Result: empty dictionary")
else: else:
for key, val in result.iteritems(): for key, val in result.iteritems():
format(4, "%s: %s" % (key, result_helper(val))) format_msg(4, "%s: %s" % (key, result_helper(val)))
else: else:
format(3, "Result: %s" % result) format_msg(3, "Result: %s" % result)
format(3, "Execution log:") format_msg(3, "Execution log:")
for serial, log_ts, log_type, log_msg in log: for serial, log_ts, log_type, log_msg in log:
time_txt = FormatTimestamp(log_ts) time_txt = FormatTimestamp(log_ts)
encoded = utils.SafeEncode(log_msg) encoded = utils.SafeEncode(log_msg)
format(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded)) format_msg(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
return 0 return 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment