From f8c10bd2f384292fc43e6a9df1407786d3cf8d71 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Wed, 6 Sep 2023 22:35:22 +0800 Subject: [PATCH] [Chore] sc-32247 Fallback to use temp folder to store profile.yml Signed-off-by: Kent Huang [Fix] test failed issue Signed-off-by: Kent Huang [Fix] Code review issue - Enhance piperider user home dir logic in piperider_cli/__init__.py Signed-off-by: Kent Huang [Fix] typo Signed-off-by: Kent Huang --- piperider_cli/__init__.py | 3 +++ piperider_cli/event/__init__.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/piperider_cli/__init__.py b/piperider_cli/__init__.py index 55f525f01..52910eda7 100644 --- a/piperider_cli/__init__.py +++ b/piperider_cli/__init__.py @@ -3,6 +3,7 @@ import os import re import sys +import tempfile import webbrowser from datetime import datetime @@ -11,6 +12,8 @@ from ruamel import yaml PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') +if os.access(os.path.expanduser('~/'), os.W_OK) is False: + PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') diff --git a/piperider_cli/event/__init__.py b/piperider_cli/event/__init__.py index 46ff75a5d..39a43c959 100644 --- a/piperider_cli/event/__init__.py +++ b/piperider_cli/event/__init__.py @@ -1,4 +1,5 @@ import os +import tempfile import uuid from typing import Union @@ -8,6 +9,9 @@ from piperider_cli.event.collector import Collector PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') +if os.access(os.path.expanduser('~/'), os.W_OK) is False: + # If we can't create file in user home directory, fallback to use temp folder + PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') PIPERIDER_USER_EVENT_PATH = os.path.join(PIPERIDER_USER_HOME, '.unsend_events.json') PIPERIDER_FLUSH_EVENTS_WHITELIST = ['init', 'run', 'generate-report', 'compare-reports']