lollms-webui/update_script.py

49 lines
1.3 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-07-23 23:25:05 +00:00
def run_git_pull():
2023-07-21 13:29:08 +00:00
try:
2023-07-23 23:25:05 +00:00
repo = git.Repo(".")
2023-07-21 13:29:08 +00:00
origin = repo.remotes.origin
origin.pull()
except git.GitCommandError as e:
print(f"Error during git pull: {e}")
def install_requirements():
try:
subprocess.check_call(["pip", "install", "-r", "requirements.txt"])
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()