Support wildcard extension in arbitrary folder

Now no longer only looks in "extensions/wildcards/widlcards".
This enables the user to call the folder whatever they like.
Fixes #37
This commit is contained in:
Dominik Reh
2022-10-28 15:06:43 +02:00
parent dc77b3f17f
commit 3e71890489
2 changed files with 25 additions and 11 deletions

View File

@@ -6,12 +6,20 @@ from pathlib import Path
# The path to the folder containing the wildcards and embeddings
FILE_DIR = Path().absolute()
WILDCARD_PATH = FILE_DIR.joinpath('scripts/wildcards')
WILDCARD_EXT_PATH = FILE_DIR.joinpath('extensions/wildcards/wildcards')
EMB_PATH = FILE_DIR.joinpath('embeddings')
EXT_PATH = FILE_DIR.joinpath('extensions')
def find_ext_wildcard_path():
"""Returns the path to the extension wildcards folder"""
found = list(EXT_PATH.rglob('**/wildcards/'))[0]
return found
WILDCARD_EXT_PATH = find_ext_wildcard_path()
# The path to the temporary file
TEMP_PATH = FILE_DIR.joinpath('tags/temp')
def get_wildcards():
"""Returns a list of all wildcards. Works on nested folders."""
wildcard_files = list(WILDCARD_PATH.rglob("*.txt"))
@@ -48,13 +56,13 @@ write_to_temp_file('emb.txt', [])
# Write wildcards to wc.txt if found
if WILDCARD_PATH.exists():
wildcards = get_wildcards()
wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards()
if wildcards:
write_to_temp_file('wc.txt', wildcards)
# Write extension wildcards to wce.txt if found
if WILDCARD_EXT_PATH.exists():
wildcards_ext = get_ext_wildcards()
wildcards_ext = [WILDCARD_EXT_PATH.relative_to(FILE_DIR).as_posix()] + get_ext_wildcards()
if wildcards_ext:
write_to_temp_file('wce.txt', wildcards_ext)