diff --git a/.context.yaml b/.context.yaml index 9244bda..08f0f6e 100644 --- a/.context.yaml +++ b/.context.yaml @@ -5,4 +5,5 @@ files: note: Chawera projects: - bokertov - tags: [] + tags: + - rusty diff --git a/.index.yaml b/.index.yaml new file mode 100644 index 0000000..f464731 --- /dev/null +++ b/.index.yaml @@ -0,0 +1,54 @@ +contexts: + frrr: + - ./README.md + python: + - ./TODO.md + test: + - ./test/test.txt +files: + ./README.md: + contexts: + - frrr + projects: + - test2 + - test + ./TODO.md: + contexts: + - python + note: Chawera + projects: + - bokertov + tags: + - frrr + - rusty + ./test/test.txt: + contexts: + - test + note: frrr + projects: + - test + tags: + - faa + - test +note: + Chawera: + - ./TODO.md + frrr: + - ./test/test.txt +projects: + bokertov: + - ./TODO.md + test: + - ./README.md + - ./test/test.txt + test2: + - ./README.md +tags: + faa: + - ./test/test.txt + frrr: + - ./TODO.md + rusty: + - ./TODO.md + test: + - ./test/test.txt diff --git a/COMMANDS.md b/COMMANDS.md index 9889250..92c9235 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -1,5 +1,5 @@ --- -// @erfwegf +#// @erfwegf #super #great +coding This is awesome --- # Tagging diff --git a/TODO.md b/TODO.md index b492fc4..f6e42b0 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,5 @@ tags: - frrr --- -+ plugin API -+ support for frontmatter ++ fix clean and purge + 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 d538525..e9a30dc 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 1e0a026..799208c 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -5,7 +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 +from plugins import frontmatter, hashslashslash def mktable(query: str, index: dict): console = Console() @@ -91,6 +91,7 @@ def main(): @orvani.metareader def reader(o): frontmatter.reader(o) + hashslashslash.reader(o) # orvani.metadata() diff --git a/orvani/orvani.py b/orvani/orvani.py index 165d999..1eaf8bb 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -3,6 +3,7 @@ import yaml import shutil from pathlib import Path from types import SimpleNamespace +from pprint import pprint # Defaults @@ -112,9 +113,8 @@ class OrvaniTag: """ target = Path(file) if target.exists(): - self.__cd(target.parent.name) + self.__cd(target.parent) 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: @@ -136,7 +136,7 @@ class OrvaniTag: """ target = Path(file) if target.exists(): - self.__cd(target.parent.name) + self.__cd(target.parent) context = self.__context(argv) if file in self.DB: for context_key in self.CTX.keys(): @@ -157,7 +157,7 @@ class OrvaniTag: """ target = Path(file) if target.exists(): - self.__cd(target.parent.name) + self.__cd(target.parent) if fop: target.unlink(missing_ok=True) if file in self.DB: @@ -209,7 +209,7 @@ class OrvaniTag: path = '.' target = Path(path) if target.exists(): - self.__cd(target.parent.name) + self.__cd(target.parent) DB = self.DB.copy() for file in self.DB.keys(): if not Path(file).is_file(): @@ -301,15 +301,37 @@ class OrvaniTag: if self.DB: for file in self.DB.keys(): path = os.path.join(sub, file) - self.INDEX['files'].update( { path : self.DB[file]} ) for context_key in self.CTX.keys(): if context_key in self.DB[file]: - for item in self.DB[file][context_key]: - filelist = [path] - if context_key in self.INDEX: - if item in self.INDEX[context_key]: - filelist += self.INDEX[context_key][item] - self.INDEX[context_key][item] = filelist + self.__updateindex(path, self.DB[file], context_key) + + def __updateindex(self, path: str, context: dict, context_key: str): + # Update files index + for key, value in context.items(): + if path in self.INDEX['files']: + if key in self.INDEX['files'][path] and isinstance(self.INDEX['files'][path][key], list) and isinstance(value, list): + self.INDEX['files'][path][key] += value + self.INDEX['files'][path][key] = list(set(self.INDEX['files'][path][key])) + else: + self.INDEX['files'][path][key] = value + else: + self.INDEX['files'][path] = { key : value } + + # Update context index + if type(context[context_key]) == list: + for item in context[context_key]: + filelist = [path] + if context_key in self.INDEX: + if item in self.INDEX[context_key]: + filelist += self.INDEX[context_key][item] + self.INDEX[context_key][item] = list(set(filelist)) + else: + item = context[context_key] + filelist = [path] + if context_key in self.INDEX: + if item in self.INDEX[context_key]: + filelist += self.INDEX[context_key][item] + self.INDEX[context_key][item] = list(set(filelist)) def __search(self, search, filter: str=None, exact:bool=False): """ @@ -327,42 +349,31 @@ class OrvaniTag: query = self.__context(search) return_dict = self.__context([' ']) universal = {i for i in self.CTX if self.CTX[i]==None}.pop() + if universal in query: + query[universal] = [query[universal]] for context_key in self.CTX.keys(): return_dict[context_key] = [] - for context in self.INDEX[context_key]: - if filter and not filter == context_key: - continue - if context_key in query: - if type(query[context_key]) == list: - for q in query[context_key]: - if exact: - if q == context: - if self.INDEX[context_key][context] not in return_dict[context_key]: - return_dict[context_key] += self.INDEX[context_key][context] - else: - if q in context: - if self.INDEX[context_key][context] not in return_dict[context_key]: - return_dict[context_key] += self.INDEX[context_key][context] - if universal in query: - if exact: - if query[universal] == context: - if self.INDEX[context_key][context] not in return_dict[context_key]: - return_dict[context_key] += self.INDEX[context_key][context] - else: - if query[universal] in context: - if self.INDEX[context_key][context] not in return_dict[context_key]: - return_dict[context_key] += self.INDEX[context_key][context] - if context_key in return_dict: - return_dict[context_key] = list(set(return_dict[context_key])) + for param in query.keys(): + needles = query[param] + if universal in query.keys(): + needles += query[universal] + if needles: + haystack = self.INDEX[param].keys() + for hay in haystack: + for needle in needles: + if needle in hay: + if self.INDEX[param][hay] not in return_dict[param]: + return_dict[param] += self.INDEX[param][hay] if len(search) > 1: - result['found'] = sorted(list(set(self.__intersect(return_dict))), key=lambda x: x.count('/')) + result['found'] = list(set(self.__intersect(return_dict))) else: min = [] for sublist in return_dict.values(): min += sublist result['found'] = list(set(min)) else: - result['found'] = sorted(self.INDEX['files'].keys(), key=lambda x: x.count('/')) + result['found'] = self.INDEX['files'].keys() + result['found'] = sorted(result['found'], key=lambda x: x.count('/')) return result def metareader(self, function): @@ -377,7 +388,9 @@ class OrvaniTag: obj = { 'path' : filename, 'index' : self.INDEX, - 'schema' : self.CTX + 'schema' : self.CTX, + 'update' : self.__updateindex, + 'context' : self.__context } o = SimpleNamespace(**obj) for reader in self.META_IN: diff --git a/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc b/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc index f114072..67611ad 100644 Binary files a/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc and b/orvani/plugins/__pycache__/frontmatter.cpython-310.pyc differ diff --git a/orvani/plugins/__pycache__/hashslashslash.cpython-310.pyc b/orvani/plugins/__pycache__/hashslashslash.cpython-310.pyc new file mode 100644 index 0000000..23aee41 Binary files /dev/null and b/orvani/plugins/__pycache__/hashslashslash.cpython-310.pyc differ diff --git a/orvani/plugins/frontmatter.py b/orvani/plugins/frontmatter.py index a75457f..3a033e7 100644 --- a/orvani/plugins/frontmatter.py +++ b/orvani/plugins/frontmatter.py @@ -11,7 +11,5 @@ def reader(o): 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 + for context_key in context.keys(): + o.update(o.path, context, context_key) \ No newline at end of file diff --git a/orvani/plugins/hashslashslash.py b/orvani/plugins/hashslashslash.py new file mode 100644 index 0000000..875ee61 --- /dev/null +++ b/orvani/plugins/hashslashslash.py @@ -0,0 +1,23 @@ +""" +#// +orvani @python #example It even works in Python code +""" +import re +from pathlib import Path + +REGEX = r'\s*([@+]\w+|#\w+(? 5: + break + if line.strip().startswith("#// "): + tags = re.findall(REGEX, line.strip()[3:]) + note = re.sub(REGEX, '', line.strip()[3:]).lstrip() + argv = ' '.join(tags).split(' ') + [note] + context = o.context(argv) + for context_key in context.keys(): + o.update(o.path, context, context_key) + \ No newline at end of file