lollms-webui/update_script.py

72 lines
2.4 KiB
Python
Raw Normal View History

2023-07-21 13:29:08 +00:00
import os
import sys
import git
import subprocess
import argparse
2023-10-09 16:11:17 +00:00
from pathlib import Path
2023-07-21 13:29:08 +00:00
2023-07-23 23:25:05 +00:00
def run_git_pull():
2023-07-21 13:29:08 +00:00
try:
2023-10-09 16:11:17 +00:00
print("----------------> Updating the code <-----------------------")
repo = git.Repo(Path(__file__).parent)
2023-07-21 13:29:08 +00:00
origin = repo.remotes.origin
origin.pull()
2023-10-16 06:55:02 +00:00
print("Updating submodules")
try:
2023-10-16 11:35:25 +00:00
repo.git.submodule('update', '--init')
2023-10-16 06:59:01 +00:00
# Checkout the main branch on each submodule
for submodule in repo.submodules:
2023-10-16 07:52:43 +00:00
try:
submodule_repo = submodule.module()
submodule_repo.git.checkout('main')
2023-10-16 11:37:05 +00:00
print(f"Checking out main from {submodule}")
2023-10-27 23:36:53 +00:00
submodule.update()
print(f"Checking out main from {submodule}")
2023-10-16 11:37:05 +00:00
2023-10-16 07:52:43 +00:00
except Exception as ex:
print(f"Couldn't checkout module {submodule}")
2023-10-16 07:00:37 +00:00
except Exception as ex:
2023-10-16 06:55:02 +00:00
print("Couldn't update submodules")
2023-10-16 07:00:37 +00:00
print(ex)
2023-10-09 16:11:17 +00:00
return True
2023-07-21 13:29:08 +00:00
except git.GitCommandError as e:
print(f"Error during git pull: {e}")
2023-10-09 16:11:17 +00:00
return False
2023-07-21 13:29:08 +00:00
def install_requirements():
try:
2023-08-25 15:53:38 +00:00
subprocess.check_call(["pip", "install", "--upgrade", "-r", "requirements.txt"])
2023-10-20 15:02:56 +00:00
subprocess.check_call(["pip", "install", "--upgrade", "-e", "lollms_core"])
subprocess.check_call(["pip", "install", "--upgrade", "-r", "utilities/safe_store"])
2023-07-21 13:29:08 +00:00
except subprocess.CalledProcessError as e:
print(f"Error during pip install: {e}")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--repo", type=str, default="https://github.com/ParisNeo/lollms-webui.git", help="Path to the Git repository")
args = parser.parse_args()
repo_path = args.repo
# Perform git pull to update the repository
2023-07-23 23:25:05 +00:00
run_git_pull()
2023-07-21 13:29:08 +00:00
# Install the new requirements
install_requirements()
# Reload the main script with the original arguments
temp_file = "temp_args.txt"
if os.path.exists(temp_file):
with open(temp_file, "r") as file:
args = file.read().split()
main_script = "app.py" # Replace with the actual name of your main script
os.system(f"python {main_script} {' '.join(args)}")
os.remove(temp_file)
else:
print("Error: Temporary arguments file not found.")
sys.exit(1)
if __name__ == "__main__":
main()