Пример #1
0
def test_unformat_directory(test_app, cli_runner, click_cli, bookmark_fixture,
                            note_fixture):
    out_dir = mkdtemp()

    # create directory to store archivy note
    note_dir = "note-dir"
    create_dir(note_dir)
    nested_note = DataObj(type="note", title="Nested note", path=note_dir)
    nested_note.insert()

    # unformat directory
    res = cli_runner.invoke(
        cli, ["unformat",
              os.path.join(get_data_dir(), note_dir), out_dir])
    assert f"Unformatted and moved {nested_note.fullpath} to {out_dir}/{note_dir}/{nested_note.title}" in res.output
Пример #2
0
def query_ripgrep(query):
    """Uses ripgrep to search data with a simpler setup than ES"""

    from archivy.data import get_data_dir

    if current_app.config["SEARCH_CONF"]["engine"] != "ripgrep" or not which(
            "rg"):
        return None

    rg_cmd = [
        "rg", RG_MISC_ARGS, RG_FILETYPE, RG_REGEX_ARG, query,
        str(get_data_dir())
    ]
    rg = run(rg_cmd, stdout=PIPE, stderr=PIPE, timeout=60)
    file_paths = [Path(p.decode()).parts[-1] for p in rg.stdout.splitlines()]

    # don't open file just find info from filename for speed
    hits = []
    for filename in file_paths:
        parsed = filename.replace(".md", "").split("-")
        hits.append({"id": int(parsed[0]), "title": "-".join(parsed[1:])})
    return hits