mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
cmdeploy: introduce LocalExec object
This commit is contained in:
@@ -19,7 +19,7 @@ from packaging import version
|
|||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
from . import dns, remote
|
from . import dns, remote
|
||||||
from .sshexec import SSHExec
|
from .sshexec import SSHExec, LocalExec
|
||||||
|
|
||||||
#
|
#
|
||||||
# cmdeploy sub commands and options
|
# cmdeploy sub commands and options
|
||||||
@@ -365,9 +365,9 @@ def get_parser():
|
|||||||
|
|
||||||
def get_sshexec(ssh_host: str, verbose=True):
|
def get_sshexec(ssh_host: str, verbose=True):
|
||||||
if ssh_host in ["localhost", "@local"]:
|
if ssh_host in ["localhost", "@local"]:
|
||||||
return "localhost"
|
return LocalExec(verbose, docker=False)
|
||||||
elif ssh_host == "docker":
|
elif ssh_host == "docker":
|
||||||
return "docker"
|
return LocalExec(verbose, docker=True)
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"[ssh] login to {ssh_host}")
|
print(f"[ssh] login to {ssh_host}")
|
||||||
return SSHExec(ssh_host, verbose=verbose)
|
return SSHExec(ssh_host, verbose=verbose)
|
||||||
|
|||||||
@@ -7,15 +7,9 @@ from . import remote
|
|||||||
|
|
||||||
|
|
||||||
def get_initial_remote_data(sshexec, mail_domain):
|
def get_initial_remote_data(sshexec, mail_domain):
|
||||||
if sshexec == "localhost":
|
return sshexec.logged(
|
||||||
result = remote.rdns.perform_initial_checks(mail_domain)
|
call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain)
|
||||||
elif sshexec == "docker":
|
)
|
||||||
result = remote.rdns.perform_initial_checks(mail_domain, pre_command="docker exec chatmail ")
|
|
||||||
else:
|
|
||||||
result = sshexec.logged(
|
|
||||||
call=remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=mail_domain)
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def check_initial_remote_data(remote_data, *, print=print):
|
def check_initial_remote_data(remote_data, *, print=print):
|
||||||
@@ -50,14 +44,9 @@ def check_full_zone(sshexec, remote_data, out, zonefile) -> int:
|
|||||||
"""Check existing DNS records, optionally write them to zone file
|
"""Check existing DNS records, optionally write them to zone file
|
||||||
and return (exitcode, remote_data) tuple."""
|
and return (exitcode, remote_data) tuple."""
|
||||||
|
|
||||||
if sshexec in ["localhost", "docker"]:
|
required_diff, recommended_diff = sshexec.logged(
|
||||||
required_diff, recommended_diff = remote.rdns.check_zonefile(
|
remote.rdns.check_zonefile, kwargs=dict(zonefile=zonefile, verbose=False),
|
||||||
zonefile=zonefile, verbose=False
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
required_diff, recommended_diff = sshexec.logged(
|
|
||||||
remote.rdns.check_zonefile, kwargs=dict(zonefile=zonefile, verbose=False),
|
|
||||||
)
|
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
if required_diff:
|
if required_diff:
|
||||||
|
|||||||
@@ -82,3 +82,19 @@ class SSHExec:
|
|||||||
res = self(call, kwargs, log_callback=remote.rshell.log_progress)
|
res = self(call, kwargs, log_callback=remote.rshell.log_progress)
|
||||||
print_stderr()
|
print_stderr()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class LocalExec:
|
||||||
|
def __init__(self, verbose=False, docker=False):
|
||||||
|
self.verbose = verbose
|
||||||
|
self.docker = docker
|
||||||
|
|
||||||
|
def logged(self, call, kwargs: dict):
|
||||||
|
where = "locally"
|
||||||
|
if self.docker:
|
||||||
|
if call == remote.rdns.perform_initial_checks:
|
||||||
|
kwargs['pre_command'] = "docker exec chatmail "
|
||||||
|
where = "in docker"
|
||||||
|
if self.verbose:
|
||||||
|
print(f"Running {where}: {call.__name__}(**{kwargs})")
|
||||||
|
return call(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user