Loading Makefile +1 −1 Changes for Makefile: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ clean: .PHONY:clean build:locales ## construire le paquet rye run pyinstaller src/climax.py --collect-submodules shellingham rye run pyinstaller src/climax.py --strip --noconfirm --collect-submodules shellingham mkdir dist/climax/_internal/climax mkdir dist/climax/_internal/climax/locales cp -r src/climax/locales/* dist/climax/_internal/climax/locales/ Loading src/climax/__main__.py +161 −17 Changes for src/climax/__main__.py: 161 added lines, 17 removed lines. Original line number Diff line number Diff line import subprocess from pathlib import Path from typing import Optional, Union from typing_extensions import Annotated import gettext locales_dir = Path(__file__).parent / "locales" gettext.bindtextdomain("messages", str(locales_dir)) gettext.textdomain("messages") _ = gettext.gettext import requests import os import stat import hashlib import json import platform import typer from rich import print from rich.progress import track import shutil USER_DIR = Path(Path.home(), ".climax") USER_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) Loading @@ -20,15 +29,23 @@ BASEX_DISTRO = "https://files.basex.org/releases/11.1/BaseX111.zip" SAXON_DISTRO = ( "https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/10.8/Saxon-HE-10.8.jar" ) MAX_DISTRO = "https://git.unicaen.fr/chauveau/max-v2-basex-poc/-/archive/master/max-v2-basex-poc-master.zip" MAX_DISTRO = "https://acasa.bontards.com/max-distro.zip" JAVA_DISTROS = { "darwin/arm64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_macos-aarch64_bin.tar.gz", "linux/x86_64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_linux-x64_bin.tar.gz", } WEB_PORT = 8080 BASEX_PORT = 1984 locales_dir = Path(__file__).parent / "locales" gettext.bindtextdomain("messages", str(locales_dir)) gettext.textdomain("messages") _ = gettext.gettext def current_system() -> str: return f"{platform.system()}/{platform.machine()}".lower() app = typer.Typer() def find_jdk(cur_sys: str = None) -> Optional[str]: if not cur_sys: cur_sys = current_system() return JAVA_DISTROS.get(cur_sys, None) def fetch_config_file() -> Path: Loading @@ -37,7 +54,7 @@ def fetch_config_file() -> Path: print( "[red]{}[/red]".format( _( "Ce dossier n'est pas géré par cliMaX. Êtes-vous sur d'être dans le dossier d'une instance de MaX ?" "Ce dossier n'est pas géré par climax. Êtes-vous sur d'être dans le dossier d'une instance de MaX ?" ) ) ) Loading Loading @@ -83,13 +100,54 @@ def cached_download( for data in track( response.iter_content(chunk_size=chunk_size), total=seq_len, description=source, description=os.path.basename(source), ): f.write(data) shutil.copy(cache_path, destination) return True def ensure_java() -> Path: java_bin = shutil.which("java") if not java_bin: cur_sys = current_system() suitable_jdk = find_jdk(cur_sys) if suitable_jdk: destination_folder = Path(USER_DIR, "jdk") if not destination_folder.exists(): destination_archive = Path(USER_DIR, os.path.basename(suitable_jdk)) cached_download(suitable_jdk, destination_archive) unzip(destination_archive, destination_folder) if cur_sys == "linux/x86_64": java_bin = Path(destination_folder, "jdk-22.0.2", "bin", "java") if cur_sys == "darwin/arm64": java_bin = Path( destination_folder, "jdk-22.0.2.jdk", "Contents", "Home", "bin", "java", ) if not java_bin: print( "[red]" + _("Java est requis pour utiliser MaX: https://openjdk.org/install/") + "[/red]" ) raise typer.Exit(code=1) return java_bin def ensure_max() -> Path: destination_folder = Path(USER_DIR, "max") if not destination_folder.exists(): destination_archive = Path(USER_DIR, "max.zip") cached_download(MAX_DISTRO, destination_archive) unzip(destination_archive, destination_folder) return destination_folder def ensure_new_max_directory(directory: Optional[Path]) -> Path: if not directory: directory = os.getcwd() Loading @@ -106,16 +164,20 @@ def ensure_new_max_directory(directory: Optional[Path]) -> Path: return directory app = typer.Typer(help="pouet pouet") @app.command(help=_("Initialisation d'une instance de MaX")) def init( directory: Annotated[ Optional[Path], typer.Argument(help=_("chemin vers un dossier")) ] = os.getcwd(), http_port: int = typer.Option(8080, help=_("port du serveur web")), basex_port: int = typer.Option(1984, help=_("port du serveur basex")), http_port: int = typer.Option(WEB_PORT, help=_("port du serveur web")), basex_port: int = typer.Option(BASEX_PORT, help=_("port du serveur basex")), ): root_directory = ensure_new_max_directory(directory) java_bin = ensure_java() max_path = ensure_max() print( "[bold]" + _("Initialisation d'une instance de MaX dans {}").format(root_directory) Loading @@ -124,9 +186,13 @@ def init( dot_max_dir = Path(root_directory, ".max") dot_max_dir.mkdir(parents=True, exist_ok=False) basex_zip_destination = Path(dot_max_dir, "BaseX.zip") cached_download(BASEX_DISTRO, basex_zip_destination) unzip(basex_zip_destination, dot_max_dir) os.chmod( Path(dot_max_dir, "basex", "bin", "basexhttp"), stat.S_IEXEC | stat.S_IREAD ) saxon_zip_destination = Path( dot_max_dir, "basex", "lib", "custom", "Saxon-HE-10.8.jar" ) Loading @@ -137,6 +203,7 @@ def init( "basex_distro": BASEX_DISTRO, "saxon_distro": SAXON_DISTRO, "max_distro": MAX_DISTRO, "java_bin": java_bin, } with open(Path(root_directory, CLIMAX_CONFIG_FILE), "w") as f: json.dump(cli_config, f, indent=2) Loading @@ -144,29 +211,106 @@ def init( with open(Path(root_directory, ".gitignore"), "w") as f: f.write(".max\n") os.makedirs(Path(dot_max_dir, "basex", "repo", "max"), exist_ok=True) shutil.copytree( Path(USER_DIR, "max", "src", "main"), Path(dot_max_dir, "basex", "webapp", "max"), ) shutil.copy( Path(USER_DIR, "max", "expath-pkg.xml"), Path(dot_max_dir, "basex", "repo", "max", "expath-pkg.xml"), ) shutil.copytree( Path(USER_DIR, "max", "src", "main", "core"), Path(dot_max_dir, "basex", "repo", "max", "max"), ) 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"), ) shutil.copytree( Path(USER_DIR, "max", "src", "main", "bundles", "max-tei-bundle"), Path(dot_max_dir, "basex", "repo", "max-tei-bundle"), ) print( "[bold]" + _("L'instance de MaX est prête dans {}").format(root_directory) + "[/bold]" ) @app.command( help=_("Installe une édition de démonstration dans l'instance de MaX en cours") ) def demo(): if typer.confirm( _("Voulez-vous afficher le dossier {} ?").format(root_directory), default=True _("Voulez-vous installer une édition de démonstration ?"), default=False ): typer.launch(str(root_directory), locate=True) config = read_climax_config() cur_dir = os.getcwd() shutil.copytree( Path(USER_DIR, "max", "fixtures", "max"), Path(cur_dir, ".max", "basex", "data", "max"), ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "content_html"), Path(cur_dir, "content_html"), ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "templates"), Path(cur_dir, "templates") ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "autoroute"), Path(cur_dir, "autoroute") ) shutil.copy( Path(USER_DIR, "max", "fixtures", "config.xml"), Path(cur_dir, "config.xml") ) print("[green]" + _("édition de démonstration installée") + "[/green]") print(_("Vous pouvez démarrer MaX avec la commande [bold]climax run[/bold]")) @app.command(help=_("Démarre l'instance de MaX du dossier en cours")) def run(): config = read_climax_config() print("[green]" + _("Démarrage de MaX...") + "[/green]") subprocess.run( [ Path( os.getcwd(), ".max", "basex", "bin", "basexhttp", ), f"-h{config.get('http_port')}", ] ) @app.command() @app.command(help=_("Efface le cache de climax")) def clear_cache(): for p in CACHE_DIR.iterdir(): if p.is_file(): p.unlink(missing_ok=True) @app.command() def config_get(): @app.command(help=_("Affiche la configuration pour l'instance de MaX en cours")) def getconfig(): config = read_climax_config() print(config) @app.command(help=_("Modifie la configuration de l'instance de MaX en cours")) def setconfig(key: str, value): config = read_climax_config() config[key] = value write_climax_config(config) if __name__ == "__main__": app() src/climax/locales/en/LC_MESSAGES/messages.mo +64 B (441 B) File changed.No diff preview for this file type. View original file View changed file src/climax/locales/en/LC_MESSAGES/messages.po +3 Changes for src/climax/locales/en/LC_MESSAGES/messages.po: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -10,3 +10,6 @@ msgstr "The folder is not empty, please choose another one." msgid "Initialisation d'une instance de MaX" msgstr "New MaX instance initialization" msgid "chemin vers un dossier" msgstr "path to a folder" No newline at end of file src/climax/locales/fr/LC_MESSAGES/messages.mo +276 B (1.27 KiB) File changed.No diff preview for this file type. View original file View changed file Loading
Makefile +1 −1 Changes for Makefile: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ clean: .PHONY:clean build:locales ## construire le paquet rye run pyinstaller src/climax.py --collect-submodules shellingham rye run pyinstaller src/climax.py --strip --noconfirm --collect-submodules shellingham mkdir dist/climax/_internal/climax mkdir dist/climax/_internal/climax/locales cp -r src/climax/locales/* dist/climax/_internal/climax/locales/ Loading
src/climax/__main__.py +161 −17 Changes for src/climax/__main__.py: 161 added lines, 17 removed lines. Original line number Diff line number Diff line import subprocess from pathlib import Path from typing import Optional, Union from typing_extensions import Annotated import gettext locales_dir = Path(__file__).parent / "locales" gettext.bindtextdomain("messages", str(locales_dir)) gettext.textdomain("messages") _ = gettext.gettext import requests import os import stat import hashlib import json import platform import typer from rich import print from rich.progress import track import shutil USER_DIR = Path(Path.home(), ".climax") USER_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) Loading @@ -20,15 +29,23 @@ BASEX_DISTRO = "https://files.basex.org/releases/11.1/BaseX111.zip" SAXON_DISTRO = ( "https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/10.8/Saxon-HE-10.8.jar" ) MAX_DISTRO = "https://git.unicaen.fr/chauveau/max-v2-basex-poc/-/archive/master/max-v2-basex-poc-master.zip" MAX_DISTRO = "https://acasa.bontards.com/max-distro.zip" JAVA_DISTROS = { "darwin/arm64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_macos-aarch64_bin.tar.gz", "linux/x86_64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_linux-x64_bin.tar.gz", } WEB_PORT = 8080 BASEX_PORT = 1984 locales_dir = Path(__file__).parent / "locales" gettext.bindtextdomain("messages", str(locales_dir)) gettext.textdomain("messages") _ = gettext.gettext def current_system() -> str: return f"{platform.system()}/{platform.machine()}".lower() app = typer.Typer() def find_jdk(cur_sys: str = None) -> Optional[str]: if not cur_sys: cur_sys = current_system() return JAVA_DISTROS.get(cur_sys, None) def fetch_config_file() -> Path: Loading @@ -37,7 +54,7 @@ def fetch_config_file() -> Path: print( "[red]{}[/red]".format( _( "Ce dossier n'est pas géré par cliMaX. Êtes-vous sur d'être dans le dossier d'une instance de MaX ?" "Ce dossier n'est pas géré par climax. Êtes-vous sur d'être dans le dossier d'une instance de MaX ?" ) ) ) Loading Loading @@ -83,13 +100,54 @@ def cached_download( for data in track( response.iter_content(chunk_size=chunk_size), total=seq_len, description=source, description=os.path.basename(source), ): f.write(data) shutil.copy(cache_path, destination) return True def ensure_java() -> Path: java_bin = shutil.which("java") if not java_bin: cur_sys = current_system() suitable_jdk = find_jdk(cur_sys) if suitable_jdk: destination_folder = Path(USER_DIR, "jdk") if not destination_folder.exists(): destination_archive = Path(USER_DIR, os.path.basename(suitable_jdk)) cached_download(suitable_jdk, destination_archive) unzip(destination_archive, destination_folder) if cur_sys == "linux/x86_64": java_bin = Path(destination_folder, "jdk-22.0.2", "bin", "java") if cur_sys == "darwin/arm64": java_bin = Path( destination_folder, "jdk-22.0.2.jdk", "Contents", "Home", "bin", "java", ) if not java_bin: print( "[red]" + _("Java est requis pour utiliser MaX: https://openjdk.org/install/") + "[/red]" ) raise typer.Exit(code=1) return java_bin def ensure_max() -> Path: destination_folder = Path(USER_DIR, "max") if not destination_folder.exists(): destination_archive = Path(USER_DIR, "max.zip") cached_download(MAX_DISTRO, destination_archive) unzip(destination_archive, destination_folder) return destination_folder def ensure_new_max_directory(directory: Optional[Path]) -> Path: if not directory: directory = os.getcwd() Loading @@ -106,16 +164,20 @@ def ensure_new_max_directory(directory: Optional[Path]) -> Path: return directory app = typer.Typer(help="pouet pouet") @app.command(help=_("Initialisation d'une instance de MaX")) def init( directory: Annotated[ Optional[Path], typer.Argument(help=_("chemin vers un dossier")) ] = os.getcwd(), http_port: int = typer.Option(8080, help=_("port du serveur web")), basex_port: int = typer.Option(1984, help=_("port du serveur basex")), http_port: int = typer.Option(WEB_PORT, help=_("port du serveur web")), basex_port: int = typer.Option(BASEX_PORT, help=_("port du serveur basex")), ): root_directory = ensure_new_max_directory(directory) java_bin = ensure_java() max_path = ensure_max() print( "[bold]" + _("Initialisation d'une instance de MaX dans {}").format(root_directory) Loading @@ -124,9 +186,13 @@ def init( dot_max_dir = Path(root_directory, ".max") dot_max_dir.mkdir(parents=True, exist_ok=False) basex_zip_destination = Path(dot_max_dir, "BaseX.zip") cached_download(BASEX_DISTRO, basex_zip_destination) unzip(basex_zip_destination, dot_max_dir) os.chmod( Path(dot_max_dir, "basex", "bin", "basexhttp"), stat.S_IEXEC | stat.S_IREAD ) saxon_zip_destination = Path( dot_max_dir, "basex", "lib", "custom", "Saxon-HE-10.8.jar" ) Loading @@ -137,6 +203,7 @@ def init( "basex_distro": BASEX_DISTRO, "saxon_distro": SAXON_DISTRO, "max_distro": MAX_DISTRO, "java_bin": java_bin, } with open(Path(root_directory, CLIMAX_CONFIG_FILE), "w") as f: json.dump(cli_config, f, indent=2) Loading @@ -144,29 +211,106 @@ def init( with open(Path(root_directory, ".gitignore"), "w") as f: f.write(".max\n") os.makedirs(Path(dot_max_dir, "basex", "repo", "max"), exist_ok=True) shutil.copytree( Path(USER_DIR, "max", "src", "main"), Path(dot_max_dir, "basex", "webapp", "max"), ) shutil.copy( Path(USER_DIR, "max", "expath-pkg.xml"), Path(dot_max_dir, "basex", "repo", "max", "expath-pkg.xml"), ) shutil.copytree( Path(USER_DIR, "max", "src", "main", "core"), Path(dot_max_dir, "basex", "repo", "max", "max"), ) 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"), ) shutil.copytree( Path(USER_DIR, "max", "src", "main", "bundles", "max-tei-bundle"), Path(dot_max_dir, "basex", "repo", "max-tei-bundle"), ) print( "[bold]" + _("L'instance de MaX est prête dans {}").format(root_directory) + "[/bold]" ) @app.command( help=_("Installe une édition de démonstration dans l'instance de MaX en cours") ) def demo(): if typer.confirm( _("Voulez-vous afficher le dossier {} ?").format(root_directory), default=True _("Voulez-vous installer une édition de démonstration ?"), default=False ): typer.launch(str(root_directory), locate=True) config = read_climax_config() cur_dir = os.getcwd() shutil.copytree( Path(USER_DIR, "max", "fixtures", "max"), Path(cur_dir, ".max", "basex", "data", "max"), ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "content_html"), Path(cur_dir, "content_html"), ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "templates"), Path(cur_dir, "templates") ) shutil.copytree( Path(USER_DIR, "max", "fixtures", "autoroute"), Path(cur_dir, "autoroute") ) shutil.copy( Path(USER_DIR, "max", "fixtures", "config.xml"), Path(cur_dir, "config.xml") ) print("[green]" + _("édition de démonstration installée") + "[/green]") print(_("Vous pouvez démarrer MaX avec la commande [bold]climax run[/bold]")) @app.command(help=_("Démarre l'instance de MaX du dossier en cours")) def run(): config = read_climax_config() print("[green]" + _("Démarrage de MaX...") + "[/green]") subprocess.run( [ Path( os.getcwd(), ".max", "basex", "bin", "basexhttp", ), f"-h{config.get('http_port')}", ] ) @app.command() @app.command(help=_("Efface le cache de climax")) def clear_cache(): for p in CACHE_DIR.iterdir(): if p.is_file(): p.unlink(missing_ok=True) @app.command() def config_get(): @app.command(help=_("Affiche la configuration pour l'instance de MaX en cours")) def getconfig(): config = read_climax_config() print(config) @app.command(help=_("Modifie la configuration de l'instance de MaX en cours")) def setconfig(key: str, value): config = read_climax_config() config[key] = value write_climax_config(config) if __name__ == "__main__": app()
src/climax/locales/en/LC_MESSAGES/messages.mo +64 B (441 B) File changed.No diff preview for this file type. View original file View changed file
src/climax/locales/en/LC_MESSAGES/messages.po +3 Changes for src/climax/locales/en/LC_MESSAGES/messages.po: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -10,3 +10,6 @@ msgstr "The folder is not empty, please choose another one." msgid "Initialisation d'une instance de MaX" msgstr "New MaX instance initialization" msgid "chemin vers un dossier" msgstr "path to a folder" No newline at end of file
src/climax/locales/fr/LC_MESSAGES/messages.mo +276 B (1.27 KiB) File changed.No diff preview for this file type. View original file View changed file