From 8ea3f348985dd2b95820aaae73aa3a5b9491279b Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 2 Feb 2020 22:36:55 +0100 Subject: [PATCH] compile all user starting points --- MultiMystery.py | 19 +++++++++++++++++-- Utils.py | 8 +++++--- setup.py | 21 +++++++++++++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/MultiMystery.py b/MultiMystery.py index 6ab761ed..addcf249 100644 --- a/MultiMystery.py +++ b/MultiMystery.py @@ -85,7 +85,14 @@ if __name__ == "__main__": player_names = list(file[:-5] for file in player_files) - command = f"py -{py_version} Mystery.py --multi {len(player_files)} {player_string} " \ + if os.path.exists("BerserkerMultiServer.exe"): + basemysterycommand = "BerserkerMystery.exe" #compiled windows + elif os.path.exists("BerserkerMultiServer"): + basemysterycommand = "BerserkerMystery" # compiled linux + else: + basemysterycommand = f"py -{py_version} Mystery.py" #source + + command = f"{basemysterycommand} --multi {len(player_files)} {player_string} " \ f"--names {','.join(player_names)} --enemizercli {enemizer_location} " \ f"--outputpath {outputpath}" + " --create_spoiler" if create_spoiler else "" + " --race" if race else "" print(command) @@ -128,7 +135,15 @@ if __name__ == "__main__": os.remove(file) print(f"Removed file {file} that is now present in the zipfile") - subprocess.call(f"py -{py_version} MultiServer.py --multidata {os.path.join(outputpath, multidataname)}") + if os.path.exists("BerserkerMultiServer.exe"): + baseservercommand = "BerserkerMultiServer.exe" # compiled windows + elif os.path.exists("BerserkerMultiServer"): + baseservercommand = "BerserkerMultiServer" # compiled linux + else: + baseservercommand = f"py -{py_version} MultiServer.py" # source + #don't have a mac to test that. If you try to run compiled on mac, good luck. + + subprocess.call(f"{baseservercommand} --multidata {os.path.join(outputpath, multidataname)}") except: import traceback traceback.print_exc() diff --git a/Utils.py b/Utils.py index b7b000ef..53744ffa 100644 --- a/Utils.py +++ b/Utils.py @@ -36,13 +36,15 @@ def local_path(path): if local_path.cached_path is not None: return os.path.join(local_path.cached_path, path) - if is_bundled(): - # we are running in a bundle + if is_bundled() and hasattr(sys, "_MEIPASS"): + # we are running in a PyInstaller bundle local_path.cached_path = sys._MEIPASS # pylint: disable=protected-access,no-member + elif is_bundled(): + #probably cxFreeze + local_path.cached_path = os.path.dirname(sys.argv[0]) else: # we are running in a normal Python environment local_path.cached_path = os.path.dirname(os.path.abspath(__file__)) - return os.path.join(local_path.cached_path, path) local_path.cached_path = None diff --git a/setup.py b/setup.py index 80111cc1..bb631e99 100644 --- a/setup.py +++ b/setup.py @@ -43,10 +43,19 @@ def manifest_creation(): json.dump(manifest, open(manifestpath, "wt"), indent=4) print("Created Manifest") -EXE = cx_Freeze.Executable( - script="MultiClient.py", - targetName="BerserkerMultiClient" if sys.platform == "linux" else "BerserkerMultiClient.exe" -) +scripts = {"MultiClient.py" : "BerserkerMultiClient", + "MultiMystery.py" : "BerserkerMultiMystery", + "MultiServer.py" : "BerserkerMultiServer", + "gui.py" : "BerserkerMultiCreator", + "Mystery.py" : "BerserkerMystery"} + +exes = [] + +for script, scriptname in scripts.items(): + exes.append(cx_Freeze.Executable( + script=script, + targetName=scriptname + ("" if sys.platform == "linux" else ".exe")) + ) import datetime @@ -57,7 +66,7 @@ cx_Freeze.setup( name="HonorarPlus", version=f"{buildtime.year}.{buildtime.month}.{buildtime.day}.{buildtime.hour}", description="HonorarPlus", - executables=[EXE], + executables=exes, options={ "build_exe": { "zip_include_packages": ["*"], @@ -87,7 +96,7 @@ def installfile(path): print('Warning,', path, 'not found') -extra_data = ["LICENSE"] +extra_data = ["LICENSE", "data", "EnemizerCLI"] for data in extra_data: installfile(Path(data))