Add auto updates.

This commit is contained in:
Nourepide
2023-11-14 01:14:59 +03:00
parent d960b48eb3
commit 840ac77c9d
4 changed files with 46 additions and 0 deletions
+36
View File
@@ -16,6 +16,12 @@ class Loader:
def __log(self, text):
print("\033[92m[Allor]\033[0m: " + text)
def __error(self, text):
print("\033[91m[Allor]\033[0m: " + text)
def __notification(self, text):
print("\033[94m[Allor]\033[0m: " + text)
def __get_template(self):
with open(self.__template_path, "r") as f:
template = json.load(f)
@@ -84,6 +90,36 @@ class Loader:
self.__log("Updating config.json")
self.__update_config(self.__template(), self.__config())
def check_updates(self):
if self.__config()["updates"]["check_updates"]:
try:
import git
except ImportError:
self.__error("GitPython is not installed.")
return
from git import Repo
# noinspection PyTypeChecker, PyUnboundLocalVariable
repo = Repo(self.__root_path, odbt=git.db.GitDB)
current_commit = repo.head.commit.hexsha
repo.remotes.origin.fetch()
# noinspection PyUnresolvedReferences
latest_commit = repo.head.ref.commit.hexsha
if current_commit == latest_commit:
if self.__config()["updates"]["notify_if_no_new_updates"]:
self.__notification("No new updates.")
else:
if self.__config()["updates"]["notify_if_has_new_updates"]:
self.__notification("New updates are available.")
if self.__config()["updates"]["auto_update"]:
repo.remotes.origin.pull()
self.__notification("Update complete.")
def setup_rembg(self):
os.environ["U2NET_HOME"] = folder_paths.models_dir + "/onnx"
+1
View File
@@ -3,6 +3,7 @@ from .Loader import Loader
loader = Loader()
loader.setup_config()
loader.check_updates()
loader.setup_rembg()
loader.setup_paths()
loader.setup_override()
+3
View File
@@ -1,6 +1,9 @@
rembg
onnx
# Optional for auto updates
gitpython
# If you want you can install onnxruntime with GPU support
# onnxruntime[gpu]
+6
View File
@@ -22,5 +22,11 @@
"postprocessing": false,
"transform": false,
"debug": false
},
"updates": {
"check_updates": true,
"notify_if_has_new_updates": true,
"notify_if_no_new_updates": true,
"auto_update": true
}
}