From 929a231882e75db7c07ba70221eb3acec6bdd93f Mon Sep 17 00:00:00 2001 From: Struan Shrimpton Date: Wed, 4 Jun 2025 14:52:26 -0700 Subject: [PATCH] Telemetry: add win support The .vpython3 change is only necessary for running the opt in/out on windows. Otherwise the only oddity was temporary files being weird in windows. Bug: 326277821 Change-Id: I88326410526d6fe7f6feb14a0bc27ab22eb12b58 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6615021 Reviewed-by: Ben Pastene Commit-Queue: Struan Shrimpton --- infra_lib/telemetry/.vpython3 | 5 +++++ infra_lib/telemetry/__init__.py | 4 ++-- infra_lib/telemetry/config.py | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/infra_lib/telemetry/.vpython3 b/infra_lib/telemetry/.vpython3 index 02ef99a4c4..df0e1d852a 100644 --- a/infra_lib/telemetry/.vpython3 +++ b/infra_lib/telemetry/.vpython3 @@ -5,6 +5,11 @@ python_version: "3.8" +wheel: < + name: "infra/python/wheels/colorama-py2_py3" + version: "version:0.4.1" +> + wheel: < name: "infra/python/wheels/typing-extensions-py3" version: "version:4.0.1" diff --git a/infra_lib/telemetry/__init__.py b/infra_lib/telemetry/__init__.py index 97c6aacfd1..4ed0108f7e 100644 --- a/infra_lib/telemetry/__init__.py +++ b/infra_lib/telemetry/__init__.py @@ -68,8 +68,8 @@ def is_google_host() -> bool: def initialize(service_name, notice=DEFAULT_BANNER, cfg_file=config.DEFAULT_CONFIG_FILE): - # TODO(326277821): Add support for other platforms - if not sys.platform.startswith('linux'): + # TODO(326277821): Add support for mac + if sys.platform == 'darwin': return if not is_google_host(): diff --git a/infra_lib/telemetry/config.py b/infra_lib/telemetry/config.py index 2c0c5bcab8..0ccb58c504 100644 --- a/infra_lib/telemetry/config.py +++ b/infra_lib/telemetry/config.py @@ -156,17 +156,19 @@ class Config: self._trace_config = TraceConfig(self._config) self._root_config = RootConfig(self._config) + def flush(self) -> None: """Flushes the current config to config file.""" - tmpfile = tempfile.NamedTemporaryFile() - with open(tmpfile.name, "w", encoding="utf-8") as configfile: + tmpDir = tempfile.mkdtemp() + tmpfile = Path.joinpath(Path(tmpDir), 'telemetry.cfg') + with open(tmpfile, "w", encoding="utf-8") as configfile: self._config.write(configfile) if not self._path.parent.exists(): self._path.parent.mkdir(parents=True, exist_ok=True) - shutil.copy(tmpfile.name, self._path) + shutil.copy(tmpfile, self._path) @property def root_config(self) -> RootConfig: