diff --git a/.context.yaml b/.context.yaml index 96d45b3..9244bda 100644 --- a/.context.yaml +++ b/.context.yaml @@ -1,6 +1,8 @@ files: TODO.md: - contexts: [] + contexts: + - python + note: Chawera projects: - bokertov tags: [] diff --git a/COMMANDS.md b/COMMANDS.md index c6d0749..9889250 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -1,3 +1,6 @@ +--- +// @erfwegf +--- # Tagging + add file.txt @context +project #tag This is a note diff --git a/README.md b/README.md index 594b003..1ca5ed5 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ --- -project: +projects: - test - test2 -context: +contexts: - frrr +howard: +- fool --- # Orvani Tagger diff --git a/TODO.md b/TODO.md index 290e980..b492fc4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,7 @@ +--- +tags: +- frrr +--- + plugin API + support for frontmatter + support for Comment ID3 tag \ No newline at end of file diff --git a/orvani/__pycache__/orvani.cpython-310.pyc b/orvani/__pycache__/orvani.cpython-310.pyc index 59ee027..d538525 100644 Binary files a/orvani/__pycache__/orvani.cpython-310.pyc and b/orvani/__pycache__/orvani.cpython-310.pyc differ diff --git a/orvani/cmd.py b/orvani/cmd.py index bf41927..1e0a026 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -5,6 +5,7 @@ from pathlib import Path from rich.console import Console from rich.table import Table from orvani import OrvaniTag, CONTEXT_FILE, CACHE_FILE, CONTEXTS +from plugins import frontmatter def mktable(query: str, index: dict): console = Console() @@ -87,6 +88,12 @@ def main(): orvani = OrvaniTag() + @orvani.metareader + def reader(o): + frontmatter.reader(o) + + # orvani.metadata() + if args.command in ['add', 'a']: if args.file and args.context: orvani.add(args.file, *args.context) diff --git a/orvani/orvani.py b/orvani/orvani.py index e3411b0..165d999 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -2,6 +2,7 @@ import os import yaml import shutil from pathlib import Path +from types import SimpleNamespace # Defaults @@ -60,7 +61,7 @@ class OrvaniTag: self.CONFIG = y['config'] else: self.DB = dict() - self.CONFIG = dict() + # self.CONFIG = dict() def __save(self): """ @@ -113,6 +114,7 @@ class OrvaniTag: if target.exists(): self.__cd(target.parent.name) context = self.__context(argv) + print(context) if target.name in self.DB: for context_key in self.CTX.keys(): if self.CTX[context_key] != None: @@ -278,6 +280,10 @@ class OrvaniTag: for dir in dirs: rpath = os.path.join(root, dir) self.__indexfolder(rpath) + if files: + for file in files: + fpath = os.path.join(root, file) + self.metadata(fpath) if cache: with open(cachefile, 'w+') as data: yaml.dump(self.INDEX, data) @@ -327,7 +333,6 @@ class OrvaniTag: if filter and not filter == context_key: continue if context_key in query: - # Is it a list of context items? if type(query[context_key]) == list: for q in query[context_key]: if exact: @@ -368,7 +373,14 @@ class OrvaniTag: self.META_OUT.append(function) return function - def read_meta(self): - for callback in self.META_IN: - entry = callback(self.CONFIG, self.DB) - print(entry) \ No newline at end of file + def metadata(self, filename: str): + obj = { + 'path' : filename, + 'index' : self.INDEX, + 'schema' : self.CTX + } + o = SimpleNamespace(**obj) + for reader in self.META_IN: + reader(o) + for writer in self.META_OUT: + writer(o) diff --git a/orvani/plugins/__init__.py b/orvani/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/orvani/plugins/__pycache__/__init__.cpython-310.pyc b/orvani/plugins/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..948db03 Binary files /dev/null and b/orvani/plugins/__pycache__/__init__.cpython-310.pyc differ diff --git a/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc b/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc new file mode 100644 index 0000000..f114072 Binary files /dev/null and b/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc differ diff --git a/orvani/plugins/frontmatter.py b/orvani/plugins/frontmatter.py new file mode 100644 index 0000000..a75457f --- /dev/null +++ b/orvani/plugins/frontmatter.py @@ -0,0 +1,17 @@ +import frontmatter +from pathlib import Path + +def reader(o): + file = Path(o.path) + if file.suffix in ['.md', '.txt', '.markdown', '.rst']: + with open(file, 'r') as data: + y = frontmatter.load(data) + if y.metadata: + context = y.metadata.copy() + for meta in y.metadata.keys(): + if not meta in o.schema: + del context[meta] + if o.path in o.index['files']: + o.index['files'][o.path].update(context) + else: + o.index['files'][o.path] = context \ No newline at end of file