From e2b3ee1e418d2eb574c0c86c20621143b481848f Mon Sep 17 00:00:00 2001 From: Ayaan Shah Date: Tue, 1 Aug 2023 16:55:28 -0700 Subject: [PATCH 1/3] Added windows autoupdate script --- apps/stable_diffusion/web/index.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/stable_diffusion/web/index.py b/apps/stable_diffusion/web/index.py index 258a92749a..90ab19b814 100644 --- a/apps/stable_diffusion/web/index.py +++ b/apps/stable_diffusion/web/index.py @@ -1,6 +1,7 @@ from multiprocessing import Process, freeze_support import os import sys +import subprocess if sys.platform == "darwin": # import before IREE to avoid torch-MLIR library issues @@ -39,10 +40,34 @@ def launch_app(address): ) webview.start(private_mode=False) +# In Windows MSI ONLY +def install_updates(): + '''Installs update from latest release on GitHub if currently running on Windows MSI and an update exists''' + + # Ensures that code is running in a pyinstaller bundle on windows + if sys.platform != 'win32' or not getattr(sys, 'frozen', False): + return + + # Gets path to updater.exe + application_path = os.path.dirname(sys.executable) + application_path, _ = os.path.split(application_path) + application_path = os.path.join(application_path, 'updater.exe') + + # If updater exe does not exist, do nothing + if not os.path.isfile(application_path): + return + + # run updater.exe + subprocess.run(application_path) + if __name__ == "__main__": # required to do multiprocessing in a pyinstaller freeze freeze_support() + + # install updates if running in windows + install_updates() + if args.api or "api" in args.ui.split(","): from apps.stable_diffusion.web.ui import ( txt2img_api, From 604b4917a47ad0a65ff63fa32251f5c7c5b0b616 Mon Sep 17 00:00:00 2001 From: Ayaan Shah Date: Tue, 1 Aug 2023 17:01:59 -0700 Subject: [PATCH 2/3] making linter happy --- apps/stable_diffusion/web/index.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/stable_diffusion/web/index.py b/apps/stable_diffusion/web/index.py index 90ab19b814..c55e118e78 100644 --- a/apps/stable_diffusion/web/index.py +++ b/apps/stable_diffusion/web/index.py @@ -40,23 +40,24 @@ def launch_app(address): ) webview.start(private_mode=False) + # In Windows MSI ONLY def install_updates(): - '''Installs update from latest release on GitHub if currently running on Windows MSI and an update exists''' + """Installs update from latest release on GitHub if currently running on Windows MSI and an update exists""" # Ensures that code is running in a pyinstaller bundle on windows - if sys.platform != 'win32' or not getattr(sys, 'frozen', False): + if sys.platform != "win32" or not getattr(sys, "frozen", False): return - + # Gets path to updater.exe application_path = os.path.dirname(sys.executable) application_path, _ = os.path.split(application_path) - application_path = os.path.join(application_path, 'updater.exe') + application_path = os.path.join(application_path, "updater.exe") # If updater exe does not exist, do nothing if not os.path.isfile(application_path): return - + # run updater.exe subprocess.run(application_path) From 27872193c0091b33555597e7bad8657a4595a984 Mon Sep 17 00:00:00 2001 From: Ayaan Shah Date: Thu, 3 Aug 2023 21:08:30 -0700 Subject: [PATCH 3/3] moved update mechanism to web/utils/updater --- apps/stable_diffusion/web/index.py | 22 +------------------ apps/stable_diffusion/web/utils/updater.py | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 apps/stable_diffusion/web/utils/updater.py diff --git a/apps/stable_diffusion/web/index.py b/apps/stable_diffusion/web/index.py index c55e118e78..5927775af6 100644 --- a/apps/stable_diffusion/web/index.py +++ b/apps/stable_diffusion/web/index.py @@ -2,6 +2,7 @@ import os import sys import subprocess +from apps.stable_diffusion.web.utils import install_updates if sys.platform == "darwin": # import before IREE to avoid torch-MLIR library issues @@ -41,27 +42,6 @@ def launch_app(address): webview.start(private_mode=False) -# In Windows MSI ONLY -def install_updates(): - """Installs update from latest release on GitHub if currently running on Windows MSI and an update exists""" - - # Ensures that code is running in a pyinstaller bundle on windows - if sys.platform != "win32" or not getattr(sys, "frozen", False): - return - - # Gets path to updater.exe - application_path = os.path.dirname(sys.executable) - application_path, _ = os.path.split(application_path) - application_path = os.path.join(application_path, "updater.exe") - - # If updater exe does not exist, do nothing - if not os.path.isfile(application_path): - return - - # run updater.exe - subprocess.run(application_path) - - if __name__ == "__main__": # required to do multiprocessing in a pyinstaller freeze freeze_support() diff --git a/apps/stable_diffusion/web/utils/updater.py b/apps/stable_diffusion/web/utils/updater.py new file mode 100644 index 0000000000..7531ea05ec --- /dev/null +++ b/apps/stable_diffusion/web/utils/updater.py @@ -0,0 +1,25 @@ +# This file contains auto update triggers for all installable distributions +import os +import sys +import subprocess + + +# In Windows MSI ONLY +def install_updates(): + """Installs update from latest release on GitHub if currently running on Windows MSI and an update exists""" + + # Ensures that code is running in a pyinstaller bundle on windows + if sys.platform != "win32" or not getattr(sys, "frozen", False): + return + + # Gets path to updater.exe + application_path = os.path.dirname(sys.executable) + application_path, _ = os.path.split(application_path) + application_path = os.path.join(application_path, "updater.exe") + + # If updater exe does not exist, do nothing + if not os.path.isfile(application_path): + return + + # run updater.exe + subprocess.run(application_path)