Skip to content

Commit

Permalink
#4472 never write bytecode in installer path
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 14, 2025
1 parent 5d465b8 commit 17113d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 15 additions & 5 deletions xpra/platform/win32/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions xpra/platform/win32/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 17113d0

Please sign in to comment.