From 68d504c79d89546dc0469f80d72fc916b510b3e1 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 1 May 2015 15:08:14 +0300 Subject: [PATCH] Force writing errors/output to file in case of frozen distributive --- config.py | 19 +++++++++++-------- pyfa.py | 8 ++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index bf4819dd2..8fe03c592 100644 --- a/config.py +++ b/config.py @@ -29,17 +29,16 @@ staticPath = None saveDB = None gameDB = None -# TODO: move back to pyfa.py main loop -# We moved it here just to avoid rebuilding windows skeleton for now (any change to pyfa.py needs it) -import logging -logging.basicConfig() + +def isFrozen(): + if hasattr(sys, 'frozen'): + return True + else: + return False def getPyfaRoot(): - if hasattr(sys, 'frozen'): - base = sys.executable - else: - base = sys.argv[0] + base = sys.executable if isFrozen() else sys.argv[0] root = os.path.dirname(os.path.realpath(os.path.abspath(base))) root = unicode(root, sys.getfilesystemencoding()) return root @@ -71,6 +70,8 @@ def defPaths(): # Redirect stderr to file if we're requested to do so stderrToFile = getattr(configforced, "stderrToFile", None) + if stderrToFile is None: + stderrToFile = True if isFrozen() else False if stderrToFile is True: if not os.path.exists(savePath): os.mkdir(savePath) @@ -78,6 +79,8 @@ def defPaths(): # Same for stdout stdoutToFile = getattr(configforced, "stdoutToFile", None) + if stdoutToFile is None: + stdoutToFile = True if isFrozen() else False if stdoutToFile is True: if not os.path.exists(savePath): os.mkdir(savePath) diff --git a/pyfa.py b/pyfa.py index 2c0c7c00d..1d954ecfe 100755 --- a/pyfa.py +++ b/pyfa.py @@ -33,7 +33,7 @@ if not hasattr(sys, 'frozen'): except ImportError: print("Cannot find wxPython\nYou can download wxPython (2.8+) from http://www.wxpython.org/") sys.exit(1) - + # if user wants to force 2.8, try that and go directly to ensureMinimal path if fails try: if getattr(config.configforced, "force28", False): @@ -51,7 +51,7 @@ if not hasattr(sys, 'frozen'): print "Installed wxPython version doesn't meet requirements.\nYou can download wxPython (2.8+) from http://www.wxpython.org/" sys.exit(1) else: - print "wxPython 2.8 not found; attempting to use newer version, expect errors" + print "wxPython 2.8 not found; attempting to use newer version, expect errors" try: import sqlalchemy @@ -87,6 +87,10 @@ if __name__ == "__main__": config.saveInRoot = True config.defPaths() + # Basic logging initialization + import logging + logging.basicConfig() + # Import everything import wx import os