paycheck: Small improvements to the block tracer utility.

This prepends the current block number to the output, simplifies some
logic, and tightens argument validation in the command-line parser.

BUG=None
TEST=paycheck -B/-b works.

Change-Id: I90d5cdf721612cdd12e49f4e4181849fc699807f
Reviewed-on: https://chromium-review.googlesource.com/286547
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/host/lib/update_payload/block_tracer.py b/host/lib/update_payload/block_tracer.py
index e7a9d27..f222b21 100644
--- a/host/lib/update_payload/block_tracer.py
+++ b/host/lib/update_payload/block_tracer.py
@@ -14,6 +14,8 @@
 
 """
 
+from __future__ import print_function
+
 import common
 
 
@@ -50,7 +52,6 @@
       trace_out_file: a file object to dump the trace to
       operations: the sequence of operations
       base_name: name of the operation sequence
-
     """
     # Traverse operations backwards.
     for op, op_name in common.OperationIter(operations, base_name,
@@ -68,8 +69,9 @@
           else:
             total_block_offset += block - dst_ex.start_block
             trace_out_file.write(
-                '%s: found %s (total block offset: %d)\n' %
-                (dst_ex_name, common.FormatExtent(dst_ex), total_block_offset))
+                '%d: %s: found %s (total block offset: %d)\n' %
+                (block, dst_ex_name, common.FormatExtent(dst_ex),
+                 total_block_offset))
             found = True
             break
 
@@ -100,13 +102,12 @@
       skip: the number of first origin mappings to skip
       trace_out_file: file object to dump the trace to
       is_kernel: trace through kernel (True) or rootfs (False) operations
-
     """
     if is_kernel:
-      self._TraceBlock(block, skip, trace_out_file,
-                       self.payload.manifest.kernel_install_operations,
-                       'kernel_install_operations')
+      operations = self.payload.manifest.kernel_install_operations
+      base_name = 'kernel_install_operations'
     else:
-      self._TraceBlock(block, skip, trace_out_file,
-                       self.payload.manifest.install_operations,
-                       'install_operations')
+      operations = self.payload.manifest.install_operations
+      base_name = 'install_operations'
+
+    self._TraceBlock(block, skip, trace_out_file, operations, base_name)
diff --git a/host/paycheck.py b/host/paycheck.py
index 5290e9d..0195f53 100755
--- a/host/paycheck.py
+++ b/host/paycheck.py
@@ -117,7 +117,7 @@
         parser.error('invalid argument to --disabled_tests: %s' % test)
 
   # Ensure consistent use of block tracing options.
-  do_block_trace = opts.root_block or opts.kern_block
+  do_block_trace = not (opts.root_block is None and opts.kern_block is None)
   if opts.skip and not do_block_trace:
     parser.error('--skip must be used with either --root-block or --kern-block')