2023-06-11 22:11:06 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2023-06-17 00:00:37 +02:00
|
|
|
|
2023-06-11 22:11:06 +02:00
|
|
|
def clone_or_pull_repository(github_url):
|
|
|
|
repository_folder = "extensions"
|
|
|
|
repo_name = github_url.split("/")[-1].split(".")[0]
|
|
|
|
|
|
|
|
# Check if the repository folder exists
|
|
|
|
if not os.path.exists(repository_folder):
|
|
|
|
os.makedirs(repository_folder)
|
|
|
|
|
|
|
|
repo_path = os.path.join(repository_folder, repo_name)
|
|
|
|
|
|
|
|
# Check if the repository is already cloned
|
|
|
|
if os.path.exists(repo_path):
|
2023-07-04 05:03:30 +02:00
|
|
|
yield f"Updating {github_url}..."
|
2023-06-11 22:11:06 +02:00
|
|
|
# Perform a 'git pull' to update the repository
|
|
|
|
try:
|
|
|
|
pull_output = subprocess.check_output(["git", "-C", repo_path, "pull"], stderr=subprocess.STDOUT)
|
2023-07-04 05:03:30 +02:00
|
|
|
yield "Done."
|
2023-06-11 22:11:06 +02:00
|
|
|
return pull_output.decode()
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return str(e)
|
|
|
|
|
|
|
|
# Clone the repository
|
|
|
|
try:
|
2023-07-04 05:03:30 +02:00
|
|
|
yield f"Cloning {github_url}..."
|
2023-06-11 22:11:06 +02:00
|
|
|
clone_output = subprocess.check_output(["git", "clone", github_url, repo_path], stderr=subprocess.STDOUT)
|
2023-07-04 05:03:30 +02:00
|
|
|
yield "Done."
|
2023-06-11 22:11:06 +02:00
|
|
|
return clone_output.decode()
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return str(e)
|