import os, sys, 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. """ app_dir = os.path.dirname(os.path.abspath(sys.argv[0])) repos_dir = os.path.join(app_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(repos_dir, git_name) if not os.path.exists(repos_dir): os.makedirs(repos_dir) print(f"Created directory: {repos_dir}") if not os.path.exists(repo_path): print(f"Repository '{git_name}' not found in '{repos_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. """ app_dir = os.path.dirname(os.path.abspath(sys.argv[0])) # home_dir = os.path.expanduser("~") source_path = os.path.join(app_dir, source_path) destination_path = os.path.join(app_dir, destination_path) try: if shutil.os.path.exists(destination_path): shutil.rmtree(destination_path) # Remove existing destination folder shutil.copytree(source_path, destination_path) print(f"Folder '{source_path}' has copied to '{destination_path}") except Exception as e: print(f"Error move_folder: {e}") def check_dir_exist(mypath): app_dir = os.path.dirname(os.path.abspath(sys.argv[0])) check_dir = os.path.join(app_dir, mypath) return os.path.exists(check_dir) def convert_path(mypath): app_dir = os.path.dirname(os.path.abspath(sys.argv[0])) converted_path = os.path.join(app_dir, mypath) return converted_path