Use new API for cmd output

The new API has been available for a while, and the old API is removed in
the new chromite. This change should work on all milestones.

BUG=b/257271340
TEST=`repo upload`
RELEASE_NOTE=None

Change-Id: I4eb60542b18fa8de8e096f8a71a09743365fa1bf
Reviewed-on: https://cos-review.googlesource.com/c/cos/repohooks/+/39513
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Reviewed-by: He Gao <hegao@google.com>
Reviewed-by: Dexter Rivera <riverade@google.com>
diff --git a/pre-upload.py b/pre-upload.py
index 3062d7e..b3944cf 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -20,12 +20,15 @@
 import json
 import os
 import re
-import sys
 import stat
 import subprocess
+import sys
 
-from errors import (VerifyException, HookFailure, PrintErrorForProject,
-                    PrintErrorsForCommit)
+from errors import HookFailure
+from errors import PrintErrorForProject
+from errors import PrintErrorsForCommit
+from errors import VerifyException
+
 
 if __name__ in ('__builtin__', 'builtins'):
   # If repo imports us, the __name__ will be __builtin__, and the cwd will be in
@@ -171,7 +174,7 @@
   result = cros_build_lib.run(cmd, **kwargs)
   # NB: We decode this directly rather than through kwargs as our tests rely
   # on this post-processing behavior currently.
-  return result.output.decode('utf-8', 'replace')
+  return result.stdout.decode('utf-8', 'replace')
 
 
 def _get_hooks_dir():
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index f532cac..eda2f6c 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -15,6 +15,7 @@
 
 import errors
 
+
 # pylint: disable=W0212
 # We access private members of the pre_upload module all over the place.
 
@@ -57,8 +58,8 @@
 
   def _run(self, content):
     """Helper for round tripping through _run_command."""
-    self.rc_mock.return_value = cros_build_lib.CommandResult(
-        output=content, returncode=0)
+    self.rc_mock.return_value = cros_build_lib.CompletedProcess(
+        stdout=content, returncode=0)
     return pre_upload._run_command([])
 
   def testEmpty(self):
@@ -1062,7 +1063,7 @@
 //
 """,
         u"""//
-// Copyright {} Google LLC
+// Copyright %s Google LLC
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -1076,7 +1077,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
-""".format(year),
+""" % year,
     )
     want_error = (True, False)
     def fake_get_affected_files(_, relative, include_adds=True):
@@ -1152,7 +1153,7 @@
     """Accept old header styles."""
     year = datetime.datetime.now().year
     header = u"""#
-# Copyright {} Google LLC
+# Copyright %s Google LLC
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -1163,7 +1164,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU General Public License for more details.
 #
-""".format(year)
+""" % year
 
     def fake_get_affected_files(_, relative, include_adds=True):
       _ = relative
@@ -1221,7 +1222,7 @@
 #
 """,
         u"""#
-# Copyright {} Google LLC
+# Copyright %s Google LLC
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -1232,7 +1233,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 # GNU General Public License for more details.
 #
-""".format(year),
+""" % year,
     )
     want_error = (True, False)
     def fake_get_affected_files(_, relative, include_adds=True):
@@ -2079,7 +2080,7 @@
   def testNoGitDir(self):
     """We should die when run on a non-git dir."""
     self.assertRaises(pre_upload.BadInvocation, pre_upload.direct_main,
-                      ['--dir', self.tempdir])
+                      ['--dir', str(self.tempdir)])
 
   def testNoDir(self):
     """We should die when run on a missing dir."""