Loading pyproject.toml +4 −1 Changes for pyproject.toml: 4 added lines, 1 removed line. Original line number Diff line number Diff line [project] name = "climax-CERTIC" version = "0.1.10" version = "0.1.11" description = "CLI tool for MaX, Le Moteur d'Affichage XML." readme = "README.md" license = {text = "CECILL-C"} Loading @@ -20,6 +20,9 @@ dependencies = [ "lxml>=5.3.0", "lxml-html-clean>=0.4.1", "geler-certic>=0.4.1", "bottle>=0.13.2", "oora>=0.2.3", "simple-term-menu>=1.6.6", ] [dependency-groups] Loading src/climax/__main__.py +49 −220 Changes for src/climax/__main__.py: 49 added lines, 220 removed lines. Original line number Diff line number Diff line import subprocess from pathlib import Path from typing import Optional, Union, Dict, Iterator from typing import Optional, Union, Iterator from typing_extensions import Annotated import gettext Loading @@ -11,6 +11,22 @@ _ = gettext.gettext from bs4 import BeautifulSoup # noqa: E402 from .eggs import get_yolk # noqa: E402 from .model import MaXProjectConfig # noqa: E402 from .config import ( # noqa: E402 WELCOME_PAGE, USER_MAX_DIR, CACHE_DIR, MAX_CONFIG_FILE, BASEX_DISTRO, SAXON_DISTRO, MAX_DISTRO, CURRENT_MAX_DISTRO_DIR, JAVA_DISTROS, WEB_PORT, WEB_HOST, BASEX_PORT, STOP_PORT, ) import geler # noqa: E402 import requests # noqa: E402 import os # noqa: E402 Loading @@ -24,59 +40,10 @@ from rich.table import Table # noqa: E402 import shutil # noqa: E402 from functools import lru_cache # noqa: E402 import socket # noqa: E402 from .model import db, MaxInstall # noqa: E402 # from simple_term_menu import TerminalMenu # noqa: E402 WELCOME_PAGE = """ <h1>Bienvenue dans MaX !</h1> <p> Vous pouvez personnaliser cette page en éditant le fichier content_html/fr/index.html </p> <p> Retrouvez la documentation de MaX à l'adresse suivante: <a href="https://pdn-certic.pages.unicaen.fr/max-documentation/"> https://pdn-certic.pages.unicaen.fr/max-documentation/ </a> </p> """ USER_MAX_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_MAX_DIR = Path(USER_MAX_DIR) USER_MAX_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_MAX_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) MAX_CONFIG_FILE = "config.xml" 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/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip" CURRENT_MAX_DISTRO_DIR = os.path.splitext(os.path.basename(MAX_DISTRO))[0] 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", "windows/amd64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_windows-x64_bin.zip", } WEB_PORT = 8080 WEB_HOST = "127.0.0.1" BASEX_PORT = 1984 STOP_PORT = 8081 CONFIG_INIT_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://certic.unicaen.fr/max/ns/1.0" env="dev" vocabulary-bundle="max-dumb-xml"> <languages> <language>fr</language> <language>en</language> </languages> <title>mon Corpus Numérique</title> <bundles> <bundle name="max-dumb-xml"/> <bundle name="max-export"/> <bundle name="max-dev"/> </bundles> </configuration> """ climax_db = db() def _port_is_in_use(port: int) -> bool: Loading Loading @@ -110,172 +77,6 @@ def _scan_dir(start_path: Union[str, Path], extension: str = None) -> Iterator[P yield Path(os.path.join(root, file)).resolve() class MaXProjectConfig: def __init__(self, path_to_config_file: Union[str, Path]): self.config_file_path = Path(path_to_config_file).resolve() if os.path.isfile(self.config_file_path): with open(self.config_file_path, "r") as f: self.xml_soup = BeautifulSoup(f, "xml") else: self.xml_soup = BeautifulSoup(CONFIG_INIT_TEMPLATE, "xml") first = self.xml_soup.find() if first and first.name != "configuration": raise ValueError( _("{} is not a MaX configuration file").format(self.config_file_path) ) conf = self.xml_soup.find("configuration") if not conf: conf = self.xml_soup.new_tag("configuration") conf["env"] = "dev" conf["vocabulary-bundle"] = "max-dumb-xml" conf["xmlns"] = "http://certic.unicaen.fr/max/ns/1.0" self.xml_soup.append(conf) @property def available_bundles(self) -> Dict[str, Dict]: active_bundles = self.bundles available_bundles = {} available_bundles_xml = Path( os.path.dirname(self.config_file_path), ".max", "resources", "available-bundles.xml", ) if available_bundles_xml.is_file(): with open(available_bundles_xml, "r") as file_handle: soup = BeautifulSoup(file_handle.read(), "xml") for b in soup.find_all("bundle"): available_bundles[b["name"]] = { "name": b["name"], "url": b["url"] if b.has_attr("url") else "", "description": b["description"] if b.has_attr("description") else "", "active": b["name"] in active_bundles.keys(), "vocabulary": True if ( b.has_attr("vocabulary-bundle") and b["vocabulary-bundle"] == "true" ) else False, } return dict(sorted(available_bundles.items())) @property def max_version(self) -> str: expath_pkg = Path( os.path.dirname(self.config_file_path), ".max", "resources", "expath-pkg.xml", ) if expath_pkg.is_file(): with open(expath_pkg, "r") as expath_handle: soup = BeautifulSoup(expath_handle.read(), "xml") package = soup.find("package") if package: return package["version"] return "" @property def env(self) -> str: conf = self.xml_soup.find("configuration") val = conf.get("env", "dev") return str(val) @env.setter def env(self, value: str): conf = self.xml_soup.find("configuration") conf["env"] = value @property def vocabulary_bundle(self) -> str: conf = self.xml_soup.find("configuration") val = conf.get("vocabulary-bundle", "max-dumb-xml") return str(val) @vocabulary_bundle.setter def vocabulary_bundle(self, value): conf = self.xml_soup.find("configuration") conf["vocabulary-bundle"] = value @property def title(self) -> str: val = "untitled" conf = self.xml_soup.find("configuration") xml_node = conf.find("title") if xml_node: val = xml_node.text.strip() return str(val) @title.setter def title(self, value): conf = self.xml_soup.find("configuration") xml_node = conf.find("title") if not xml_node: xml_node = self.xml_soup.new_tag("title") conf.append(xml_node) xml_node.string = value @property def languages(self) -> list[str]: vals = [] conf = self.xml_soup.find("configuration") nodes = conf.find("languages") if nodes: for language in nodes.find_all("language"): vals.append(language.text.strip()) return vals @languages.setter def languages(self, languages: list[str]): conf = self.xml_soup.find("configuration") nodes = conf.find("languages") if not nodes: nodes = self.xml_soup.new_tag("languages") conf.append(nodes) nodes.clear() for language in languages: language_tag = self.xml_soup.new_tag("language") language_tag.string = language nodes.append(language_tag) @property def bundles(self) -> Dict[str, Dict]: vals = {} conf = self.xml_soup.find("configuration") nodes = conf.find("bundles") if nodes: for bundle in nodes.find_all("bundle"): vals[bundle["name"]] = { "name": bundle["name"], "url": bundle["url"] if bundle.has_attr("url") else "", } return vals @bundles.setter def bundles(self, bundles: Dict[str, Dict]): conf = self.xml_soup.find("configuration") nodes = conf.find("bundles") if not nodes: nodes = self.xml_soup.new_tag("bundles") conf.append(nodes) nodes.clear() for bundle_name, bundle_dict in bundles.items(): bundle_tag = self.xml_soup.new_tag("bundle") bundle_tag["name"] = bundle_dict["name"] if bundle_dict.get("url"): bundle_tag["url"] = bundle_dict["url"] nodes.append(bundle_tag) def __str__(self): return self.xml_soup.prettify() def write(self): with open(self.config_file_path, "w") as f: f.write(str(self)) @lru_cache() def current_system() -> str: return f"{platform.system()}/{platform.machine()}".lower() Loading Loading @@ -522,7 +323,8 @@ def _install_new_max_instance(root_directory: Path): welcome_page = Path(root_directory, "content_html", "fr", "index.html") with open(welcome_page, "w") as f: f.write(WELCOME_PAGE) climax_db.save(MaxInstall(None, str(root_directory.resolve()))) climax_db.commit() print( "[bold]" + _("La nouvelle instance de MaX est prête dans {}").format(root_directory) Loading Loading @@ -591,6 +393,8 @@ def sync( if is_max: _sync_max_instance(root_directory) climax_db.save(MaxInstall(None, str(root_directory.resolve()))) climax_db.commit() else: print( _( Loading Loading @@ -958,6 +762,31 @@ def templates_list(): print(item) @app.command(help=_("Liste les projets gérés par climax")) def projects(): console = Console() table = Table(_("Projet"), _("Chemin"), show_lines=True) for max_install in climax_db.projects(): if max_install.exists(): config = max_install.config() table.add_row(config.title, max_install.path) console.print(table) # options = [] # for max_install in climax_db.projects(): # options.append(max_install.path) # terminal_menu = TerminalMenu(options) # menu_entry_index = terminal_menu.show() # subprocess.run(["cd", options[menu_entry_index]], shell=True) @app.command(help=_("Application web (test)")) def ui(max_dir: str = None): from .gui import app app.max_directory = max_dir app.run(port=8888, reloader=True, debug=True) get_yolk() if __name__ == "__main__": Loading src/climax/config.py +64 Changes for src/climax/config.py: 64 added lines, 0 removed lines. Original line number Diff line number Diff line import os import json from pathlib import Path from typing import List, Dict from requests import get from functools import cache GITLAB_API_READ_TOKEN = "glpat-5BCYCid1WaxxBgax-7VW" WELCOME_PAGE = """ <h1>Bienvenue dans MaX !</h1> <p> Vous pouvez personnaliser cette page en éditant le fichier content_html/fr/index.html </p> <p> Retrouvez la documentation de MaX à l'adresse suivante: <a href="https://pdn-certic.pages.unicaen.fr/max-documentation/"> https://pdn-certic.pages.unicaen.fr/max-documentation/ </a> </p> """ USER_MAX_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_MAX_DIR = Path(USER_MAX_DIR) USER_MAX_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_MAX_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) MAX_CONFIG_FILE = "config.xml" BASEX_DISTRO = "https://files.basex.org/releases/11.7/BaseX117.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/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip" CURRENT_MAX_DISTRO_DIR = os.path.splitext(os.path.basename(MAX_DISTRO))[0] 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", "windows/amd64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_windows-x64_bin.zip", } WEB_PORT = 8080 WEB_HOST = "127.0.0.1" BASEX_PORT = 1984 STOP_PORT = 8081 @cache def max_releases() -> List[Dict]: try: response = get( "https://git.unicaen.fr/api/v4/projects/2429/releases", headers={"PRIVATE-TOKEN": GITLAB_API_READ_TOKEN}, ) if response.ok: return json.loads(response.content) except: # noqa: E722 pass with open( Path(os.path.dirname(os.path.realpath(__file__)), "max_releases.json") ) as f: return json.load(f) src/climax/gui.py +18 Changes for src/climax/gui.py: 18 added lines, 0 removed lines. Original line number Diff line number Diff line from bottle import Bottle from pathlib import Path from .model import MaXProjectConfig app = Bottle() @app.get("/") def home(): return f"HomePage {app.max_directory}" @app.get("/conf") def config(): conf_path = Path(app.max_directory, "config.xml") print(conf_path) conf = MaXProjectConfig(conf_path) return conf.available_bundles src/climax/max_releases.json +1 Changes for src/climax/max_releases.json: 1 added line, 0 removed lines. Original line number Diff line number Diff line [{"name":"0.0.2-alpha","tag_name":"0.0.2-alpha","description":"","created_at":"2025-03-10T14:38:17.672+01:00","released_at":"2025-03-10T14:38:17.672+01:00","upcoming_release":false,"author":{"id":11,"username":"chauveau","name":"Jerome Chauveau","state":"active","locked":false,"avatar_url":"https://secure.gravatar.com/avatar/bb32beebd4915ca92c58ea8282b2d7270f01132b660ce645db5b17a0002029c0?s=80\u0026d=identicon","web_url":"https://git.unicaen.fr/chauveau"},"commit":{"id":"76b83bb3d2650e2c1be8705646a453ea86b36532","short_id":"76b83bb3","created_at":"2025-03-10T14:37:06.000+01:00","parent_ids":["57ccde26d1c7329e1929ea7269f00d6b61346d87"],"title":"rng fix + basex 11.7 + max-db url update","message":"rng fix + basex 11.7 + max-db url update\n","author_name":"Jérôme Chauveau","author_email":"jerome.chauveau@unicaen.fr","authored_date":"2025-03-10T14:37:06.000+01:00","committer_name":"Jérôme Chauveau","committer_email":"jerome.chauveau@unicaen.fr","committed_date":"2025-03-10T14:37:06.000+01:00","trailers":{},"extended_trailers":{},"web_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/commit/76b83bb3d2650e2c1be8705646a453ea86b36532"},"commit_path":"/pdn-certic/max-v2/-/commit/76b83bb3d2650e2c1be8705646a453ea86b36532","tag_path":"/pdn-certic/max-v2/-/tags/0.0.2-alpha","assets":{"count":4,"sources":[{"format":"zip","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip"},{"format":"tar.gz","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar.gz"},{"format":"tar.bz2","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar.bz2"},{"format":"tar","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar"}],"links":[]},"evidences":[{"sha":"a100be82705a5fd1030bc32747f11e7bdbd1615e122d","filepath":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha/evidences/515.json","collected_at":"2025-03-10T14:38:17.734+01:00"}],"_links":{"closed_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.2-alpha\u0026scope=all\u0026state=closed","closed_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=closed","edit_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha/edit","merged_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=merged","opened_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.2-alpha\u0026scope=all\u0026state=opened","opened_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=opened","self":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha"}},{"name":"0.0.1-alpha","tag_name":"0.0.1-alpha","description":"Release de test.","created_at":"2024-10-09T15:58:45.946+02:00","released_at":"2024-10-09T15:58:45.946+02:00","upcoming_release":false,"author":{"id":11,"username":"chauveau","name":"Jerome Chauveau","state":"active","locked":false,"avatar_url":"https://secure.gravatar.com/avatar/bb32beebd4915ca92c58ea8282b2d7270f01132b660ce645db5b17a0002029c0?s=80\u0026d=identicon","web_url":"https://git.unicaen.fr/chauveau"},"commit":{"id":"e1f216d98ce827b021050e8b1f28156eb1d6a49c","short_id":"e1f216d9","created_at":"2024-10-09T15:56:32.000+02:00","parent_ids":["401c3ff10290aceddb7b81c9ef8d9f85884eb54e"],"title":"catch repo:not found exception","message":"catch repo:not found exception\n","author_name":"Jérôme Chauveau","author_email":"jerome.chauveau@unicaen.fr","authored_date":"2024-10-09T15:56:32.000+02:00","committer_name":"Jérôme Chauveau","committer_email":"jerome.chauveau@unicaen.fr","committed_date":"2024-10-09T15:56:32.000+02:00","trailers":{},"extended_trailers":{},"web_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/commit/e1f216d98ce827b021050e8b1f28156eb1d6a49c"},"commit_path":"/pdn-certic/max-v2/-/commit/e1f216d98ce827b021050e8b1f28156eb1d6a49c","tag_path":"/pdn-certic/max-v2/-/tags/0.0.1-alpha","assets":{"count":4,"sources":[{"format":"zip","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.zip"},{"format":"tar.gz","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar.gz"},{"format":"tar.bz2","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar.bz2"},{"format":"tar","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar"}],"links":[]},"evidences":[{"sha":"17b0b81d3fdc0ffe172ea3ec1fb033f629bffa5d2e0d","filepath":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha/evidences/388.json","collected_at":"2024-10-09T15:58:46.087+02:00"}],"_links":{"closed_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.1-alpha\u0026scope=all\u0026state=closed","closed_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=closed","edit_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha/edit","merged_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=merged","opened_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.1-alpha\u0026scope=all\u0026state=opened","opened_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=opened","self":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha"}}] No newline at end of file Loading
pyproject.toml +4 −1 Changes for pyproject.toml: 4 added lines, 1 removed line. Original line number Diff line number Diff line [project] name = "climax-CERTIC" version = "0.1.10" version = "0.1.11" description = "CLI tool for MaX, Le Moteur d'Affichage XML." readme = "README.md" license = {text = "CECILL-C"} Loading @@ -20,6 +20,9 @@ dependencies = [ "lxml>=5.3.0", "lxml-html-clean>=0.4.1", "geler-certic>=0.4.1", "bottle>=0.13.2", "oora>=0.2.3", "simple-term-menu>=1.6.6", ] [dependency-groups] Loading
src/climax/__main__.py +49 −220 Changes for src/climax/__main__.py: 49 added lines, 220 removed lines. Original line number Diff line number Diff line import subprocess from pathlib import Path from typing import Optional, Union, Dict, Iterator from typing import Optional, Union, Iterator from typing_extensions import Annotated import gettext Loading @@ -11,6 +11,22 @@ _ = gettext.gettext from bs4 import BeautifulSoup # noqa: E402 from .eggs import get_yolk # noqa: E402 from .model import MaXProjectConfig # noqa: E402 from .config import ( # noqa: E402 WELCOME_PAGE, USER_MAX_DIR, CACHE_DIR, MAX_CONFIG_FILE, BASEX_DISTRO, SAXON_DISTRO, MAX_DISTRO, CURRENT_MAX_DISTRO_DIR, JAVA_DISTROS, WEB_PORT, WEB_HOST, BASEX_PORT, STOP_PORT, ) import geler # noqa: E402 import requests # noqa: E402 import os # noqa: E402 Loading @@ -24,59 +40,10 @@ from rich.table import Table # noqa: E402 import shutil # noqa: E402 from functools import lru_cache # noqa: E402 import socket # noqa: E402 from .model import db, MaxInstall # noqa: E402 # from simple_term_menu import TerminalMenu # noqa: E402 WELCOME_PAGE = """ <h1>Bienvenue dans MaX !</h1> <p> Vous pouvez personnaliser cette page en éditant le fichier content_html/fr/index.html </p> <p> Retrouvez la documentation de MaX à l'adresse suivante: <a href="https://pdn-certic.pages.unicaen.fr/max-documentation/"> https://pdn-certic.pages.unicaen.fr/max-documentation/ </a> </p> """ USER_MAX_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_MAX_DIR = Path(USER_MAX_DIR) USER_MAX_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_MAX_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) MAX_CONFIG_FILE = "config.xml" 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/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip" CURRENT_MAX_DISTRO_DIR = os.path.splitext(os.path.basename(MAX_DISTRO))[0] 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", "windows/amd64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_windows-x64_bin.zip", } WEB_PORT = 8080 WEB_HOST = "127.0.0.1" BASEX_PORT = 1984 STOP_PORT = 8081 CONFIG_INIT_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://certic.unicaen.fr/max/ns/1.0" env="dev" vocabulary-bundle="max-dumb-xml"> <languages> <language>fr</language> <language>en</language> </languages> <title>mon Corpus Numérique</title> <bundles> <bundle name="max-dumb-xml"/> <bundle name="max-export"/> <bundle name="max-dev"/> </bundles> </configuration> """ climax_db = db() def _port_is_in_use(port: int) -> bool: Loading Loading @@ -110,172 +77,6 @@ def _scan_dir(start_path: Union[str, Path], extension: str = None) -> Iterator[P yield Path(os.path.join(root, file)).resolve() class MaXProjectConfig: def __init__(self, path_to_config_file: Union[str, Path]): self.config_file_path = Path(path_to_config_file).resolve() if os.path.isfile(self.config_file_path): with open(self.config_file_path, "r") as f: self.xml_soup = BeautifulSoup(f, "xml") else: self.xml_soup = BeautifulSoup(CONFIG_INIT_TEMPLATE, "xml") first = self.xml_soup.find() if first and first.name != "configuration": raise ValueError( _("{} is not a MaX configuration file").format(self.config_file_path) ) conf = self.xml_soup.find("configuration") if not conf: conf = self.xml_soup.new_tag("configuration") conf["env"] = "dev" conf["vocabulary-bundle"] = "max-dumb-xml" conf["xmlns"] = "http://certic.unicaen.fr/max/ns/1.0" self.xml_soup.append(conf) @property def available_bundles(self) -> Dict[str, Dict]: active_bundles = self.bundles available_bundles = {} available_bundles_xml = Path( os.path.dirname(self.config_file_path), ".max", "resources", "available-bundles.xml", ) if available_bundles_xml.is_file(): with open(available_bundles_xml, "r") as file_handle: soup = BeautifulSoup(file_handle.read(), "xml") for b in soup.find_all("bundle"): available_bundles[b["name"]] = { "name": b["name"], "url": b["url"] if b.has_attr("url") else "", "description": b["description"] if b.has_attr("description") else "", "active": b["name"] in active_bundles.keys(), "vocabulary": True if ( b.has_attr("vocabulary-bundle") and b["vocabulary-bundle"] == "true" ) else False, } return dict(sorted(available_bundles.items())) @property def max_version(self) -> str: expath_pkg = Path( os.path.dirname(self.config_file_path), ".max", "resources", "expath-pkg.xml", ) if expath_pkg.is_file(): with open(expath_pkg, "r") as expath_handle: soup = BeautifulSoup(expath_handle.read(), "xml") package = soup.find("package") if package: return package["version"] return "" @property def env(self) -> str: conf = self.xml_soup.find("configuration") val = conf.get("env", "dev") return str(val) @env.setter def env(self, value: str): conf = self.xml_soup.find("configuration") conf["env"] = value @property def vocabulary_bundle(self) -> str: conf = self.xml_soup.find("configuration") val = conf.get("vocabulary-bundle", "max-dumb-xml") return str(val) @vocabulary_bundle.setter def vocabulary_bundle(self, value): conf = self.xml_soup.find("configuration") conf["vocabulary-bundle"] = value @property def title(self) -> str: val = "untitled" conf = self.xml_soup.find("configuration") xml_node = conf.find("title") if xml_node: val = xml_node.text.strip() return str(val) @title.setter def title(self, value): conf = self.xml_soup.find("configuration") xml_node = conf.find("title") if not xml_node: xml_node = self.xml_soup.new_tag("title") conf.append(xml_node) xml_node.string = value @property def languages(self) -> list[str]: vals = [] conf = self.xml_soup.find("configuration") nodes = conf.find("languages") if nodes: for language in nodes.find_all("language"): vals.append(language.text.strip()) return vals @languages.setter def languages(self, languages: list[str]): conf = self.xml_soup.find("configuration") nodes = conf.find("languages") if not nodes: nodes = self.xml_soup.new_tag("languages") conf.append(nodes) nodes.clear() for language in languages: language_tag = self.xml_soup.new_tag("language") language_tag.string = language nodes.append(language_tag) @property def bundles(self) -> Dict[str, Dict]: vals = {} conf = self.xml_soup.find("configuration") nodes = conf.find("bundles") if nodes: for bundle in nodes.find_all("bundle"): vals[bundle["name"]] = { "name": bundle["name"], "url": bundle["url"] if bundle.has_attr("url") else "", } return vals @bundles.setter def bundles(self, bundles: Dict[str, Dict]): conf = self.xml_soup.find("configuration") nodes = conf.find("bundles") if not nodes: nodes = self.xml_soup.new_tag("bundles") conf.append(nodes) nodes.clear() for bundle_name, bundle_dict in bundles.items(): bundle_tag = self.xml_soup.new_tag("bundle") bundle_tag["name"] = bundle_dict["name"] if bundle_dict.get("url"): bundle_tag["url"] = bundle_dict["url"] nodes.append(bundle_tag) def __str__(self): return self.xml_soup.prettify() def write(self): with open(self.config_file_path, "w") as f: f.write(str(self)) @lru_cache() def current_system() -> str: return f"{platform.system()}/{platform.machine()}".lower() Loading Loading @@ -522,7 +323,8 @@ def _install_new_max_instance(root_directory: Path): welcome_page = Path(root_directory, "content_html", "fr", "index.html") with open(welcome_page, "w") as f: f.write(WELCOME_PAGE) climax_db.save(MaxInstall(None, str(root_directory.resolve()))) climax_db.commit() print( "[bold]" + _("La nouvelle instance de MaX est prête dans {}").format(root_directory) Loading Loading @@ -591,6 +393,8 @@ def sync( if is_max: _sync_max_instance(root_directory) climax_db.save(MaxInstall(None, str(root_directory.resolve()))) climax_db.commit() else: print( _( Loading Loading @@ -958,6 +762,31 @@ def templates_list(): print(item) @app.command(help=_("Liste les projets gérés par climax")) def projects(): console = Console() table = Table(_("Projet"), _("Chemin"), show_lines=True) for max_install in climax_db.projects(): if max_install.exists(): config = max_install.config() table.add_row(config.title, max_install.path) console.print(table) # options = [] # for max_install in climax_db.projects(): # options.append(max_install.path) # terminal_menu = TerminalMenu(options) # menu_entry_index = terminal_menu.show() # subprocess.run(["cd", options[menu_entry_index]], shell=True) @app.command(help=_("Application web (test)")) def ui(max_dir: str = None): from .gui import app app.max_directory = max_dir app.run(port=8888, reloader=True, debug=True) get_yolk() if __name__ == "__main__": Loading
src/climax/config.py +64 Changes for src/climax/config.py: 64 added lines, 0 removed lines. Original line number Diff line number Diff line import os import json from pathlib import Path from typing import List, Dict from requests import get from functools import cache GITLAB_API_READ_TOKEN = "glpat-5BCYCid1WaxxBgax-7VW" WELCOME_PAGE = """ <h1>Bienvenue dans MaX !</h1> <p> Vous pouvez personnaliser cette page en éditant le fichier content_html/fr/index.html </p> <p> Retrouvez la documentation de MaX à l'adresse suivante: <a href="https://pdn-certic.pages.unicaen.fr/max-documentation/"> https://pdn-certic.pages.unicaen.fr/max-documentation/ </a> </p> """ USER_MAX_DIR = os.getenv("CLIMAX_HOME") or Path(Path.home(), ".climax") USER_MAX_DIR = Path(USER_MAX_DIR) USER_MAX_DIR.mkdir(exist_ok=True) CACHE_DIR = Path(USER_MAX_DIR, "cache") CACHE_DIR.mkdir(exist_ok=True) MAX_CONFIG_FILE = "config.xml" BASEX_DISTRO = "https://files.basex.org/releases/11.7/BaseX117.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/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip" CURRENT_MAX_DISTRO_DIR = os.path.splitext(os.path.basename(MAX_DISTRO))[0] 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", "windows/amd64": "https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_windows-x64_bin.zip", } WEB_PORT = 8080 WEB_HOST = "127.0.0.1" BASEX_PORT = 1984 STOP_PORT = 8081 @cache def max_releases() -> List[Dict]: try: response = get( "https://git.unicaen.fr/api/v4/projects/2429/releases", headers={"PRIVATE-TOKEN": GITLAB_API_READ_TOKEN}, ) if response.ok: return json.loads(response.content) except: # noqa: E722 pass with open( Path(os.path.dirname(os.path.realpath(__file__)), "max_releases.json") ) as f: return json.load(f)
src/climax/gui.py +18 Changes for src/climax/gui.py: 18 added lines, 0 removed lines. Original line number Diff line number Diff line from bottle import Bottle from pathlib import Path from .model import MaXProjectConfig app = Bottle() @app.get("/") def home(): return f"HomePage {app.max_directory}" @app.get("/conf") def config(): conf_path = Path(app.max_directory, "config.xml") print(conf_path) conf = MaXProjectConfig(conf_path) return conf.available_bundles
src/climax/max_releases.json +1 Changes for src/climax/max_releases.json: 1 added line, 0 removed lines. Original line number Diff line number Diff line [{"name":"0.0.2-alpha","tag_name":"0.0.2-alpha","description":"","created_at":"2025-03-10T14:38:17.672+01:00","released_at":"2025-03-10T14:38:17.672+01:00","upcoming_release":false,"author":{"id":11,"username":"chauveau","name":"Jerome Chauveau","state":"active","locked":false,"avatar_url":"https://secure.gravatar.com/avatar/bb32beebd4915ca92c58ea8282b2d7270f01132b660ce645db5b17a0002029c0?s=80\u0026d=identicon","web_url":"https://git.unicaen.fr/chauveau"},"commit":{"id":"76b83bb3d2650e2c1be8705646a453ea86b36532","short_id":"76b83bb3","created_at":"2025-03-10T14:37:06.000+01:00","parent_ids":["57ccde26d1c7329e1929ea7269f00d6b61346d87"],"title":"rng fix + basex 11.7 + max-db url update","message":"rng fix + basex 11.7 + max-db url update\n","author_name":"Jérôme Chauveau","author_email":"jerome.chauveau@unicaen.fr","authored_date":"2025-03-10T14:37:06.000+01:00","committer_name":"Jérôme Chauveau","committer_email":"jerome.chauveau@unicaen.fr","committed_date":"2025-03-10T14:37:06.000+01:00","trailers":{},"extended_trailers":{},"web_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/commit/76b83bb3d2650e2c1be8705646a453ea86b36532"},"commit_path":"/pdn-certic/max-v2/-/commit/76b83bb3d2650e2c1be8705646a453ea86b36532","tag_path":"/pdn-certic/max-v2/-/tags/0.0.2-alpha","assets":{"count":4,"sources":[{"format":"zip","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.zip"},{"format":"tar.gz","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar.gz"},{"format":"tar.bz2","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar.bz2"},{"format":"tar","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.2-alpha/max-v2-0.0.2-alpha.tar"}],"links":[]},"evidences":[{"sha":"a100be82705a5fd1030bc32747f11e7bdbd1615e122d","filepath":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha/evidences/515.json","collected_at":"2025-03-10T14:38:17.734+01:00"}],"_links":{"closed_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.2-alpha\u0026scope=all\u0026state=closed","closed_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=closed","edit_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha/edit","merged_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=merged","opened_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.2-alpha\u0026scope=all\u0026state=opened","opened_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.2-alpha\u0026scope=all\u0026state=opened","self":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.2-alpha"}},{"name":"0.0.1-alpha","tag_name":"0.0.1-alpha","description":"Release de test.","created_at":"2024-10-09T15:58:45.946+02:00","released_at":"2024-10-09T15:58:45.946+02:00","upcoming_release":false,"author":{"id":11,"username":"chauveau","name":"Jerome Chauveau","state":"active","locked":false,"avatar_url":"https://secure.gravatar.com/avatar/bb32beebd4915ca92c58ea8282b2d7270f01132b660ce645db5b17a0002029c0?s=80\u0026d=identicon","web_url":"https://git.unicaen.fr/chauveau"},"commit":{"id":"e1f216d98ce827b021050e8b1f28156eb1d6a49c","short_id":"e1f216d9","created_at":"2024-10-09T15:56:32.000+02:00","parent_ids":["401c3ff10290aceddb7b81c9ef8d9f85884eb54e"],"title":"catch repo:not found exception","message":"catch repo:not found exception\n","author_name":"Jérôme Chauveau","author_email":"jerome.chauveau@unicaen.fr","authored_date":"2024-10-09T15:56:32.000+02:00","committer_name":"Jérôme Chauveau","committer_email":"jerome.chauveau@unicaen.fr","committed_date":"2024-10-09T15:56:32.000+02:00","trailers":{},"extended_trailers":{},"web_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/commit/e1f216d98ce827b021050e8b1f28156eb1d6a49c"},"commit_path":"/pdn-certic/max-v2/-/commit/e1f216d98ce827b021050e8b1f28156eb1d6a49c","tag_path":"/pdn-certic/max-v2/-/tags/0.0.1-alpha","assets":{"count":4,"sources":[{"format":"zip","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.zip"},{"format":"tar.gz","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar.gz"},{"format":"tar.bz2","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar.bz2"},{"format":"tar","url":"https://git.unicaen.fr/pdn-certic/max-v2/-/archive/0.0.1-alpha/max-v2-0.0.1-alpha.tar"}],"links":[]},"evidences":[{"sha":"17b0b81d3fdc0ffe172ea3ec1fb033f629bffa5d2e0d","filepath":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha/evidences/388.json","collected_at":"2024-10-09T15:58:46.087+02:00"}],"_links":{"closed_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.1-alpha\u0026scope=all\u0026state=closed","closed_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=closed","edit_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha/edit","merged_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=merged","opened_issues_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/issues?release_tag=0.0.1-alpha\u0026scope=all\u0026state=opened","opened_merge_requests_url":"https://git.unicaen.fr/pdn-certic/max-v2/-/merge_requests?release_tag=0.0.1-alpha\u0026scope=all\u0026state=opened","self":"https://git.unicaen.fr/pdn-certic/max-v2/-/releases/0.0.1-alpha"}}] No newline at end of file