diff --git a/src/tools/interop/idt/capture/config.py b/src/tools/interop/idt/capture/config.py index 6ca0b1bf4fd407..e4be4262471b2a 100644 --- a/src/tools/interop/idt/capture/config.py +++ b/src/tools/interop/idt/capture/config.py @@ -17,6 +17,4 @@ import logging -log_level = logging.INFO async_timeout = 45.0 -enable_color = True diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/analysis.py b/src/tools/interop/idt/capture/ecosystem/play_services/analysis.py index 90e7a88dd10bd3..aca67d8fa20c95 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/analysis.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/analysis.py @@ -17,9 +17,9 @@ import os -from capture.utils import log +import log from capture.utils.artifact import create_standard_log_name -from capture.utils.log import print_and_write, add_border +from log import print_and_write, add_border from capture.platform.android import Android logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py b/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py index 22997883bf7b3c..a8355e014c4e51 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py @@ -29,7 +29,7 @@ from .command_map import dumpsys, getprop from .prober import PlayServicesProber -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py index 754b8cb9367131..e1d8b2033b36bf 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py @@ -18,7 +18,7 @@ import os from capture.utils.shell import Bash -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/ecosystem/play_services_user/play_services_user.py b/src/tools/interop/idt/capture/ecosystem/play_services_user/play_services_user.py index a9e0bcce5eb55e..b36719edc21c70 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services_user/play_services_user.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services_user/play_services_user.py @@ -19,7 +19,7 @@ from capture.base import EcosystemCapture, UnsupportedCapturePlatformException from capture.utils.artifact import create_standard_log_name -from capture.utils.log import print_and_write +from log import print_and_write from capture.platform.android.android import Android diff --git a/src/tools/interop/idt/capture/factory.py b/src/tools/interop/idt/capture/factory.py index c2d10d9644ff19..a128496f6fa4e4 100644 --- a/src/tools/interop/idt/capture/factory.py +++ b/src/tools/interop/idt/capture/factory.py @@ -27,8 +27,8 @@ from capture.utils.async_control import get_timeout from capture.base import EcosystemCapture, PlatformLogStreamer, UnsupportedCapturePlatformException from capture.utils.artifact import safe_mkdir -from capture.utils.log import border_print -from capture.utils import log +from log import border_print +import log _PLATFORM_MAP: typing.Dict[str, PlatformLogStreamer] = {} _ECOSYSTEM_MAP: typing.Dict[str, PlatformLogStreamer] = {} diff --git a/src/tools/interop/idt/capture/loader.py b/src/tools/interop/idt/capture/loader.py index a765bed8bcbc12..6263450d9cc43c 100644 --- a/src/tools/interop/idt/capture/loader.py +++ b/src/tools/interop/idt/capture/loader.py @@ -21,7 +21,7 @@ import traceback from typing import Any -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/pcap/pcap.py b/src/tools/interop/idt/capture/pcap/pcap.py index 2fea8d498ce825..eec577af891f6a 100644 --- a/src/tools/interop/idt/capture/pcap/pcap.py +++ b/src/tools/interop/idt/capture/pcap/pcap.py @@ -21,7 +21,7 @@ from capture.utils.artifact import create_standard_log_name from capture.utils.shell import Bash -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/platform/android/android.py b/src/tools/interop/idt/capture/platform/android/android.py index 114a496afbd965..bc0b0edceba028 100644 --- a/src/tools/interop/idt/capture/platform/android/android.py +++ b/src/tools/interop/idt/capture/platform/android/android.py @@ -26,7 +26,7 @@ from . import streams from .capabilities import Capabilities -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/platform/android/capabilities.py b/src/tools/interop/idt/capture/platform/android/capabilities.py index a50a5062d83b0f..3b61563d85693f 100644 --- a/src/tools/interop/idt/capture/platform/android/capabilities.py +++ b/src/tools/interop/idt/capture/platform/android/capabilities.py @@ -5,7 +5,7 @@ if TYPE_CHECKING: from capture.platform.android import Android -from capture.utils import log +import log from . import config logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/platform/android/streams/logcat/logcat.py b/src/tools/interop/idt/capture/platform/android/streams/logcat/logcat.py index a76d80a0348a50..51d7a8c99ad708 100644 --- a/src/tools/interop/idt/capture/platform/android/streams/logcat/logcat.py +++ b/src/tools/interop/idt/capture/platform/android/streams/logcat/logcat.py @@ -22,7 +22,7 @@ from typing import TYPE_CHECKING from ..base import AndroidStream -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/platform/android/streams/pcap/pcap.py b/src/tools/interop/idt/capture/platform/android/streams/pcap/pcap.py index b68004737b6650..403f86b912d520 100644 --- a/src/tools/interop/idt/capture/platform/android/streams/pcap/pcap.py +++ b/src/tools/interop/idt/capture/platform/android/streams/pcap/pcap.py @@ -27,7 +27,7 @@ if TYPE_CHECKING: from capture.platform.android import Android -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/platform/android/streams/screen/screen.py b/src/tools/interop/idt/capture/platform/android/streams/screen/screen.py index 3ad3f6198e043e..3f201784c7784c 100644 --- a/src/tools/interop/idt/capture/platform/android/streams/screen/screen.py +++ b/src/tools/interop/idt/capture/platform/android/streams/screen/screen.py @@ -26,7 +26,7 @@ if TYPE_CHECKING: from capture.platform.android import Android -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/utils/__init__.py b/src/tools/interop/idt/capture/utils/__init__.py index af291fc35e5e75..f92780d4df0177 100644 --- a/src/tools/interop/idt/capture/utils/__init__.py +++ b/src/tools/interop/idt/capture/utils/__init__.py @@ -15,11 +15,10 @@ # limitations under the License. # -from . import artifact, async_control, log, shell +from . import artifact, async_control, shell __all__ = [ 'artifact', 'async_control', - 'log', 'shell', ] diff --git a/src/tools/interop/idt/capture/utils/artifact.py b/src/tools/interop/idt/capture/utils/artifact.py index 700a09795bd243..257a22d335c09e 100644 --- a/src/tools/interop/idt/capture/utils/artifact.py +++ b/src/tools/interop/idt/capture/utils/artifact.py @@ -20,7 +20,7 @@ import time from multiprocessing import Process from pathlib import Path -from . import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/capture/utils/shell.py b/src/tools/interop/idt/capture/utils/shell.py index 97eb9431b488e9..44c6c661994892 100644 --- a/src/tools/interop/idt/capture/utils/shell.py +++ b/src/tools/interop/idt/capture/utils/shell.py @@ -20,7 +20,7 @@ from mobly.utils import stop_standing_subprocess -from capture.utils import log +import log logger = log.get_logger(__file__) diff --git a/src/tools/interop/idt/config.py b/src/tools/interop/idt/config.py new file mode 100644 index 00000000000000..a7c6cfecc36bc0 --- /dev/null +++ b/src/tools/interop/idt/config.py @@ -0,0 +1,20 @@ +# +# Copyright (c) 2023 Project CHIP Authors +# All rights reserved. +# +# 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. +# +import logging + +enable_color = True +log_level = logging.INFO diff --git a/src/tools/interop/idt/idt.py b/src/tools/interop/idt/idt.py index c3140dc9e0e7dd..784f1b7b91a845 100644 --- a/src/tools/interop/idt/idt.py +++ b/src/tools/interop/idt/idt.py @@ -22,9 +22,10 @@ import sys from pathlib import Path +import config from capture import EcosystemController, EcosystemFactory, PacketCaptureRunner, PlatformFactory from capture.utils.artifact import create_file_timestamp, safe_mkdir -from capture.utils.log import border_print +from log import border_print from discovery import MatterBleScanner, MatterDnssdListener splash = '''\x1b[0m @@ -43,7 +44,8 @@ class InteropDebuggingTool: def __init__(self) -> None: - print(splash) + if config.enable_color: + print(splash) self.artifact_dir = None create_artifact_dir = True if len(sys.argv) == 1: diff --git a/src/tools/interop/idt/capture/utils/log.py b/src/tools/interop/idt/log.py similarity index 92% rename from src/tools/interop/idt/capture/utils/log.py rename to src/tools/interop/idt/log.py index 41d862bc6b8cb0..7357449b14ffb3 100644 --- a/src/tools/interop/idt/capture/utils/log.py +++ b/src/tools/interop/idt/log.py @@ -18,7 +18,7 @@ import logging from typing import TextIO -from .. import config +import config _CONFIG_LEVEL = config.log_level @@ -71,21 +71,20 @@ def border_print(to_print: str, important: bool = False) -> None: border = f"\n{'_' * len_borders}\n" i_border = f"\n{'!' * len_borders}\n" if important else "" if config.enable_color: - print("\x1b[35;1m", end="") + print(magenta, end="") print(f"{border}{i_border}{to_print}{i_border}{border}") if config.enable_color: - print("\x1b[0m", end="") + print(reset, end="") def print_and_write(to_print: str, file: TextIO) -> None: if config.enable_color: - print("\x1b[32;1m", end="") + print(green, end="") print(f"{to_print}") if config.enable_color: - print("\x1b[0m", end="") + print(reset, end="") file.write(to_print) def add_border(to_print: str) -> str: - """Add star borders to important strings""" return '\n' + '*' * len(to_print) + '\n' + to_print