mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
repo: add trace support to the launcher
Now that we have a central run_command point, we can easily add tracing support to the launcher script. Change-Id: I9e0335c196cafd6263ff501925abfe835f036c5e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254755 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
parent
62285d22c1
commit
6fb0cb5c80
24
repo
24
repo
@ -17,8 +17,29 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
# Keep basic logic in sync with repo_trace.py.
|
||||||
|
class Trace(object):
|
||||||
|
"""Trace helper logic."""
|
||||||
|
|
||||||
|
REPO_TRACE = 'REPO_TRACE'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.set(os.environ.get(self.REPO_TRACE) == '1')
|
||||||
|
|
||||||
|
def set(self, value):
|
||||||
|
self.enabled = bool(value)
|
||||||
|
|
||||||
|
def print(self, *args, **kwargs):
|
||||||
|
if self.enabled:
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
trace = Trace()
|
||||||
|
|
||||||
|
|
||||||
def exec_command(cmd):
|
def exec_command(cmd):
|
||||||
"""Execute |cmd| or return None on failure."""
|
"""Execute |cmd| or return None on failure."""
|
||||||
|
trace.print(':', ' '.join(cmd))
|
||||||
try:
|
try:
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
ret = subprocess.call(cmd)
|
ret = subprocess.call(cmd)
|
||||||
@ -309,6 +330,7 @@ def run_command(cmd, **kwargs):
|
|||||||
stdout = stdout.decode('utf-8')
|
stdout = stdout.decode('utf-8')
|
||||||
if stderr is not None:
|
if stderr is not None:
|
||||||
stderr = stderr.decode('utf-8')
|
stderr = stderr.decode('utf-8')
|
||||||
|
trace.print(':', ' '.join(cmd))
|
||||||
ret = RunResult(proc.returncode, stdout, stderr)
|
ret = RunResult(proc.returncode, stdout, stderr)
|
||||||
|
|
||||||
# If things failed, print useful debugging output.
|
# If things failed, print useful debugging output.
|
||||||
@ -810,6 +832,8 @@ def _ParseArguments(args):
|
|||||||
opt.help = True
|
opt.help = True
|
||||||
elif a == '--version':
|
elif a == '--version':
|
||||||
opt.version = True
|
opt.version = True
|
||||||
|
elif a == '--trace':
|
||||||
|
trace.set(True)
|
||||||
elif not a.startswith('-'):
|
elif not a.startswith('-'):
|
||||||
cmd = a
|
cmd = a
|
||||||
arg = args[i + 1:]
|
arg = args[i + 1:]
|
||||||
|
Loading…
Reference in New Issue
Block a user