Implemented --clone-mode {ssh,https} option
This commit is contained in:
7
main.py
7
main.py
@@ -112,6 +112,7 @@ For detailed help on each command, use:
|
|||||||
add_identifier_arguments(install_parser)
|
add_identifier_arguments(install_parser)
|
||||||
install_parser.add_argument("-q", "--quiet", action="store_true", help="Suppress warnings and info messages")
|
install_parser.add_argument("-q", "--quiet", action="store_true", help="Suppress warnings and info messages")
|
||||||
install_parser.add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
install_parser.add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
||||||
|
install_parser.add_argument("--clone-mode", choices=["ssh", "https"], default="ssh", help="Specify the clone mode (default: ssh)")
|
||||||
|
|
||||||
deinstall_parser = subparsers.add_parser("deinstall", help="Remove alias links to repository/repositories")
|
deinstall_parser = subparsers.add_parser("deinstall", help="Remove alias links to repository/repositories")
|
||||||
add_identifier_arguments(deinstall_parser)
|
add_identifier_arguments(deinstall_parser)
|
||||||
@@ -192,6 +193,8 @@ For detailed help on each command, use:
|
|||||||
)
|
)
|
||||||
if subcommand in ["pull","clone"]:
|
if subcommand in ["pull","clone"]:
|
||||||
proxy_command_parsers[f"{command}_{subcommand}"].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
proxy_command_parsers[f"{command}_{subcommand}"].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
||||||
|
if subcommand == "clone":
|
||||||
|
proxy_command_parsers[f"{command}_{subcommand}"].add_argument("--clone-mode", choices=["ssh", "https"], default="ssh", help="Specify the clone mode (default: ssh)")
|
||||||
add_identifier_arguments(proxy_command_parsers[f"{command}_{subcommand}"])
|
add_identifier_arguments(proxy_command_parsers[f"{command}_{subcommand}"])
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -204,7 +207,7 @@ For detailed help on each command, use:
|
|||||||
for subcommand in subcommands:
|
for subcommand in subcommands:
|
||||||
if args.command == subcommand:
|
if args.command == subcommand:
|
||||||
if args.command == "clone":
|
if args.command == "clone":
|
||||||
clone_repos(selected, REPOSITORIES_BASE_DIR, ALL_REPOSITORIES, args.preview, no_verification=args.no_verification)
|
clone_repos(selected, REPOSITORIES_BASE_DIR, ALL_REPOSITORIES, args.preview, no_verification=args.no_verification, clone_mode=args.clone_mode)
|
||||||
elif args.command == "pull":
|
elif args.command == "pull":
|
||||||
from pkgmgr.pull_with_verification import pull_with_verification
|
from pkgmgr.pull_with_verification import pull_with_verification
|
||||||
pull_with_verification(selected, REPOSITORIES_BASE_DIR, ALL_REPOSITORIES, args.extra_args, no_verification=args.no_verification, preview=args.preview)
|
pull_with_verification(selected, REPOSITORIES_BASE_DIR, ALL_REPOSITORIES, args.extra_args, no_verification=args.no_verification, preview=args.preview)
|
||||||
@@ -218,7 +221,7 @@ For detailed help on each command, use:
|
|||||||
|
|
||||||
# Dispatch commands.
|
# Dispatch commands.
|
||||||
if args.command == "install":
|
if args.command == "install":
|
||||||
install_repos(selected,REPOSITORIES_BASE_DIR, BINARIES_DIRECTORY, ALL_REPOSITORIES, args.no_verification, preview=args.preview, quiet=args.quiet)
|
install_repos(selected, REPOSITORIES_BASE_DIR, BINARIES_DIRECTORY, ALL_REPOSITORIES, args.no_verification, preview=args.preview, quiet=args.quiet, clone_mode=args.clone_mode)
|
||||||
elif args.command == "create":
|
elif args.command == "create":
|
||||||
from pkgmgr.create_repo import create_repo
|
from pkgmgr.create_repo import create_repo
|
||||||
# If no identifiers are provided, you can decide to either use the repository of the current folder
|
# If no identifiers are provided, you can decide to either use the repository of the current folder
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from pkgmgr.get_repo_dir import get_repo_dir
|
|||||||
from pkgmgr.get_repo_identifier import get_repo_identifier
|
from pkgmgr.get_repo_identifier import get_repo_identifier
|
||||||
from pkgmgr.verify import verify_repository
|
from pkgmgr.verify import verify_repository
|
||||||
|
|
||||||
def clone_repos(selected_repos, repositories_base_dir: str, all_repos, preview:bool, no_verification:bool):
|
def clone_repos(selected_repos, repositories_base_dir: str, all_repos, preview: bool, no_verification: bool, clone_mode: str = "ssh"):
|
||||||
for repo in selected_repos:
|
for repo in selected_repos:
|
||||||
repo_identifier = get_repo_identifier(repo, all_repos)
|
repo_identifier = get_repo_identifier(repo, all_repos)
|
||||||
repo_dir = get_repo_dir(repositories_base_dir, repo)
|
repo_dir = get_repo_dir(repositories_base_dir, repo)
|
||||||
@@ -14,11 +14,20 @@ def clone_repos(selected_repos, repositories_base_dir: str, all_repos, preview:b
|
|||||||
|
|
||||||
parent_dir = os.path.dirname(repo_dir)
|
parent_dir = os.path.dirname(repo_dir)
|
||||||
os.makedirs(parent_dir, exist_ok=True)
|
os.makedirs(parent_dir, exist_ok=True)
|
||||||
|
# Build clone URL based on the clone_mode
|
||||||
|
if clone_mode == "ssh":
|
||||||
|
clone_url = f"git@{repo.get('provider')}:{repo.get('account')}/{repo.get('repository')}.git"
|
||||||
|
elif clone_mode == "https":
|
||||||
|
# Use replacement if defined, otherwise construct from provider/account/repository
|
||||||
|
if repo.get("replacement"):
|
||||||
|
clone_url = f"https://{repo.get('replacement')}.git"
|
||||||
|
else:
|
||||||
|
clone_url = f"https://{repo.get('provider')}/{repo.get('account')}/{repo.get('repository')}.git"
|
||||||
|
else:
|
||||||
|
print(f"Unknown clone mode '{clone_mode}'. Aborting clone for {repo_identifier}.")
|
||||||
|
continue
|
||||||
|
|
||||||
# Attempt SSH clone first.
|
print(f"[INFO] Attempting to clone '{repo_identifier}' using {clone_mode.upper()} from {clone_url} into '{repo_dir}'.")
|
||||||
target = repo.get("replacement") if repo.get("replacement") else f"{repo.get('provider')}:{repo.get('account')}/{repo.get('repository')}"
|
|
||||||
clone_url = f"git@{target}.git"
|
|
||||||
print(f"[INFO] Attempting to clone '{repo_identifier}' using SSH from {clone_url} into '{repo_dir}'.")
|
|
||||||
|
|
||||||
if preview:
|
if preview:
|
||||||
print(f"[Preview] Would run: git clone {clone_url} {repo_dir} in {parent_dir}")
|
print(f"[Preview] Would run: git clone {clone_url} {repo_dir} in {parent_dir}")
|
||||||
@@ -27,19 +36,28 @@ def clone_repos(selected_repos, repositories_base_dir: str, all_repos, preview:b
|
|||||||
result = subprocess.run(f"git clone {clone_url} {repo_dir}", cwd=parent_dir, shell=True)
|
result = subprocess.run(f"git clone {clone_url} {repo_dir}", cwd=parent_dir, shell=True)
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print(f"[WARNING] SSH clone failed for '{repo_identifier}' with return code {result.returncode}.")
|
# Only offer fallback if the original mode was SSH.
|
||||||
choice = input("Do you want to attempt HTTPS clone instead? (y/N): ").strip().lower()
|
if clone_mode == "ssh":
|
||||||
if choice == 'y':
|
print(f"[WARNING] SSH clone failed for '{repo_identifier}' with return code {result.returncode}.")
|
||||||
target = repo.get("replacement") if repo.get("replacement") else f"{repo.get('provider')}/{repo.get('account')}/{repo.get('repository')}"
|
choice = input("Do you want to attempt HTTPS clone instead? (y/N): ").strip().lower()
|
||||||
clone_url = f"https://{target}.git"
|
if choice == 'y':
|
||||||
print(f"[INFO] Attempting to clone '{repo_identifier}' using HTTPS from {clone_url} into '{repo_dir}'.")
|
# Attempt HTTPS clone
|
||||||
if preview:
|
if repo.get("replacement"):
|
||||||
print(f"[Preview] Would run: git clone {clone_url} {repo_dir} in {parent_dir}")
|
clone_url = f"https://{repo.get('replacement')}.git"
|
||||||
result = subprocess.CompletedProcess(args=[], returncode=0)
|
else:
|
||||||
|
clone_url = f"https://{repo.get('provider')}/{repo.get('account')}/{repo.get('repository')}.git"
|
||||||
|
print(f"[INFO] Attempting to clone '{repo_identifier}' using HTTPS from {clone_url} into '{repo_dir}'.")
|
||||||
|
if preview:
|
||||||
|
print(f"[Preview] Would run: git clone {clone_url} {repo_dir} in {parent_dir}")
|
||||||
|
result = subprocess.CompletedProcess(args=[], returncode=0)
|
||||||
|
else:
|
||||||
|
result = subprocess.run(f"git clone {clone_url} {repo_dir}", cwd=parent_dir, shell=True)
|
||||||
else:
|
else:
|
||||||
result = subprocess.run(f"git clone {clone_url} {repo_dir}", cwd=parent_dir, shell=True)
|
print(f"[INFO] HTTPS clone not attempted for '{repo_identifier}'.")
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
print(f"[INFO] HTTPS clone not attempted for '{repo_identifier}'.")
|
# For https mode, do not attempt fallback.
|
||||||
|
print(f"[WARNING] HTTPS clone failed for '{repo_identifier}' with return code {result.returncode}.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# After cloning, perform verification in local mode.
|
# After cloning, perform verification in local mode.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from pkgmgr.run_command import run_command
|
|||||||
from pkgmgr.verify import verify_repository
|
from pkgmgr.verify import verify_repository
|
||||||
from pkgmgr.clone_repos import clone_repos
|
from pkgmgr.clone_repos import clone_repos
|
||||||
|
|
||||||
def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_verification, preview=False, quiet=False):
|
def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_verification, preview=False, quiet=False, clone_mode: str = "ssh"):
|
||||||
"""
|
"""
|
||||||
Install repositories by creating symbolic links, running setup commands, and
|
Install repositories by creating symbolic links, running setup commands, and
|
||||||
installing additional packages if a requirements.yml or requirements.txt file is found.
|
installing additional packages if a requirements.yml or requirements.txt file is found.
|
||||||
@@ -18,11 +18,10 @@ def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_
|
|||||||
for repo in selected_repos:
|
for repo in selected_repos:
|
||||||
repo_identifier = get_repo_identifier(repo, all_repos)
|
repo_identifier = get_repo_identifier(repo, all_repos)
|
||||||
repo_dir = get_repo_dir(repositories_base_dir, repo)
|
repo_dir = get_repo_dir(repositories_base_dir, repo)
|
||||||
|
|
||||||
# If the repository directory does not exist, clone it automatically.
|
|
||||||
if not os.path.exists(repo_dir):
|
if not os.path.exists(repo_dir):
|
||||||
print(f"Repository directory '{repo_dir}' does not exist. Cloning it now...")
|
print(f"Repository directory '{repo_dir}' does not exist. Cloning it now...")
|
||||||
clone_repos([repo], repositories_base_dir, all_repos, preview, no_verification)
|
# Pass the clone_mode parameter to clone_repos
|
||||||
|
clone_repos([repo], repositories_base_dir, all_repos, preview, no_verification, clone_mode=clone_mode)
|
||||||
if not os.path.exists(repo_dir):
|
if not os.path.exists(repo_dir):
|
||||||
print(f"Cloning failed for repository {repo_identifier}. Skipping installation.")
|
print(f"Cloning failed for repository {repo_identifier}. Skipping installation.")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user