From 8a11f6f24cecac28e7cdb3f5d0d7c83aec0df017 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 27 Aug 2019 00:26:15 -0400 Subject: rename local trace module There is a standard Python "trace" module, so having a local trace.py prevents us being able to import that. Rename the module to avoid. Change-Id: I23e29ec95a2204bb168a641323d05e76968d9b57 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234832 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- git_command.py | 2 +- git_config.py | 2 +- git_refs.py | 2 +- main.py | 4 ++-- progress.py | 2 +- project.py | 2 +- repo_trace.py | 40 ++++++++++++++++++++++++++++++++++++++++ trace.py | 36 ------------------------------------ 8 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 repo_trace.py delete mode 100644 trace.py diff --git a/git_command.py b/git_command.py index f5352ea0..67423035 100644 --- a/git_command.py +++ b/git_command.py @@ -23,7 +23,7 @@ from signal import SIGTERM from error import GitError import platform_utils -from trace import REPO_TRACE, IsTrace, Trace +from repo_trace import REPO_TRACE, IsTrace, Trace from wrapper import Wrapper GIT = 'git' diff --git a/git_config.py b/git_config.py index 9b3dd25a..1ea9c43e 100644 --- a/git_config.py +++ b/git_config.py @@ -44,7 +44,7 @@ else: from signal import SIGTERM from error import GitError, UploadError import platform_utils -from trace import Trace +from repo_trace import Trace if is_python3(): from http.client import HTTPException else: diff --git a/git_refs.py b/git_refs.py index 3187783a..98ed1e2f 100644 --- a/git_refs.py +++ b/git_refs.py @@ -15,7 +15,7 @@ # limitations under the License. import os -from trace import Trace +from repo_trace import Trace import platform_utils HEAD = 'HEAD' diff --git a/main.py b/main.py index 5c546e82..35023d52 100755 --- a/main.py +++ b/main.py @@ -45,7 +45,7 @@ except ImportError: from color import SetDefaultColoring import event_log -from trace import SetTrace +from repo_trace import SetTrace from git_command import git, GitCommand from git_config import init_ssh, close_ssh from command import InteractiveCommand @@ -84,7 +84,7 @@ global_options.add_option('--color', help='control color usage: auto, always, never') global_options.add_option('--trace', dest='trace', action='store_true', - help='trace git command execution') + help='trace git command execution (REPO_TRACE=1)') global_options.add_option('--time', dest='time', action='store_true', help='time repo command execution') diff --git a/progress.py b/progress.py index 64316959..7d4f71f1 100644 --- a/progress.py +++ b/progress.py @@ -17,7 +17,7 @@ import os import sys from time import time -from trace import IsTrace +from repo_trace import IsTrace _NOT_TTY = not os.isatty(2) diff --git a/project.py b/project.py index 5a478b41..8212e0c0 100755 --- a/project.py +++ b/project.py @@ -39,7 +39,7 @@ from error import GitError, HookError, UploadError, DownloadError from error import ManifestInvalidRevisionError from error import NoManifestException import platform_utils -from trace import IsTrace, Trace +from repo_trace import IsTrace, Trace from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M diff --git a/repo_trace.py b/repo_trace.py new file mode 100644 index 00000000..f5bc76d4 --- /dev/null +++ b/repo_trace.py @@ -0,0 +1,40 @@ +# -*- coding:utf-8 -*- +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Logic for tracing repo interactions. + +Activated via `repo --trace ...` or `REPO_TRACE=1 repo ...`. +""" + +from __future__ import print_function +import sys +import os + +# Env var to implicitly turn on tracing. +REPO_TRACE = 'REPO_TRACE' + +_TRACE = os.environ.get(REPO_TRACE) == '1' + +def IsTrace(): + return _TRACE + +def SetTrace(): + global _TRACE + _TRACE = True + +def Trace(fmt, *args): + if IsTrace(): + print(fmt % args, file=sys.stderr) diff --git a/trace.py b/trace.py deleted file mode 100644 index db514554..00000000 --- a/trace.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding:utf-8 -*- -# -# Copyright (C) 2008 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import print_function -import sys -import os -REPO_TRACE = 'REPO_TRACE' - -try: - _TRACE = os.environ[REPO_TRACE] == '1' -except KeyError: - _TRACE = False - -def IsTrace(): - return _TRACE - -def SetTrace(): - global _TRACE - _TRACE = True - -def Trace(fmt, *args): - if IsTrace(): - print(fmt % args, file=sys.stderr) -- cgit v1.2.3-54-g00ecf