mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
cmdeploy: add --force to cmdeploy init for recreating chatmail.ini
This commit is contained in:
@@ -17,6 +17,9 @@
|
|||||||
- Add startup for `fcgiwrap.service` because sometimes it did not start automatically.
|
- Add startup for `fcgiwrap.service` because sometimes it did not start automatically.
|
||||||
([#657](https://github.com/chatmail/relay/pull/657))
|
([#657](https://github.com/chatmail/relay/pull/657))
|
||||||
|
|
||||||
|
- Add `cmdeploy init --force` command for recreating chatmail.ini
|
||||||
|
([#656](https://github.com/chatmail/relay/pull/656))
|
||||||
|
|
||||||
- Increase maxproc for reinjecting ports from 10 to 100
|
- Increase maxproc for reinjecting ports from 10 to 100
|
||||||
([#646](https://github.com/chatmail/relay/pull/646))
|
([#646](https://github.com/chatmail/relay/pull/646))
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ from .sshexec import SSHExec
|
|||||||
# cmdeploy sub commands and options
|
# cmdeploy sub commands and options
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def is_pytest():
|
||||||
|
return "PYTEST_CURRENT_TEST" in os.environ
|
||||||
|
|
||||||
|
|
||||||
def init_cmd_options(parser):
|
def init_cmd_options(parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -32,18 +35,28 @@ def init_cmd_options(parser):
|
|||||||
action="store",
|
action="store",
|
||||||
help="fully qualified DNS domain name for your chatmail instance",
|
help="fully qualified DNS domain name for your chatmail instance",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--force",
|
||||||
|
dest="recreate_ini",
|
||||||
|
action="store_true",
|
||||||
|
help="force reacreate ini file",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def init_cmd(args, out):
|
def init_cmd(args, out):
|
||||||
"""Initialize chatmail config file."""
|
"""Initialize chatmail config file."""
|
||||||
mail_domain = args.chatmail_domain
|
mail_domain = args.chatmail_domain
|
||||||
|
inipath = args.inipath
|
||||||
if args.inipath.exists():
|
if args.inipath.exists():
|
||||||
print(f"Path exists, not modifying: {args.inipath}")
|
if not args.recreate_ini:
|
||||||
return 1
|
out.green(f"[WARNING] Path exists, not modifying: {inipath}")
|
||||||
else:
|
return 1
|
||||||
write_initial_config(args.inipath, mail_domain, overrides={})
|
else:
|
||||||
out.green(f"created config file for {mail_domain} in {args.inipath}")
|
out.yellow(f"[WARNING] Force argument was provided, deleting config file: {inipath}")
|
||||||
|
inipath.unlink()
|
||||||
|
|
||||||
|
write_initial_config(inipath, mail_domain, overrides={})
|
||||||
|
out.green(f"created config file for {mail_domain} in {inipath}")
|
||||||
|
|
||||||
def run_cmd_options(parser):
|
def run_cmd_options(parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -263,11 +276,20 @@ class Out:
|
|||||||
def red(self, msg, file=sys.stderr):
|
def red(self, msg, file=sys.stderr):
|
||||||
print(colored(msg, "red"), file=file)
|
print(colored(msg, "red"), file=file)
|
||||||
|
|
||||||
def green(self, msg, file=sys.stderr):
|
def green(self, msg, file=sys.stdout):
|
||||||
print(colored(msg, "green"), file=file)
|
print(colored(msg, "green"), file=file)
|
||||||
|
|
||||||
def __call__(self, msg, red=False, green=False, file=sys.stdout):
|
def yellow(self, msg, file=sys.stdout):
|
||||||
color = "red" if red else ("green" if green else None)
|
print(colored(msg, "yellow"), file=file)
|
||||||
|
|
||||||
|
def __call__(self, msg, red=False, green=False, yellow=False, file=sys.stdout):
|
||||||
|
color = None
|
||||||
|
if red:
|
||||||
|
color = "red"
|
||||||
|
elif green:
|
||||||
|
color = "green"
|
||||||
|
elif yellow:
|
||||||
|
color = "yellow"
|
||||||
print(colored(msg, color), file=file)
|
print(colored(msg, color), file=file)
|
||||||
|
|
||||||
def check_call(self, arg, env=None, quiet=False):
|
def check_call(self, arg, env=None, quiet=False):
|
||||||
@@ -352,6 +374,12 @@ def main(args=None):
|
|||||||
args.get_sshexec = get_sshexec
|
args.get_sshexec = get_sshexec
|
||||||
|
|
||||||
out = Out()
|
out = Out()
|
||||||
|
if is_pytest(): ## issue: https://github.com/chatmail/relay/issues/622
|
||||||
|
out.green = print
|
||||||
|
out.red = print
|
||||||
|
out.yellow = print
|
||||||
|
out.__call__ = print
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if args.func.__name__ not in ("init_cmd", "fmt_cmd"):
|
if args.func.__name__ not in ("init_cmd", "fmt_cmd"):
|
||||||
if not args.inipath.exists():
|
if not args.inipath.exists():
|
||||||
|
|||||||
@@ -25,11 +25,17 @@ class TestCmdline:
|
|||||||
|
|
||||||
def test_init_not_overwrite(self, capsys):
|
def test_init_not_overwrite(self, capsys):
|
||||||
assert main(["init", "chat.example.org"]) == 0
|
assert main(["init", "chat.example.org"]) == 0
|
||||||
capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
|
assert "created config file" in out.lower()
|
||||||
|
|
||||||
assert main(["init", "chat.example.org"]) == 1
|
assert main(["init", "chat.example.org"]) == 1
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert "path exists" in out.lower()
|
assert "path exists" in out.lower()
|
||||||
|
|
||||||
|
assert main(["init", "chat.example.org", "--force"]) == 0
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert "deleting config file" in out.lower()
|
||||||
|
|
||||||
|
|
||||||
def test_www_folder(example_config, tmp_path):
|
def test_www_folder(example_config, tmp_path):
|
||||||
reporoot = importlib.resources.files(__package__).joinpath("../../../../").resolve()
|
reporoot = importlib.resources.files(__package__).joinpath("../../../../").resolve()
|
||||||
|
|||||||
Reference in New Issue
Block a user