blob: 7be0c045517b516e6a72b12c8e8367f59d304f4e [file] [log] [blame]
Shawn O. Pearcead3193a2009-04-18 09:54:51 -07001# Copyright (C) 2008 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Mike Frysinger8a11f6f2019-08-27 00:26:15 -040015"""Logic for tracing repo interactions.
16
17Activated via `repo --trace ...` or `REPO_TRACE=1 repo ...`.
18"""
19
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070020import sys
21import os
Mike Frysinger8a11f6f2019-08-27 00:26:15 -040022
23# Env var to implicitly turn on tracing.
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070024REPO_TRACE = 'REPO_TRACE'
25
Mike Frysinger8a11f6f2019-08-27 00:26:15 -040026_TRACE = os.environ.get(REPO_TRACE) == '1'
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070027
David Pursehouse819827a2020-02-12 15:20:19 +090028
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070029def IsTrace():
30 return _TRACE
31
David Pursehouse819827a2020-02-12 15:20:19 +090032
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070033def SetTrace():
34 global _TRACE
35 _TRACE = True
36
David Pursehouse819827a2020-02-12 15:20:19 +090037
Shawn O. Pearcead3193a2009-04-18 09:54:51 -070038def Trace(fmt, *args):
39 if IsTrace():
Sarah Owenscecd1d82012-11-01 22:59:27 -070040 print(fmt % args, file=sys.stderr)