From 9e9d5b7698f00ebd7184478b3ba47fc5099274ad Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 11 Dec 2023 01:50:56 +0100 Subject: [PATCH] consistently show ssh/shell output --- .../src/deploy_chatmail/cmdeploy.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py index 3f384031..f109553a 100644 --- a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py +++ b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py @@ -67,10 +67,6 @@ def dns_cmd(args, out): template = importlib.resources.files(__package__).joinpath("chatmail.zone.f") ssh = f"ssh root@{args.config.mailname}" - def shell_output(arg): - out(f"[{arg}]", file=sys.stderr) - return subprocess.check_output(arg, shell=True).decode() - def read_dkim_entries(entry): lines = [] for line in entry.split("\n"): @@ -80,8 +76,8 @@ def dns_cmd(args, out): lines.append(line) return "\n".join(lines) - acme_account_url = shell_output(f"{ssh} -- acmetool account-url") - dkim_entry = read_dkim_entries(shell_output(f"{ssh} -- opendkim-genzone -F")) + acme_account_url = out.shell_output(f"{ssh} -- acmetool account-url") + dkim_entry = read_dkim_entries(out.shell_output(f"{ssh} -- opendkim-genzone -F")) out( f"[writing {args.config.mailname} zone data (using space as separator) to stdout output]", @@ -105,19 +101,14 @@ def status_cmd(args, out): ssh = f"ssh root@{args.config.mailname}" - def shell_output(arg): - return subprocess.check_output(arg, shell=True).decode() - out.green(f"chatmail domain: {args.config.mailname}") if args.config.privacy_mail: out.green("privacy settings: present") else: out.red("no privacy settings") - out(f"[retrieving info by invoking {ssh}]", file=sys.stderr) - s1 = "systemctl --type=service --state=running" - for line in shell_output(f"{ssh} -- {s1}").split("\n"): + for line in out.shell_output(f"{ssh} -- {s1}").split("\n"): if line.startswith(" "): print(line) @@ -170,6 +161,10 @@ class Out: color = "red" if red else ("green" if green else None) print(colored(msg, color), file=file) + def shell_output(self, arg): + self(f"[$ {arg}]", file=sys.stderr) + return subprocess.check_output(arg, shell=True).decode() + def add_config_option(parser): parser.add_argument(