diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 596ded6e..9ba7ee87 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -12,12 +12,28 @@ import webbrowser from builtins import object, str from os import chdir, environ from os.path import dirname, isdir, join -import killswitch from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple, cast -from constants import applongname, appname, protocolhandler_redirect +# config will now cause an appname logger to be set up, so we need the +# console redirect before this +appname = 'EDMarketConnector' # TODO: Must match config.appname, add test +if __name__ == '__main__': + # Keep this as the very first code run to be as sure as possible of no + # output until after this redirect is done, if needed. + if True or getattr(sys, 'frozen', False): + # By default py2exe tries to write log to dirname(sys.executable) which fails when installed + import tempfile + + # unbuffered not allowed for text in python3, so use `1 for line buffering + sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) + # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup + +# isort: off +import killswitch # noqa: E402 # Will cause a logging import/startup so needs to be after the redirect +from config import applongname, appname, appversion, appversion_nobuild, config, copyright # noqa: E402 +# isort: on if __name__ == "__main__": def no_other_instance_running() -> bool: # noqa: CCR001 @@ -130,15 +146,6 @@ if __name__ == "__main__": # reach here. sys.exit(0) - # Keep this as the very first code run to be as sure as possible of no - # output until after this redirect is done, if needed. - if getattr(sys, 'frozen', False): - # By default py2exe tries to write log to dirname(sys.executable) which fails when installed - import tempfile - - # unbuffered not allowed for text in python3, so use `1 for line buffering - sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1) - # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup # After the redirect in case config does logging setup from config import appversion, appversion_nobuild, config, copyright