plugins
This commit is contained in:
parent
f04ffae75a
commit
35231aa55b
11 changed files with 138 additions and 49 deletions
|
|
@ -5,4 +5,5 @@ files:
|
|||
note: Chawera
|
||||
projects:
|
||||
- bokertov
|
||||
tags: []
|
||||
tags:
|
||||
- rusty
|
||||
|
|
|
|||
54
.index.yaml
Normal file
54
.index.yaml
Normal file
|
|
@ -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
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
// @erfwegf
|
||||
#// @erfwegf #super #great +coding This is awesome
|
||||
---
|
||||
# Tagging
|
||||
|
||||
|
|
|
|||
3
TODO.md
3
TODO.md
|
|
@ -2,6 +2,5 @@
|
|||
tags:
|
||||
- frrr
|
||||
---
|
||||
+ plugin API
|
||||
+ support for frontmatter
|
||||
+ fix clean and purge
|
||||
+ support for Comment ID3 tag
|
||||
Binary file not shown.
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Binary file not shown.
BIN
orvani/plugins/__pycache__/hashslashslash.cpython-310.pyc
Normal file
BIN
orvani/plugins/__pycache__/hashslashslash.cpython-310.pyc
Normal file
Binary file not shown.
|
|
@ -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
|
||||
for context_key in context.keys():
|
||||
o.update(o.path, context, context_key)
|
||||
23
orvani/plugins/hashslashslash.py
Normal file
23
orvani/plugins/hashslashslash.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
#// +orvani @python #example It even works in Python code
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
REGEX = r'\s*([@+]\w+|#\w+(?<!#//))'
|
||||
|
||||
def reader(o):
|
||||
file = Path(o.path)
|
||||
if file.suffix in ['.md', '.txt', '.py']:
|
||||
with file.open() as data:
|
||||
for line_num, line in enumerate(data, start=1):
|
||||
if line_num > 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)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue