Implemented docker and docker compose in proxy logic
This commit is contained in:
56
main.py
56
main.py
@@ -16,7 +16,7 @@ from pkgmgr.config_init import config_init
|
|||||||
from pkgmgr.create_ink import create_ink
|
from pkgmgr.create_ink import create_ink
|
||||||
from pkgmgr.deinstall_repos import deinstall_repos
|
from pkgmgr.deinstall_repos import deinstall_repos
|
||||||
from pkgmgr.delete_repos import delete_repos
|
from pkgmgr.delete_repos import delete_repos
|
||||||
from pkgmgr.exec_git_command import exec_git_command
|
from pkgmgr.exec_proxy_command import exec_proxy_command
|
||||||
from pkgmgr.filter_ignored import filter_ignored
|
from pkgmgr.filter_ignored import filter_ignored
|
||||||
from pkgmgr.get_repo_identifier import get_repo_identifier
|
from pkgmgr.get_repo_identifier import get_repo_identifier
|
||||||
from pkgmgr.get_selected_repos import get_selected_repos
|
from pkgmgr.get_selected_repos import get_selected_repos
|
||||||
@@ -32,7 +32,8 @@ from pkgmgr.status_repos import status_repos
|
|||||||
from pkgmgr.update_repos import update_repos
|
from pkgmgr.update_repos import update_repos
|
||||||
|
|
||||||
# Commands proxied by package-manager
|
# Commands proxied by package-manager
|
||||||
GIT_DEFAULT_COMMANDS = [
|
PROXY_COMMANDS = {
|
||||||
|
"git":[
|
||||||
"pull",
|
"pull",
|
||||||
"push",
|
"push",
|
||||||
"diff",
|
"diff",
|
||||||
@@ -44,7 +45,16 @@ GIT_DEFAULT_COMMANDS = [
|
|||||||
"revert",
|
"revert",
|
||||||
"rebase",
|
"rebase",
|
||||||
"commit"
|
"commit"
|
||||||
|
],
|
||||||
|
"docker":[
|
||||||
|
"start",
|
||||||
|
"stop"
|
||||||
|
],
|
||||||
|
"docker compose":[
|
||||||
|
"up",
|
||||||
|
"down"
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
|
||||||
class SortedSubParsersAction(argparse._SubParsersAction):
|
class SortedSubParsersAction(argparse._SubParsersAction):
|
||||||
def add_parser(self, name, **kwargs):
|
def add_parser(self, name, **kwargs):
|
||||||
@@ -162,25 +172,37 @@ For detailed help on each command, use:
|
|||||||
add_identifier_arguments(shell_parser)
|
add_identifier_arguments(shell_parser)
|
||||||
shell_parser.add_argument("-c", "--command", nargs=argparse.REMAINDER, dest="shell_command", help="The shell command (and its arguments) to execute in each repository",default=[])
|
shell_parser.add_argument("-c", "--command", nargs=argparse.REMAINDER, dest="shell_command", help="The shell command (and its arguments) to execute in each repository",default=[])
|
||||||
|
|
||||||
git_command_parsers = {}
|
proxy_command_parsers = {}
|
||||||
# Proxies the default git commands
|
for command, subcommands in PROXY_COMMANDS.items():
|
||||||
for git_command in GIT_DEFAULT_COMMANDS:
|
for subcommand in subcommands:
|
||||||
git_command_parsers[git_command] = subparsers.add_parser(
|
proxy_command_parsers[f"{command}_{subcommand}"] = subparsers.add_parser(
|
||||||
git_command,
|
subcommand,
|
||||||
help=f"Proxies 'git {git_command}' to one repository/repositories",
|
help=f"Proxies '{command} {subcommand}' to repository/ies",
|
||||||
description=f"Executes 'git {git_command}' for the identified repos.\nTo recieve more help execute 'git {git_command} --help'",
|
description=f"Executes '{command} {subcommand}' for the identified repos.\nTo recieve more help execute '{command} {subcommand} --help'",
|
||||||
formatter_class=argparse.RawTextHelpFormatter
|
formatter_class=argparse.RawTextHelpFormatter
|
||||||
)
|
)
|
||||||
add_identifier_arguments(git_command_parsers[git_command])
|
if subcommand in ["pull","clone"]:
|
||||||
if git_command in ["pull","clone"]:
|
proxy_command_parsers[f"{command}_{subcommand}"].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
||||||
git_command_parsers[git_command].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg")
|
add_identifier_arguments(proxy_command_parsers[f"{command}_{subcommand}"])
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# All
|
# All
|
||||||
if args.command and not args.command in ["config","list","create"]:
|
if args.command and not args.command in ["config","list","create"]:
|
||||||
selected = get_selected_repos(args.all,all_repos_list,args.identifiers)
|
selected = get_selected_repos(args.all,all_repos_list,args.identifiers)
|
||||||
|
|
||||||
|
for command, subcommands in PROXY_COMMANDS.items():
|
||||||
|
for subcommand in subcommands:
|
||||||
|
if args.command == subcommand:
|
||||||
|
if args.command == "clone":
|
||||||
|
clone_repos(selected, repositories_base_dir, all_repos_list, args.preview, no_verification=args.no_verification)
|
||||||
|
elif args.command == "pull":
|
||||||
|
from pkgmgr.pull_with_verification import pull_with_verification
|
||||||
|
pull_with_verification(selected, repositories_base_dir, all_repos_list, args.extra_args, no_verification=args.no_verification, preview=args.preview)
|
||||||
|
else:
|
||||||
|
exec_proxy_command(command,selected, repositories_base_dir, all_repos_list, args.command, args.extra_args, args.preview)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
# Dispatch commands.
|
# Dispatch commands.
|
||||||
if args.command == "install":
|
if args.command == "install":
|
||||||
install_repos(selected,repositories_base_dir, BIN_DIR, all_repos_list, args.no_verification, preview=args.preview, quiet=args.quiet)
|
install_repos(selected,repositories_base_dir, BIN_DIR, all_repos_list, args.no_verification, preview=args.preview, quiet=args.quiet)
|
||||||
@@ -195,14 +217,6 @@ For detailed help on each command, use:
|
|||||||
selected = get_selected_repos(True,all_repos_list,None)
|
selected = get_selected_repos(True,all_repos_list,None)
|
||||||
for identifier in args.identifiers:
|
for identifier in args.identifiers:
|
||||||
create_repo(identifier, config_merged, USER_CONFIG_PATH, BIN_DIR, remote=args.remote, preview=args.preview)
|
create_repo(identifier, config_merged, USER_CONFIG_PATH, BIN_DIR, remote=args.remote, preview=args.preview)
|
||||||
elif args.command in GIT_DEFAULT_COMMANDS:
|
|
||||||
if args.command == "clone":
|
|
||||||
clone_repos(selected, repositories_base_dir, all_repos_list, args.preview, no_verification=args.no_verification)
|
|
||||||
elif args.command == "pull":
|
|
||||||
from pkgmgr.pull_with_verification import pull_with_verification
|
|
||||||
pull_with_verification(selected, repositories_base_dir, all_repos_list, args.extra_args, no_verification=args.no_verification, preview=args.preview)
|
|
||||||
else:
|
|
||||||
exec_git_command(selected, repositories_base_dir, all_repos_list, args.command, args.extra_args, args.preview)
|
|
||||||
elif args.command == "list":
|
elif args.command == "list":
|
||||||
list_repositories(all_repos_list, repositories_base_dir, BIN_DIR, search_filter=args.search, status_filter=args.status)
|
list_repositories(all_repos_list, repositories_base_dir, BIN_DIR, search_filter=args.search, status_filter=args.status)
|
||||||
elif args.command == "deinstall":
|
elif args.command == "deinstall":
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ from pkgmgr.get_repo_identifier import get_repo_identifier
|
|||||||
from pkgmgr.get_repo_dir import get_repo_dir
|
from pkgmgr.get_repo_dir import get_repo_dir
|
||||||
from pkgmgr.run_command import run_command
|
from pkgmgr.run_command import run_command
|
||||||
|
|
||||||
def exec_git_command(selected_repos, repositories_base_dir, all_repos, git_cmd, extra_args, preview=False):
|
def exec_proxy_command(proxy_prefix:str,selected_repos, repositories_base_dir, all_repos, proxy_command:str, extra_args, preview:bool):
|
||||||
"""Execute a given git command with extra arguments for each repository."""
|
"""Execute a given proxy command with extra arguments for each repository."""
|
||||||
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 os.path.exists(repo_dir):
|
if os.path.exists(repo_dir):
|
||||||
full_cmd = f"git {git_cmd} {' '.join(extra_args)}"
|
full_cmd = f"{proxy_prefix} {proxy_command} {' '.join(extra_args)}"
|
||||||
run_command(full_cmd, cwd=repo_dir, preview=preview)
|
run_command(full_cmd, cwd=repo_dir, preview=preview)
|
||||||
else:
|
else:
|
||||||
print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.")
|
print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.")
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
from .exec_git_command import exec_git_command
|
from .exec_proxy_command import exec_proxy_command
|
||||||
from .run_command import run_command
|
from .run_command import run_command
|
||||||
|
|
||||||
def status_repos(selected_repos, repositories_base_dir, all_repos, extra_args, list_only=False, system_status=False, preview=False):
|
def status_repos(selected_repos, repositories_base_dir, all_repos, extra_args, list_only=False, system_status=False, preview=False):
|
||||||
@@ -10,4 +10,4 @@ def status_repos(selected_repos, repositories_base_dir, all_repos, extra_args, l
|
|||||||
for repo in selected_repos:
|
for repo in selected_repos:
|
||||||
print(get_repo_identifier(repo, all_repos))
|
print(get_repo_identifier(repo, all_repos))
|
||||||
else:
|
else:
|
||||||
exec_git_command(selected_repos, repositories_base_dir, all_repos, "status", extra_args, preview)
|
exec_proxy_command('git',selected_repos, repositories_base_dir, all_repos, "status", extra_args, preview)
|
||||||
Reference in New Issue
Block a user