From 0523e2289a9cb0281f2891b01ba8da0ac17cd7d6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Dec 2022 10:49:35 +0000 Subject: [PATCH] EDMarketConnector: Improve 'develop only for devs' check * Move it later, after CLI args processing. This would allow for a magic 'override' this, providing a key or similar. * Correct text 'XAthan' to 'Athan' in 'win32' check. * If `git_branch != 'develop'` check if `-alpha0` is in the app version. Such version strings are never in any pre-release or release. --- EDMarketConnector.py | 69 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 6ec96195..ced2ed33 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -49,39 +49,6 @@ if __name__ == '__main__': 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 - try: - import subprocess - git_cmd = subprocess.Popen('git branch --show-current'.split(), - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) - out, err = git_cmd.communicate() - git_branch = out.decode().rstrip('\n') - - if ( - git_branch == 'develop' - and ( - ( - sys.platform == 'linux' - and environ.get('USER') is not None - and environ['USER'] not in ['ad', 'athan'] - ) - or ( - sys.platform == 'win32' - and environ.get('USERNAME') is not None - and environ['USERNAME'] not in ['XAthan'] - ) - ) - ): - print("Why are you running the develop branch if you're not a developer?") - print("Please check https://github.com/EDCD/EDMarketConnector/wiki/Running-from-source#running-from-source") - print("You probably want the 'stable' branch.") - print("\n\rIf Athanasius or A_D asked you to run this, tell them about this message.") - sys.exit(-1) - - except Exception: - pass - # These need to be after the stdout/err redirect because they will cause # logging to be set up. @@ -399,6 +366,42 @@ if __name__ == '__main__': # noqa: C901 sys.stdout.seek(0) sys.stdout.truncate() + git_branch = "" + try: + import subprocess + git_cmd = subprocess.Popen('git branch --show-current'.split(), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + out, err = git_cmd.communicate() + git_branch = out.decode().rstrip('\n') + + except Exception: + pass + + if ( + ( + git_branch == 'develop' + or '-alpha0' in str(appversion()) + ) and ( + ( + sys.platform == 'linux' + and environ.get('USER') is not None + and environ['USER'] not in ['ad', 'athan'] + ) + or ( + sys.platform == 'win32' + and environ.get('USERNAME') is not None + and environ['USERNAME'] not in ['Athan'] + ) + ) + ): + print("Why are you running the develop branch if you're not a developer?") + print("Please check https://github.com/EDCD/EDMarketConnector/wiki/Running-from-source#running-from-source") + print("You probably want the 'stable' branch.") + print("\n\rIf Athanasius or A_D asked you to run this, tell them about this message.") + sys.exit(-1) + # See EDMCLogging.py docs. # isort: off