Update utils_py to use chromite.lib.cros_build_lib.

BUG=chromium-os:24660, chromium-os:21287
TEST=Trybot runs. Unit tests. Pylint.
TEST=Verify both successful and failed VMTest runs behave correctly.
Change-Id: I2408761f1e00437a4f9e0d212a67ddd89634a2c7
Reviewed-on: https://gerrit.chromium.org/gerrit/40311
Tested-by: David James <davidjames@chromium.org>
Reviewed-by: Brian Harring <ferringb@chromium.org>
Commit-Queue: David James <davidjames@chromium.org>
diff --git a/utils_py/cros_run_parallel_vm_tests.py b/utils_py/cros_run_parallel_vm_tests.py
index b0c3b53..add428c 100755
--- a/utils_py/cros_run_parallel_vm_tests.py
+++ b/utils_py/cros_run_parallel_vm_tests.py
@@ -8,13 +8,9 @@
 import optparse
 import os
 import subprocess
-import sys
 import tempfile
 
-import constants
-sys.path.append(constants.CROSUTILS_LIB_DIR)
-from cros_build_lib import Die
-from cros_build_lib import Info
+from chromite.lib import cros_build_lib
 
 
 _DEFAULT_BASE_SSH_PORT = 9322
@@ -90,11 +86,11 @@
       if self._quiet:
         args.append('--verbose=0')  # generate less output
         output = open('/dev/null', mode='w')
-        Info('Log files are in %s' % results_dir)
+        cros_build_lib.Info('Log files are in %s', results_dir)
       elif self._order_output:
         output = tempfile.NamedTemporaryFile(prefix='parallel_vm_test_')
-        Info('Piping output to %s.' % output.name)
-      Info('Running %r...' % args)
+        cros_build_lib.Info('Piping output to %s.', output.name)
+      cros_build_lib.Info('Running %r...', args)
       proc = subprocess.Popen(args, stdout=output, stderr=output)
       test_info = { 'test': test,
                     'proc': proc,
@@ -122,18 +118,18 @@
       output = test_info['output']
       if output and not self._quiet:
         test = test_info['test']
-        Info('------ START %s:%s ------' % (test, output.name))
+        cros_build_lib.Info('------ START %s:%s ------', test, output.name)
         output.seek(0)
         for line in output:
           print line,
-        Info('------ END %s:%s ------' % (test, output.name))
+        cros_build_lib.Info('------ END %s:%s ------', test, output.name)
     return failed_tests
 
   def Run(self):
     """Runs the tests in |self._tests| on separate VMs in parallel."""
     spawned_tests = self._SpawnTests()
     failed_tests = self._WaitForCompletion(spawned_tests)
-    if failed_tests: Die('Tests failed: %r' % failed_tests)
+    if failed_tests: cros_build_lib.Die('Tests failed: %r', failed_tests)
 
 
 def main():
@@ -164,12 +160,12 @@
 
   if not args:
     parser.print_help()
-    Die('no tests provided')
+    cros_build_lib.Die('no tests provided')
 
   if options.quiet:
     options.order_output = False
     if not options.results_dir_root:
-      Die('--quiet requires --results_dir_root')
+      cros_build_lib.Die('--quiet requires --results_dir_root')
   runner = ParallelTestRunner(args, options.base_ssh_port, options.board,
                               options.image_path, options.order_output,
                               options.quiet, options.results_dir_root)
diff --git a/utils_py/generate_test_report.py b/utils_py/generate_test_report.py
index 9433b72..27f85cc 100755
--- a/utils_py/generate_test_report.py
+++ b/utils_py/generate_test_report.py
@@ -18,9 +18,8 @@
 import re
 import sys
 
-import constants
-sys.path.append(constants.CROSUTILS_LIB_DIR)
-from cros_build_lib import Color, Die, Warning
+from chromite.lib import cros_build_lib
+from chromite.lib import terminal
 
 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
 
@@ -362,7 +361,7 @@
   def __init__(self, options, args):
     self._options = options
     self._args = args
-    self._color = Color(options.color)
+    self._color = terminal.Color(options.color)
     self._results = []
 
   def _CollectAllResults(self):
@@ -379,11 +378,11 @@
                                 self._options.whitelist_chrome_crashes)
     for resdir in self._args:
       if not os.path.isdir(resdir):
-        Die('\'%s\' does not exist' % resdir)
+        cros_build_lib.Die('%r does not exist', resdir)
       self._results.extend(collector.RecursivelyCollectResults(resdir))
 
     if not self._results:
-      Die('no test directories found')
+      cros_build_lib.Die('no test directories found')
 
   def _GenStatusString(self, status):
     """Given a bool indicating success or failure, return the right string.
@@ -492,7 +491,7 @@
       else:
         key_entry = dict_key.ljust(width - self._KEYVAL_INDENT)
         key_entry = key_entry.rjust(width)
-      value_entry = self._color.Color(Color.BOLD, result_dict[dict_key])
+      value_entry = self._color.Color(self._color.BOLD, result_dict[dict_key])
       self._PrintEntries([test_entry, key_entry, value_entry])
 
   def _GetSortedTests(self):
@@ -537,10 +536,10 @@
 
       status_entry = self._GenStatusString(result['status'])
       if result['status']:
-        color = Color.GREEN
+        color = self._color.GREEN
         tests_pass += 1
       else:
-        color = Color.RED
+        color = self._color.RED
 
       test_entries = [test_entry, self._color.Color(color, status_entry)]
 
@@ -581,21 +580,22 @@
       total_tests = len(tests)
       percent_pass = 100 * tests_pass / total_tests
       pass_str = '%d/%d (%d%%)' % (tests_pass, total_tests, percent_pass)
-      print 'Total PASS: ' + self._color.Color(Color.BOLD, pass_str)
+      print 'Total PASS: ' + self._color.Color(self._color.BOLD, pass_str)
 
     if self._options.crash_detection:
       print ''
       if crashes:
-        print self._color.Color(Color.RED, 'Crashes detected during testing:')
+        print self._color.Color(self._color.RED,
+                                'Crashes detected during testing:')
         self._PrintDashLine(width)
 
         for crash_name, crashed_tests in sorted(crashes.iteritems()):
-          print self._color.Color(Color.RED, crash_name)
+          print self._color.Color(self._color.RED, crash_name)
           for crashed_test in crashed_tests:
             print self._Indent(crashed_test)
 
         self._PrintDashLine(width)
-        print 'Total unique crashes: ' + self._color.Color(Color.BOLD,
+        print 'Total unique crashes: ' + self._color.Color(self._color.BOLD,
                                                            str(len(crashes)))
 
       # Sometimes the builders exit before these buffers are flushed.
@@ -659,7 +659,7 @@
 
   if not args:
     parser.print_help()
-    Die('no result directories provided')
+    cros_build_lib.Die('no result directories provided')
 
   if options.csv and (options.print_debug or options.crash_detection):
     Warning('Forcing --no-debug --no-crash-detection')