2023-05-25 09:50:42 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
class GitCloner:
|
|
|
|
def __init__(self, directory):
|
|
|
|
self.directory = directory
|
|
|
|
|
2023-05-25 09:55:35 +00:00
|
|
|
def clone_repo(self, repo_url, branch='main'):
|
2023-05-25 09:50:42 +00:00
|
|
|
repo_name = repo_url.split('/')[-1].split('.')[0]
|
|
|
|
repo_path = os.path.join(self.directory, repo_name)
|
|
|
|
|
|
|
|
if os.path.exists(repo_path):
|
|
|
|
print(f"Repository '{repo_name}' already exists. Skipping cloning.")
|
|
|
|
return
|
|
|
|
|
|
|
|
command = ['git', 'clone', '--branch', branch, repo_url, repo_path]
|
|
|
|
try:
|
|
|
|
subprocess.check_output(command)
|
|
|
|
print(f"Successfully cloned repository '{repo_name}'.")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(f"Failed to clone repository '{repo_name}': {e}")
|
|
|
|
|
|
|
|
# Usage example
|
|
|
|
cloner = GitCloner('./src')
|
2023-05-25 09:54:07 +00:00
|
|
|
|
2023-05-26 08:56:14 +00:00
|
|
|
# Load repository URLs from file
|
|
|
|
with open('repos.txt', 'r') as file:
|
|
|
|
repos = file.readlines()
|
|
|
|
|
|
|
|
# Clone repositories
|
|
|
|
for repo_url in repos:
|
|
|
|
repo_url = repo_url.strip() # Remove newline characters
|
|
|
|
cloner.clone_repo(repo_url)
|