Commit d87b764e authored by Michael Achenbach's avatar Michael Achenbach Committed by V8 LUCI CQ

[infra] Migrate auto-roller commands to Python3

Another encoding fix and test coverage for it.

No-Try: true
Bug: chromium:1292013
Change-Id: Id54f505848f93b4869710156fa77ad2e258c5dd6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3447905Reviewed-by: 's avatarLiviu Rau <liviurau@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79007}
parent d01a024c
......@@ -76,6 +76,10 @@ new_path = path_to_depot_tools + os.pathsep + os.environ.get('PATH')
os.environ['PATH'] = new_path
def maybe_decode(obj):
return obj.decode('utf-8') if PYTHON3 else obj
def TextToFile(text, file_name):
with open(file_name, "w") as f:
f.write(text)
......@@ -112,7 +116,7 @@ def Command(cmd, args="", prefix="", pipe=True, cwd=None):
sys.stdout.flush()
try:
if pipe:
return subprocess.check_output(cmd_line, shell=True, cwd=cwd)
return maybe_decode(subprocess.check_output(cmd_line, shell=True, cwd=cwd))
else:
return subprocess.check_call(cmd_line, shell=True, cwd=cwd)
except subprocess.CalledProcessError:
......
......@@ -29,6 +29,7 @@
# for py2/py3 compatibility
from __future__ import print_function
import json
import os
import shutil
import tempfile
......@@ -93,6 +94,10 @@ class ToplevelTest(unittest.TestCase):
]
self.assertEquals(expected, NormalizeVersionTags(input))
def testCommand(self):
"""Ensure json can decode the output of commands."""
json.dumps(Command('ls', pipe=True))
def Cmd(*args, **kwargs):
"""Convenience function returning a shell command test expectation."""
......
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