Commit 1c218b3a authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add vocabulary prompt in interactive new install

parent cbd215f7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
__version__ = "0.2.11"
__version__ = "0.2.12"
+33 −18
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ import json
from .eggs import get_yolk
from .model import MaXProjectConfig, db as climax_db, DEFAULT_DOT_BASEX_FILE
from .config import (
    WELCOME_PAGE,
    USER_MAX_DIR,
    CACHE_DIR,
    MAX_CONFIG_FILE,
@@ -97,7 +96,7 @@ def _scan_dir(start_path: Union[str, Path], extension: str = None) -> Iterator[P
        for file in files:
            if extension:
                if file[(len(extension) * -1) :].lower() == extension.lower():
                    yield os.path.join(root, file)
                    yield Path(os.path.join(root, file)).resolve()
            else:
                yield Path(os.path.join(root, file)).resolve()

@@ -346,7 +345,11 @@ def _copy_max_tree(
        )


def _install_new_max_instance(root_directory: Path, init_values: dict = None):
def _install_new_max_instance(
    root_directory: Path,
    init_values: dict = None,
    choose_vocabulary_post_install: bool = False,
):
    rich_print(
        "[bold]"
        + _("Initialisation d'une nouvelle instance de MaX dans {}").format(
@@ -379,20 +382,32 @@ def _install_new_max_instance(root_directory: Path, init_values: dict = None):

    _sync_max_instance(root_directory, verbose=False)

    Path(root_directory, "content_html", "fr").mkdir(exist_ok=True, parents=True)
    welcome_page = Path(root_directory, "content_html", "fr", "index.html")
    with open(welcome_page, "w", encoding="utf-8") as f:
        f.write(WELCOME_PAGE)
    if choose_vocabulary_post_install:
        vocabulary_bundle_name = _choose_between(
            [
                bundle.get("name")
                for bundle in conf.available_bundles.values()
                if bundle.get("vocabulary")
            ],
            "vocabulaire à utiliser",
        )
        print(root_directory)
        bundles_add(vocabulary_bundle_name, str(root_directory))

    # Path(root_directory, "content_html", "fr").mkdir(exist_ok=True, parents=True)
    # welcome_page = Path(root_directory, "content_html", "fr", "index.html")
    # with open(welcome_page, "w", encoding="utf-8") as f:
    #    f.write(WELCOME_PAGE)
    rich_print(
        "[bold]"
        + _("La nouvelle instance de MaX est prête dans {}").format(root_directory)
        + "[/bold]"
    )
    rich_print(
        _(
            'Vous pouvez éventuellement installer un projet de démonstration avec "climax demo".'
        )
    )
    # rich_print(
    #    _(
    #        'Vous pouvez éventuellement installer un projet de démonstration avec "climax demo".'
    #    )
    # )


def _sync_max_instance(root_directory: Path, verbose=True):
@@ -451,7 +466,7 @@ def new(
    interactive: bool = False,
):
    ensure_java()
    root_directory, is_max = ensure_available_max_directory(directory)
    root_directory, is_max = ensure_available_max_directory(str(directory))
    if is_max:
        rich_print(
            _("Le dossier contient une instance de MaX. Utilisez la commande sync")
@@ -472,7 +487,7 @@ def new(
        except (KeyboardInterrupt, TypeError):
            root_directory.rmdir()
            return
    _install_new_max_instance(root_directory, init_values)
    _install_new_max_instance(root_directory, init_values, interactive)


@app.command(help=_("Installe une édition de démonstration."))
@@ -815,7 +830,7 @@ def bundles_add(
                    config.bundles = current_bundles_config
                    config.write()
                    _sync_max_instance(directory, verbose=False)
                    bundles_list()
                    bundles_list(str(directory))


@app.command(help=_("Supprime un bundle"))
@@ -840,7 +855,7 @@ def bundles_remove(
    config.bundles = keep_bundles
    config.write()
    _sync_max_instance(directory, verbose=False)
    bundles_list(directory)
    bundles_list(str(directory))


@app.command(help=_("Ajoute un fichier ou un dossier XML"))
@@ -907,7 +922,7 @@ def sync(
    ] = os.getcwd(),
):
    ensure_java()
    root_directory, is_max = ensure_available_max_directory(directory)
    root_directory, is_max = ensure_available_max_directory(str(directory))

    if is_max:
        _sync_max_instance(root_directory)
@@ -1026,7 +1041,7 @@ def projects(json_out: bool = False):
                }
            )
        else:
            db.delete("maxinstall", "id = ?", max_install.id)
            db.delete("maxinstall", "id = ?", [max_install.id])
            db.commit()
    if json_out:
        print(json.dumps({"projects": projects_list}, indent=4))
+3 −2
Original line number Diff line number Diff line
import os
import json
from pathlib import Path
from typing import List, Dict
from typing import List, Dict, Union
from requests import get
from functools import cache
import logging
@@ -107,7 +107,7 @@ def max_releases() -> List[Dict]:


@cache
def max_release(release_name: str) -> Dict:
def max_release(release_name: str) -> Union[Dict, None]:
    for release in max_releases():
        if release.get("name") == release_name:
            if release["assets"]["count"] > 0:
@@ -115,6 +115,7 @@ def max_release(release_name: str) -> Dict:
                    if source["format"] == "zip":
                        release["zip_url"] = source["url"]
            return release
    return None


@cache
+3 −2
Original line number Diff line number Diff line
@@ -259,8 +259,8 @@ class MaXProjectConfig:

@dataclass
class MaxInstall:
    id: int
    path: str
    id: int = None
    path: str = None
    _meta: str = None

    def exists(self):
@@ -272,6 +272,7 @@ class MaxInstall:
    def config(self) -> Union[MaXProjectConfig, None]:
        if self.exists():
            return MaXProjectConfig(Path(self.path, "config.xml"))
        return None

    @property
    def meta(self) -> dict: