mirror of
https://github.com/chatmail/relay.git
synced 2026-05-13 09:24:43 +00:00
add webdev sub command
This commit is contained in:
@@ -413,7 +413,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
|
||||
|
||||
pkg_root = importlib.resources.files(__package__)
|
||||
chatmail_ini = pkg_root.joinpath("../../../chatmail.ini").resolve()
|
||||
config = read_config(chatmail_ini, mailname=mail_domain)
|
||||
config = read_config(chatmail_ini)
|
||||
check_config(config)
|
||||
www_path = pkg_root.joinpath("../../../www").resolve()
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ along with command line option and subcommand parsing.
|
||||
"""
|
||||
import importlib.resources
|
||||
import argparse
|
||||
import subprocess
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import iniconfig
|
||||
@@ -70,8 +72,17 @@ def get_parser():
|
||||
|
||||
install_parser = add_subcommand(subparsers, install_cmd)
|
||||
add_config_option(install_parser)
|
||||
install_parser.add_argument(
|
||||
"--dry-run",
|
||||
dest="dry_run",
|
||||
action="store_true",
|
||||
help="don't actually modify the server",
|
||||
)
|
||||
|
||||
add_subcommand(subparsers, webdev_cmd)
|
||||
return parser
|
||||
|
||||
|
||||
def write_initial_config(inipath, mailname, out):
|
||||
inidir = importlib.resources.files(__package__).joinpath("ini")
|
||||
content = inidir.joinpath("chatmail.ini.f").read_text().format(mailname=mailname)
|
||||
@@ -102,20 +113,38 @@ def write_initial_config(inipath, mailname, out):
|
||||
def init_cmd(args, out):
|
||||
"""Initialize chatmail config file."""
|
||||
if args.chatmail_ini.exists():
|
||||
out.red(f"Path exists, not modifying: {args.xdcget_ini}")
|
||||
out.red(f"Path exists, not modifying: {args.chatmail_ini}")
|
||||
raise SystemExit(1)
|
||||
write_initial_config(args.chatmail_ini, args.chatmail_domain, out)
|
||||
|
||||
|
||||
def install_cmd(args, out):
|
||||
"""Install or update chatmail services on the remote server. """
|
||||
"""Install or update chatmail services on the remote server."""
|
||||
import pyinfra
|
||||
|
||||
try:
|
||||
config = read_config(args.chatmail_ini)
|
||||
except Exception as ex:
|
||||
out.red(ex)
|
||||
raise SystemExit(1)
|
||||
|
||||
XXX
|
||||
popen_args = ["pyinfra"]
|
||||
if args.dry_run:
|
||||
popen_args.append("--dry")
|
||||
popen_args.extend(["--ssh-user", "root", config.mailname])
|
||||
popen_args.append("deploy-chatmail/src/deploy_chatmail/deploy.py")
|
||||
|
||||
out(f"{os.getcwd()} $ {' '.join(popen_args)}")
|
||||
env = os.environ.copy()
|
||||
env["CHATMAIL_DOMAIN"] = config.mailname
|
||||
subprocess.check_call(popen_args, env=env)
|
||||
|
||||
|
||||
def webdev_cmd(args, out):
|
||||
"""Run web development loop for static local web pages."""
|
||||
from .www import main
|
||||
|
||||
main()
|
||||
|
||||
|
||||
def main(args=None):
|
||||
|
||||
@@ -66,12 +66,12 @@ def _build_webpages(src_dir, build_dir, config):
|
||||
|
||||
|
||||
def main():
|
||||
chatmail_domain = "example.testrun.org"
|
||||
path = importlib.resources.files(__package__)
|
||||
reporoot = path.joinpath("../../../").resolve()
|
||||
inipath = reporoot.joinpath("chatmail.ini")
|
||||
config = read_config(inipath, mailname=chatmail_domain)
|
||||
config["webdev"] = True
|
||||
config = read_config(inipath)
|
||||
config.webdev = True
|
||||
assert config.mailname
|
||||
www_path = reporoot.joinpath("www")
|
||||
src_path = www_path.joinpath("src")
|
||||
stats = None
|
||||
|
||||
Reference in New Issue
Block a user