diff options
| author | Mike Frysinger <vapier@google.com> | 2020-02-12 09:39:23 -0500 |
|---|---|---|
| committer | David Pursehouse <dpursehouse@collab.net> | 2020-02-13 07:02:07 +0000 |
| commit | 6fb0cb5c80a4b0f229aa91ece02d4ba05d133a84 (patch) | |
| tree | 036021778f5b715c15230f3b6cc116b2c50a5b36 | |
| parent | 62285d22c106b0e96cacf21845fb77cabb361812 (diff) | |
| download | git-repo-6fb0cb5c80a4b0f229aa91ece02d4ba05d133a84.tar.gz | |
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>
| -rwxr-xr-x | repo | 24 |
1 files changed, 24 insertions, 0 deletions
| @@ -17,8 +17,29 @@ import subprocess | |||
| 17 | import sys | 17 | import sys |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | # Keep basic logic in sync with repo_trace.py. | ||
| 21 | class Trace(object): | ||
| 22 | """Trace helper logic.""" | ||
| 23 | |||
| 24 | REPO_TRACE = 'REPO_TRACE' | ||
| 25 | |||
| 26 | def __init__(self): | ||
| 27 | self.set(os.environ.get(self.REPO_TRACE) == '1') | ||
| 28 | |||
| 29 | def set(self, value): | ||
| 30 | self.enabled = bool(value) | ||
| 31 | |||
| 32 | def print(self, *args, **kwargs): | ||
| 33 | if self.enabled: | ||
| 34 | print(*args, **kwargs) | ||
| 35 | |||
| 36 | |||
| 37 | trace = Trace() | ||
| 38 | |||
| 39 | |||
| 20 | def exec_command(cmd): | 40 | def exec_command(cmd): |
| 21 | """Execute |cmd| or return None on failure.""" | 41 | """Execute |cmd| or return None on failure.""" |
| 42 | trace.print(':', ' '.join(cmd)) | ||
| 22 | try: | 43 | try: |
| 23 | if platform.system() == 'Windows': | 44 | if platform.system() == 'Windows': |
| 24 | ret = subprocess.call(cmd) | 45 | ret = subprocess.call(cmd) |
| @@ -309,6 +330,7 @@ def run_command(cmd, **kwargs): | |||
| 309 | stdout = stdout.decode('utf-8') | 330 | stdout = stdout.decode('utf-8') |
| 310 | if stderr is not None: | 331 | if stderr is not None: |
| 311 | stderr = stderr.decode('utf-8') | 332 | stderr = stderr.decode('utf-8') |
| 333 | trace.print(':', ' '.join(cmd)) | ||
| 312 | ret = RunResult(proc.returncode, stdout, stderr) | 334 | ret = RunResult(proc.returncode, stdout, stderr) |
| 313 | 335 | ||
| 314 | # If things failed, print useful debugging output. | 336 | # If things failed, print useful debugging output. |
| @@ -810,6 +832,8 @@ def _ParseArguments(args): | |||
| 810 | opt.help = True | 832 | opt.help = True |
| 811 | elif a == '--version': | 833 | elif a == '--version': |
| 812 | opt.version = True | 834 | opt.version = True |
| 835 | elif a == '--trace': | ||
| 836 | trace.set(True) | ||
| 813 | elif not a.startswith('-'): | 837 | elif not a.startswith('-'): |
| 814 | cmd = a | 838 | cmd = a |
| 815 | arg = args[i + 1:] | 839 | arg = args[i + 1:] |
