Update initialize.py

Update reading from repos.yaml file
This commit is contained in:
bjoernellens1 2023-05-26 10:59:39 +02:00 committed by GitHub
parent db333799f7
commit 298e8ad74f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import os import os
import subprocess import subprocess
import yaml
class GitCloner: class GitCloner:
def __init__(self, directory): def __init__(self, directory):
@ -16,18 +17,20 @@ class GitCloner:
command = ['git', 'clone', '--branch', branch, repo_url, repo_path] command = ['git', 'clone', '--branch', branch, repo_url, repo_path]
try: try:
subprocess.check_output(command) subprocess.check_output(command)
print(f"Successfully cloned repository '{repo_name}'.") print(f"Successfully cloned repository '{repo_name}' on branch '{branch}'.")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f"Failed to clone repository '{repo_name}': {e}") print(f"Failed to clone repository '{repo_name}' on branch '{branch}': {e}")
# Usage example # Usage example
cloner = GitCloner('./src') cloner = GitCloner('./src')
# Load repository URLs from file # Load repository URLs from YAML file
with open('repos.txt', 'r') as file: with open('repos.yaml', 'r') as file:
repos = file.readlines() repos_data = yaml.safe_load(file)
# Clone repositories # Clone repositories
for repo_url in repos: for repo_data in repos_data['repositories']:
repo_url = repo_url.strip() # Remove newline characters repo_url = repo_data['url']
cloner.clone_repo(repo_url) branch = repo_data.get('branch', 'main')
cloner.clone_repo(repo_url, branch)