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

fixes #3 list templates

parent 72a6701e
Loading
Loading
Loading
Loading
+28 −3
Changes for src/climax/__main__.py: 28 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -870,7 +870,7 @@ def bundles_add(bundle_name: str):
                    bundles_list()


@app.command(help=_("Ajoute un fichier XML à l'instance de Max en cours"))
@app.command(help=_("Ajoute un fichier ou un dossier XML à l'instance de Max en cours"))
def feed(feed_path: Path):
    feed_path = Path(feed_path).resolve()
    if not feed_path.is_file() and not feed_path.is_dir():
@@ -895,11 +895,12 @@ def feed(feed_path: Path):
            cp_paths(),
            "-Xmx2g",
            "org.basex.BaseX",
            f"db:put('max', '{feed_path}', '{feed_path}')",
            f"db:put('max', '{feed_path}', '{feed_path.name}')",
            # f"-cOPEN max; REPLACE {feed_path.resolve()}",
        ]
        subprocess.run(process_args)
    elif feed_path.is_dir():
        offset = len(str(feed_path))
        for f in _scan_dir(feed_path, ".xml"):
            process_args = [
                str(java_bin_path),
@@ -907,7 +908,7 @@ def feed(feed_path: Path):
                cp_paths(),
                "-Xmx2g",
                "org.basex.BaseX",
                f"db:put('max', '{f}', '{str(f).lstrip(str(feed_path))}')",
                f"db:put('max', '{f}', '{str(f)[offset:]}')",
                # f"-cOPEN max; REPLACE {f}",
            ]
        subprocess.run(process_args)
@@ -927,6 +928,30 @@ def basex():
    subprocess.run(process_args)


@app.command(help=_("Liste les templates du bundle de vocabulaire en cours"))
def templates_list():
    check_cwd_is_max()
    config = max_config()
    vocab_bundle = config.vocabulary_bundle
    tpl_dir = Path(
        os.getcwd(),
        ".max",
        "basex",
        "webapp",
        "max",
        "bundles",
        vocab_bundle,
        "templates",
    )
    tpls_list = []
    offset = len(str(tpl_dir))
    for f in _scan_dir(tpl_dir):
        if f.is_file():
            tpls_list.append(str(f)[offset:])
    for item in sorted(tpls_list):
        print(item)


get_yolk()

if __name__ == "__main__":