import os, subprocess, shutil def clone_repo_if_not_exists(git_url, git_dir): """ Clones a Git repository if it doesn't already exist in the git_dir folder. """ home_dir = os.path.expanduser("~") models_dir = os.path.join(home_dir, git_dir) # Extract repository name from the Git URL if git_url.endswith(".git"): git_name = git_url.split('/')[-1][:-4] else: git_name = git_url.split('/')[-1] repo_path = os.path.join(models_dir, git_name) if not os.path.exists(models_dir): os.makedirs(models_dir) print(f"Created directory: {models_dir}") if not os.path.exists(repo_path): print(f"Repository '{git_name}' not found in '{models_dir}'. Cloning from {git_url}...") try: subprocess.run(["git", "clone", git_url, repo_path], check=True) print(f"Successfully cloned '{git_name}' to '{repo_path}'.") except subprocess.CalledProcessError as e: print(f"Error cloning repository: {e}") except FileNotFoundError: print("Error: 'git' command not found. Please ensure Git is installed and in your PATH.") else: print(f"Repository '{git_name}' already exists at '{repo_path}'. Skipping clone.") def move_folder(source_path, destination_path): """ Moves a folder from source_path to destination_path. If a folder already exists at destination_path, it will be replaced. """ home_dir = os.path.expanduser("~") source_path = os.path.join(home_dir, source_path) destination_path = os.path.join(home_dir, destination_path) if shutil.os.path.exists(destination_path): shutil.rmtree(destination_path) # Remove existing destination folder shutil.copytree(source_path, destination_path)