From 5f75e36efde0d2c629844dea9587b78e64e22b3b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 21 Jul 2023 15:28:26 +0300 Subject: [PATCH] Move "get_project_id" to the project helpers --- platformio/app.py | 4 ---- platformio/project/helpers.py | 7 +++++++ platformio/telemetry.py | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platformio/app.py b/platformio/app.py index f629ff13..d94cdfef 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -258,10 +258,6 @@ def get_cid(): return cid -def get_project_id(project_dir): - return hashlib.sha1(hashlib_encode_data(project_dir)).hexdigest() - - def get_user_agent(): data = [ "PlatformIO/%s" % __version__, diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index b1ae5bee..97bdbbb8 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import hashlib import os import re import subprocess @@ -28,6 +29,12 @@ def get_project_dir(): return os.getcwd() +def get_project_id(project_dir=None): + return hashlib.sha1( + hashlib_encode_data(project_dir or get_project_dir()) + ).hexdigest() + + def is_platformio_project(project_dir=None): if not project_dir: project_dir = get_project_dir() diff --git a/platformio/telemetry.py b/platformio/telemetry.py index ceb09296..97f17ff5 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -29,6 +29,7 @@ from platformio.cli import PlatformioCLI from platformio.debug.config.base import DebugConfigBase from platformio.http import HTTPSession, ensure_internet_on from platformio.proc import is_ci +from platformio.project.helpers import get_project_id KEEP_MAX_REPORTS = 100 SEND_MAX_EVENTS = 25 @@ -218,7 +219,7 @@ def dump_project_env_params(config, env, platform): for option in non_sensitive_data if config.has_option(section, option) } - params["pid"] = app.get_project_id(os.path.dirname(config.path)) + params["pid"] = get_project_id(os.path.dirname(config.path)) params["platform_name"] = platform.name params["platform_version"] = platform.version return params