Commit 04585b7b authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

implement mirror

parent 156c7ab3
Loading
Loading
Loading
Loading
+1
Changes for README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ climax is a CLI tool for MaX, Le Moteur d'Affichage XML.
## Prerequisite

- Rye: `curl -sSf https://rye.astral.sh/get | bash`
- gettext

## Dev commands

+35 −6
Changes for src/climax/__main__.py: 35 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ from rich import print
from rich.progress import track
import shutil
from functools import lru_cache
import socket

USER_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax")
USER_DIR.mkdir(exist_ok=True)
@@ -51,6 +52,14 @@ CONFIG_INIT_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
</configuration>"""


def _free_port() -> int:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(("localhost", 0))
    port = s.getsockname()[1]
    s.close()
    return port


class MaXProjectConfig:
    def __init__(self, path_to_config_file: Union[str, Path]):
        self.config_file_path = Path(path_to_config_file).resolve()
@@ -384,9 +393,8 @@ def _sync_max_instance(root_directory: Path):
    cached_download(SAXON_DISTRO, saxon_zip_destination)
    os.makedirs(Path(dot_max_dir, "basex", "repo", "max"), exist_ok=True)
    shutil.copytree(
        Path(USER_DIR, "max", "src", "main"),
        Path(USER_DIR, "max", "src", "main", "webapp"),
        Path(dot_max_dir, "basex", "webapp", "max"),
        dirs_exist_ok=True,
    )
    shutil.copy(
        Path(USER_DIR, "max", "expath-pkg.xml"),
@@ -395,7 +403,14 @@ def _sync_max_instance(root_directory: Path):
    shutil.copytree(
        Path(USER_DIR, "max", "src", "main", "core"),
        Path(dot_max_dir, "basex", "repo", "max", "max"),
        dirs_exist_ok=True,
    )
    shutil.copytree(
        Path(USER_DIR, "max", "src", "main", "bundles", "max-content-html-bundle"),
        Path(dot_max_dir, "basex", "repo", "max-content-html-bundle"),
    )
    shutil.copytree(
        Path(USER_DIR, "max", "src", "main", "bundles", "max-autoroute-bundle"),
        Path(dot_max_dir, "basex", "repo", "max-autoroute-bundle"),
    )

    #
@@ -562,13 +577,27 @@ def mirror(
        Optional[Path], typer.Argument(help=_("chemin vers un dossier"))
    ] = Path(os.getcwd(), "output")
):
    config = max_config()
    # start server on specific port
    port_number = _free_port()
    stop_port = port_number + 1
    start(WEB_HOST, port_number, http_stop_port=stop_port, service=True)
    # copy website
    pywebcopy_config["encoding"] = "utf-8"
    # save_website(url="https://www.website.tld/", project_folder="/my/folder/", project_name="project name")
    start_url = f"http://localhost:{port_number}/{config.languages[0]}/pages/index.html"
    print(start_url)
    try:
        save_website(
            url=start_url,
            project_folder=str(directory),
            project_name=config.title,
        )
    except Exception as e:
        stop(stop_port)
        raise e
    # stop server

    pass
    stop(stop_port)
    print("[green]" + _("Site copié dans {}").format(str(directory)) + "[/green]")


if __name__ == "__main__":