Skip to content

Commit

Permalink
never write bytecode in installer path (#4472)
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 14, 2025
1 parent c41a7a7 commit 828b7a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 16 additions & 6 deletions xpra/platform/win32/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,29 @@ def setup_console_event_listener(handler, enable):
def do_init():
if FIX_UNICODE_OUT:
fix_unicode_out()

if not REDIRECT_OUTPUT:
#figure out if we want to wait for input at the end:
set_wait_for_input()
return

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 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 @@ -40,6 +40,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 828b7a0

Please sign in to comment.