From 84489f16b502cffce66e75ae0a109682715e5729 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 12 Aug 2024 20:44:42 -0700 Subject: [PATCH] refactor: Refactor data file name and mkdir operations --- aider/analytics.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aider/analytics.py b/aider/analytics.py index 0893bb020..b75bc1ae5 100644 --- a/aider/analytics.py +++ b/aider/analytics.py @@ -7,6 +7,8 @@ from pathlib import Path from mixpanel import Mixpanel +DATA_FILE_NAME = "mixpanel.json" + from aider import __version__ from aider.dump import dump # noqa: F401 @@ -25,17 +27,19 @@ class Analytics: self.mp = Mixpanel(project_token) if project_token else None self.user_id = self.get_or_create_uuid() - def mark_as_disabled(self): - data_file = Path.home() / ".aider" / "caches" / "mixpanel.json" + def get_data_file_path(self): + data_file = Path.home() / ".aider" / "caches" / DATA_FILE_NAME data_file.parent.mkdir(parents=True, exist_ok=True) + return data_file + def mark_as_disabled(self): + data_file = self.get_data_file_path() data = {"uuid": str(uuid.uuid4()), "disabled": True} with open(data_file, "w") as f: json.dump(data, f) def get_or_create_uuid(self): - data_file = Path.home() / ".aider" / "caches" / "mixpanel.json" - data_file.parent.mkdir(parents=True, exist_ok=True) + data_file = self.get_data_file_path() if data_file.exists(): with open(data_file, "r") as f: