diff --git a/.gitignore b/.gitignore index a0dc422..1bbdfbd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,11 @@ build/build-exe-config.json install/*.exe *.pyo + +*.spec + +build/build-exe-pyinstaller-command.bat + +build/build/BAPSicle/ + +build/output/ diff --git a/build/build-exe-config.template.json b/build/build-exe-config.template.json index 2ac7d21..147e9f0 100644 --- a/build/build-exe-config.template.json +++ b/build/build-exe-config.template.json @@ -7,7 +7,7 @@ }, { "optionDest": "filenames", - "value": "../launch_standalone.py" + "value": "\\launch_standalone.py" }, { "optionDest": "onefile", @@ -19,7 +19,7 @@ }, { "optionDest": "icon_file", - "value": "\\icon.ico" + "value": "\\build\\icon.ico" }, { "optionDest": "name", diff --git a/build/build-exe.bat b/build/build-exe.bat index 3c7c410..a2cf6e0 100644 --- a/build/build-exe.bat +++ b/build/build-exe.bat @@ -3,8 +3,16 @@ pip install -r requirements.txt pip install -r requirements-windows.txt pip install -e ..\ +: Generate the json config in case you wanted to use the gui to regenerate the command below manually. python generate-build-exe-config.py -auto-py-to-exe -c build-exe-config.json -o ../install +: auto-py-to-exe -c build-exe-config.json -o ../install +python build-exe.py + +build-exe-pyinstaller-command.bat + +del *.spec /q + +echo "Output file should be located in 'output/' folder." TIMEOUT 5 \ No newline at end of file diff --git a/build/build-exe.py b/build/build-exe.py new file mode 100644 index 0000000..d9dc3ea --- /dev/null +++ b/build/build-exe.py @@ -0,0 +1,43 @@ +import sys +import json + +file = open('build-exe-config.json', 'r') +config = json.loads(file.read()) +file.close() + +cmd_str = "pyinstaller " +json_dests = ["icon_file", "clean_build"] +pyi_dests = ["icon", "clean"] + +for option in config["pyinstallerOptions"]: + + option_dest = option["optionDest"] + + # The json is rather inconsistent :/ + if option_dest in json_dests: + print("in") + option_dest = pyi_dests[json_dests.index(option_dest)] + + option_dest = option_dest.replace("_", "-") + + if option_dest == "datas": + cmd_str += '--add-data "' + option["value"] + '" ' + elif option_dest == "filenames": + filename = option["value"] + elif option["value"] == True: + cmd_str += "--" + str(option_dest) + " " + elif option["value"] == False: + pass + else: + cmd_str += "--" + str(option_dest) + ' "' + str(option["value"]) + '" ' + + +command = open('build-exe-pyinstaller-command.bat', 'w') + +if filename == "": + print("No filename data was found in json file.") + command.write("") +else: + command.write(cmd_str + ' --distpath "output/" --workpath "build/" "' + filename + '"') + +command.close() diff --git a/build/generate-build-exe-config.py b/build/generate-build-exe-config.py index b84a501..5fc1e0d 100644 --- a/build/generate-build-exe-config.py +++ b/build/generate-build-exe-config.py @@ -9,10 +9,8 @@ config = json.loads(in_file.read()) in_file.close() for option in config["pyinstallerOptions"]: - if option["optionDest"] == "icon_file": - option["value"] = dir_path + option["value"] - if option["optionDest"] == "datas": - option["value"] = parent_path + option["value"] + if option["optionDest"] in ["datas", "filenames", "icon_file"]: + option["value"] = os.path.abspath(parent_path + option["value"]) out_file = open('build-exe-config.json', 'w') out_file.write(json.dumps(config, indent=2)) diff --git a/install/install.bat b/install/install.bat index 5b38a1a..8e3b330 100644 --- a/install/install.bat +++ b/install/install.bat @@ -1,9 +1,44 @@ -mkdir "C:\Program Files\BAPSicle" -cd "C:\Program Files\BAPSicle\" -mkdir state +set install_path="C:\Program Files\BAPSicle" +set exe_name="BAPSicle.exe" +set exe_path=%install_path%\\%exe_name% +set service_name="BAPSicle" -copy /Y "%~dp0\BAPSicle.exe" "BAPSicle.exe" +mkdir %install_path% +mkdir "%install_path%\state" -%~dp0nssm\nssm.exe remove BAPSicle confirm -%~dp0nssm\nssm.exe install BAPSicle .\BAPSicle.exe -TIMEOUT 5 \ No newline at end of file + +cd %~dp0\nssm +nssm stop %service_name% +nssm remove %service_name% confirm +sc.exe delete %service_name% + +cd %install_path% + + +copy /Y "%~dp0\uninstall.bat" . +copy /Y "%~dp0\..\build\output\%exe_name%" %exe_name% + +mkdir nssm +cd nssm +copy /Y "%~dp0\nssm\nssm.exe" . +nssm install %service_name% %exe_path% +nssm set %service_name% AppDirectory %install_path% +nssm set %service_name% AppExit Default Restart +nssm set %service_name% AppStopMethodConsole 5000 +nssm set %service_name% AppStopMethodWindow 5000 +nssm set %service_name% AppStopMethodThreads 5000 +nssm set %service_name% DisplayName "BAPSicle Server" +nssm set %service_name% Description "The next gen Broadcast and Presenting Suite server! Access settings on port 5000." +nssm set %service_name% ObjectName LocalSystem +nssm set %service_name% Start SERVICE_AUTO_START +nssm set %service_name% Type SERVICE_INTERACTIVE_PROCESS + +: usefull tools are edit and dump: + +: nssm edit %service_name% +: nssm dump %service_name% +nssm start %service_name% + +timeout 4 /nobreak + +explorer "http://localhost:5000/" diff --git a/install/uninstall.bat b/install/uninstall.bat new file mode 100644 index 0000000..2b66ee1 --- /dev/null +++ b/install/uninstall.bat @@ -0,0 +1,11 @@ + +set service_name="BAPSicle" + +cd %~dp0\nssm +nssm stop %service_name% +nssm remove %service_name% confirm +sc.exe delete %service_name% + +del "C:\Program Files\BAPSicle\" /q /s /f + +PAUSE \ No newline at end of file