From 17113d0213a2b15223de414fd2fd4977c12addf9 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 14 Jan 2025 17:41:02 +0700 Subject: [PATCH] #4472 never write bytecode in installer path --- xpra/platform/win32/__init__.py | 20 +++++++++++++++----- xpra/platform/win32/paths.py | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/xpra/platform/win32/__init__.py b/xpra/platform/win32/__init__.py index 0df30b5804..7f122a2684 100644 --- a/xpra/platform/win32/__init__.py +++ b/xpra/platform/win32/__init__.py @@ -209,20 +209,30 @@ def setup_console_event_listener(handler, enable: bool) -> bool: def do_init() -> None: + def datadir() -> str: + from xpra.platform.win32.paths import get_appdata_dir + appdatadir = get_appdata_dir(False) + if not os.path.exists(appdatadir): + os.mkdir(appdatadir) + return appdatadir + + if FROZEN: + if envbool("PYTHONDONTWRITEBYTECODE", False): + sys.dont_write_bytecode = True + if not os.environ.get("PYTHONPYCACHEPREFIX"): + sys.pycache_prefix = os.path.join(datadir(), "pycache-%i.%i" % (sys.version_info[:2])) + if not REDIRECT_OUTPUT or is_terminal(): # figure out if we want to wait for input at the end: global _wait_for_input _wait_for_input = should_wait_for_input() return + if envbool("XPRA_LOG_TO_FILE", True): log_filename = os.environ.get("XPRA_LOG_FILENAME") if not log_filename: - from xpra.platform.win32.paths import _get_data_dir from xpra.platform import get_prgname - data_dir = _get_data_dir(False) - if not os.path.exists(data_dir): - os.mkdir(data_dir) - log_filename = os.path.join(data_dir, (get_prgname() or "Xpra")+".log") + log_filename = os.path.join(datadir(), (get_prgname() or "Xpra")+".log") sys.stdout = open(log_filename, "a", encoding="utf8") sys.stderr = sys.stdout os.environ["XPRA_LOG_FILENAME"] = log_filename diff --git a/xpra/platform/win32/paths.py b/xpra/platform/win32/paths.py index 941a8fce09..9aa45e0f32 100644 --- a/xpra/platform/win32/paths.py +++ b/xpra/platform/win32/paths.py @@ -37,6 +37,10 @@ def _get_data_dir(roaming=True) -> str: # if not running from a binary, return current directory: if not getattr(sys, 'frozen', ''): return os.getcwd() + return get_appdata_dir(roaming) + + +def get_appdata_dir(roaming=True) -> str: appdata = sh_get_folder_path(CSIDL_APPDATA if roaming else CSIDL_LOCAL_APPDATA) if not appdata: # on win32 we must send stdout to a logfile to prevent an alert box on exit shown by `py2exe`