meta API
This commit is contained in:
parent
42c9cbf002
commit
534152eb9f
5 changed files with 88 additions and 20 deletions
34
orvani.py
34
orvani.py
|
|
@ -5,6 +5,7 @@ import shutil
|
|||
from argparse import ArgumentParser as argp, SUPPRESS, RawTextHelpFormatter as raw
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
import frontmatter
|
||||
|
||||
# Defaults
|
||||
|
||||
|
|
@ -13,9 +14,12 @@ CACHE_FILE = '.index.yaml'
|
|||
|
||||
class OrvaniTag:
|
||||
|
||||
META_IN = []
|
||||
META_OUT = []
|
||||
INDEX = {} # our search index
|
||||
CACHEFILE = '' # search index cache ('.index.yaml')
|
||||
DB = dict() # holds the folder context data
|
||||
CONFIG = dict()
|
||||
FILENAME = '' # folder context data filename ('.context.yaml')
|
||||
FILE = '' # holds the folder context file path
|
||||
CTX = { # default contexts
|
||||
|
|
@ -53,11 +57,15 @@ class OrvaniTag:
|
|||
if os.path.isfile(self.FILE):
|
||||
try:
|
||||
with open(self.FILE, 'r') as data:
|
||||
self.DB = yaml.safe_load(data)
|
||||
y = yaml.safe_load(data)
|
||||
self.DB = y['files']
|
||||
if 'config' in y:
|
||||
self.CONFIG = y['config']
|
||||
except Exception:
|
||||
print('File does not exist')
|
||||
else:
|
||||
self.DB = dict()
|
||||
self.CONFIG = dict()
|
||||
|
||||
def __save(self):
|
||||
"""
|
||||
|
|
@ -66,7 +74,10 @@ class OrvaniTag:
|
|||
"""
|
||||
try:
|
||||
with open(self.FILE, 'w+') as data:
|
||||
yaml.dump(self.DB, data)
|
||||
y = {
|
||||
'files' : self.DB
|
||||
}
|
||||
yaml.dump(y, data)
|
||||
except Exception:
|
||||
print('File write error')
|
||||
|
||||
|
|
@ -352,6 +363,19 @@ class OrvaniTag:
|
|||
result['found'] = sorted(self.INDEX['files'].keys(), key=lambda x: x.count('/'))
|
||||
return result
|
||||
|
||||
def metareader(self, function):
|
||||
self.META_IN.append(function)
|
||||
return function
|
||||
|
||||
def metawriter(self, function):
|
||||
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)
|
||||
|
||||
def mktable(query: str, index: dict):
|
||||
console = Console()
|
||||
if len(index['found']) > 0:
|
||||
|
|
@ -416,7 +440,8 @@ def main():
|
|||
'listproj', 'lsprj',
|
||||
'listcon', 'lsc',
|
||||
'listtag', 'lst',
|
||||
'clean', 'purge'
|
||||
'clean', 'purge',
|
||||
'read'
|
||||
])
|
||||
p.add_argument("file", nargs="?", type=str, help=SUPPRESS)
|
||||
p.add_argument("context", nargs="*", type=str, help=SUPPRESS)
|
||||
|
|
@ -466,5 +491,8 @@ def main():
|
|||
args.file = ''
|
||||
orvani.purge(args.file, args.not_recursive)
|
||||
|
||||
elif args.command in ['read']:
|
||||
orvani.read_meta()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue