2009-04-18 16:54:51 +00:00
|
|
|
# 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.
|
|
|
|
|
2019-08-27 04:26:15 +00:00
|
|
|
"""Logic for tracing repo interactions.
|
|
|
|
|
|
|
|
Activated via `repo --trace ...` or `REPO_TRACE=1 repo ...`.
|
|
|
|
"""
|
|
|
|
|
2009-04-18 16:54:51 +00:00
|
|
|
import sys
|
|
|
|
import os
|
2019-08-27 04:26:15 +00:00
|
|
|
|
|
|
|
# Env var to implicitly turn on tracing.
|
2009-04-18 16:54:51 +00:00
|
|
|
REPO_TRACE = 'REPO_TRACE'
|
|
|
|
|
2022-11-08 00:54:56 +00:00
|
|
|
_TRACE = os.environ.get(REPO_TRACE) == '1'
|
2009-04-18 16:54:51 +00:00
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2009-04-18 16:54:51 +00:00
|
|
|
def IsTrace():
|
|
|
|
return _TRACE
|
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2009-04-18 16:54:51 +00:00
|
|
|
def SetTrace():
|
|
|
|
global _TRACE
|
|
|
|
_TRACE = True
|
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2022-11-08 00:54:56 +00:00
|
|
|
def Trace(fmt, *args):
|
|
|
|
if IsTrace():
|
|
|
|
print(fmt % args, file=sys.stderr)
|