mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-19 04:17:52 +00:00
upgrade
This commit is contained in:
parent
0117f25412
commit
bf741b4297
@ -254,10 +254,10 @@ class LOLLMSWebUI(LOLLMSElfServer):
|
|||||||
def check_update_(self, branch_name="main"):
|
def check_update_(self, branch_name="main"):
|
||||||
try:
|
try:
|
||||||
# Open the repository
|
# Open the repository
|
||||||
repo_path = str(Path(__file__).parent)
|
repo_path = str(Path(__file__).parent/"lollms_core")
|
||||||
if self.check_module_update_(repo_path, branch_name):
|
if self.check_module_update_(repo_path, branch_name):
|
||||||
return True
|
return True
|
||||||
repo_path = str(Path(__file__).parent/"lollms_core")
|
repo_path = str(Path(__file__).parent)
|
||||||
if self.check_module_update_(repo_path, branch_name):
|
if self.check_module_update_(repo_path, branch_name):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
122
update_script.py
122
update_script.py
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import git
|
import git
|
||||||
@ -6,51 +5,91 @@ import subprocess
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ascii_colors import ASCIIColors, trace_exception
|
from ascii_colors import ASCIIColors, trace_exception
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
def show_error_dialog(message):
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw() # Hide the main window
|
||||||
|
messagebox.showerror("Error", message)
|
||||||
|
root.destroy()
|
||||||
|
|
||||||
def run_git_pull():
|
def run_git_pull():
|
||||||
try:
|
try:
|
||||||
print("----------------> Updating the code <-----------------------")
|
ASCIIColors.info("----------------> Updating the code <-----------------------")
|
||||||
|
|
||||||
repo = git.Repo(Path(__file__).parent)
|
repo = git.Repo(Path(__file__).parent)
|
||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
origin.pull()
|
|
||||||
|
# Fetch the latest changes
|
||||||
|
origin.fetch()
|
||||||
|
|
||||||
|
# Check if there are any changes to pull
|
||||||
|
if repo.head.commit == origin.refs.main.commit:
|
||||||
|
ASCIIColors.success("Already up-to-date.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Discard local changes and force update
|
||||||
|
try:
|
||||||
|
repo.git.reset('--hard', 'origin/main')
|
||||||
|
repo.git.clean('-fd')
|
||||||
|
origin.pull()
|
||||||
|
ASCIIColors.success("Successfully updated the code.")
|
||||||
|
except git.GitCommandError as e:
|
||||||
|
error_message = f"Failed to update the code: {str(e)}"
|
||||||
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
|
return False
|
||||||
|
|
||||||
print("Updating submodules")
|
print("Updating submodules")
|
||||||
try:
|
try:
|
||||||
repo.git.submodule('update', '--init')
|
repo.git.submodule('update', '--init', '--recursive', '--force')
|
||||||
# Checkout the main branch on each submodule
|
# Checkout the main branch on each submodule
|
||||||
for submodule in repo.submodules:
|
for submodule in repo.submodules:
|
||||||
try:
|
try:
|
||||||
submodule_repo = submodule.module()
|
submodule_repo = submodule.module()
|
||||||
submodule_repo.git.checkout('main')
|
submodule_repo.git.fetch('origin')
|
||||||
print(f"Checking out main from {submodule}")
|
submodule_repo.git.reset('--hard', 'origin/main')
|
||||||
submodule.repo.git.submodule('update', '--remote', submodule.name) # Force submodule update
|
submodule_repo.git.clean('-fd')
|
||||||
print(f"Forcing update on {submodule}")
|
print(f"Updated submodule: {submodule}.\nPlease report the error to ParisNeo either on Discord or on github.")
|
||||||
submodule_repo.git.checkout('main')
|
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(f"Couldn't checkout module {submodule}")
|
print(f"Couldn't update submodule {submodule}: {str(ex)}")
|
||||||
|
|
||||||
execution_path = Path(os.getcwd())
|
execution_path = Path(os.getcwd())
|
||||||
|
|
||||||
# Clone the repository to the target path
|
# Update lollms_core
|
||||||
ASCIIColors.info("Lollms_core found in the app space.\nPulling last lollms_core")
|
ASCIIColors.info("Updating lollms_core")
|
||||||
subprocess.run(["git", "-C", str(execution_path/"lollms_core"), "pull"])
|
lollms_core_path = execution_path / "lollms_core"
|
||||||
|
if lollms_core_path.exists():
|
||||||
|
subprocess.run(["git", "-C", str(lollms_core_path), "fetch", "origin"], check=True)
|
||||||
|
subprocess.run(["git", "-C", str(lollms_core_path), "reset", "--hard", "origin/main"], check=True)
|
||||||
|
subprocess.run(["git", "-C", str(lollms_core_path), "clean", "-fd"], check=True)
|
||||||
|
ASCIIColors.success("Successfully updated lollms_core")
|
||||||
|
else:
|
||||||
|
ASCIIColors.warning("lollms_core directory not found")
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print("Couldn't update submodules")
|
error_message = f"Couldn't update submodules: {str(ex)}"
|
||||||
print(ex)
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except git.GitCommandError as e:
|
except Exception as e:
|
||||||
print(f"Error during git pull: {e}")
|
error_message = f"Error during git operations: {str(e)}"
|
||||||
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def install_requirements():
|
def install_requirements():
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(["pip", "install", "--upgrade", "-r", "requirements.txt"])
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "-r", "requirements.txt"])
|
||||||
subprocess.check_call(["pip", "install", "--upgrade", "-e", "lollms_core"])
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "-e", "lollms_core"])
|
||||||
|
ASCIIColors.success("Successfully installed requirements")
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"Error during pip install: {e}")
|
error_message = f"Error during pip install: {str(e)}"
|
||||||
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -60,24 +99,31 @@ def main():
|
|||||||
repo_path = args.repo
|
repo_path = args.repo
|
||||||
|
|
||||||
# Perform git pull to update the repository
|
# Perform git pull to update the repository
|
||||||
run_git_pull()
|
if run_git_pull():
|
||||||
|
# Install the new requirements
|
||||||
|
install_requirements()
|
||||||
|
|
||||||
# Install the new requirements
|
# Reload the main script with the original arguments
|
||||||
install_requirements()
|
temp_file = "temp_args.txt"
|
||||||
|
if os.path.exists(temp_file):
|
||||||
# Reload the main script with the original arguments
|
with open(temp_file, "r") as file:
|
||||||
temp_file = "temp_args.txt"
|
args = file.read().split()
|
||||||
if os.path.exists(temp_file):
|
main_script = "app.py" # Replace with the actual name of your main script
|
||||||
with open(temp_file, "r") as file:
|
os.system(f"{sys.executable} {main_script} {' '.join(args)}")
|
||||||
args = file.read().split()
|
try:
|
||||||
main_script = "app.py" # Replace with the actual name of your main script
|
os.remove(temp_file)
|
||||||
os.system(f"python {main_script} {' '.join(args)}")
|
except Exception as e:
|
||||||
try:
|
error_message = f"Couldn't remove temp file. Try to remove it manually.\nThe file is located here: {temp_file}\nError: {str(e)}"
|
||||||
os.remove(temp_file)
|
ASCIIColors.warning(error_message)
|
||||||
except:
|
else:
|
||||||
print(f"Couldn't remove temp file.\nTry to remove it manually.\nLe fichier se trouve ici: {temp_file}")
|
error_message = "Error: Temporary arguments file not found."
|
||||||
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("Error: Temporary arguments file not found.")
|
error_message = "Update process failed. Please check the console for more details."
|
||||||
|
ASCIIColors.error(error_message)
|
||||||
|
show_error_dialog(error_message)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user