changed plugin system
This commit is contained in:
parent
473094bda9
commit
05edcb9f82
3 changed files with 20 additions and 28 deletions
2
TODO.md
2
TODO.md
|
|
@ -2,4 +2,4 @@
|
|||
tags:
|
||||
- frrr
|
||||
---
|
||||
+ plugin for xattr
|
||||
+ plugin writers
|
||||
|
|
@ -92,15 +92,7 @@ def main():
|
|||
|
||||
orvani = OrvaniTag()
|
||||
|
||||
@orvani.metareader
|
||||
def reader(o):
|
||||
frontmatter.reader(o)
|
||||
hashdoubleslash.reader(o)
|
||||
id3.reader(o)
|
||||
office.reader(o)
|
||||
pdf.reader(o)
|
||||
|
||||
orvani.PLUGINS = args.no_plugins
|
||||
orvani.ENABLE_PLUGINS = args.no_plugins
|
||||
|
||||
if args.command in ['add', 'a']:
|
||||
if args.file and args.context:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import os
|
|||
import yaml
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from importlib import import_module
|
||||
from types import SimpleNamespace
|
||||
from pprint import pprint
|
||||
|
||||
|
|
@ -15,11 +16,16 @@ CONTEXTS = {
|
|||
'tags' : '#',
|
||||
'note' : None
|
||||
}
|
||||
DEFAULT_PLUGINS = [
|
||||
'frontmatter',
|
||||
'hashdoubleslash',
|
||||
'id3',
|
||||
'office',
|
||||
'pdf'
|
||||
]
|
||||
|
||||
class OrvaniTag:
|
||||
|
||||
META_IN = []
|
||||
META_OUT = []
|
||||
INDEX = {} # our search index
|
||||
CACHEFILE = '' # search index cache ('.index.yaml')
|
||||
DB = dict() # holds the folder context data
|
||||
|
|
@ -29,9 +35,10 @@ class OrvaniTag:
|
|||
FILENAME = '' # folder context data filename ('.context.yaml')
|
||||
FILE = '' # holds the folder context file path
|
||||
CTX = {}
|
||||
PLUGINS = True
|
||||
ENABLE_PLUGINS = True
|
||||
PLUGINS = []
|
||||
|
||||
def __init__(self, path: str=CONTEXT_FILE, cache: str=CACHE_FILE, contexts=CONTEXTS):
|
||||
def __init__(self, path: str=CONTEXT_FILE, cache: str=CACHE_FILE, contexts=CONTEXTS, plugins:list=DEFAULT_PLUGINS):
|
||||
"""
|
||||
Initialization
|
||||
|
||||
|
|
@ -40,6 +47,7 @@ class OrvaniTag:
|
|||
contexts (dict): override the default contexts
|
||||
|
||||
"""
|
||||
self.PLUGINS = plugins
|
||||
self.FILENAME = os.path.basename(path)
|
||||
self.CACHEFILE = cache
|
||||
self.CTX = contexts
|
||||
|
|
@ -288,7 +296,7 @@ class OrvaniTag:
|
|||
self.__indexfolder(path)
|
||||
if recursive:
|
||||
for (root,dirs,files) in os.walk(path):
|
||||
if self.PLUGINS:
|
||||
if self.ENABLE_PLUGINS:
|
||||
if files:
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
|
|
@ -412,17 +420,10 @@ class OrvaniTag:
|
|||
common_elements = common_elements.intersection(mresult[key])
|
||||
return list(common_elements)
|
||||
|
||||
|
||||
def metareader(self, function):
|
||||
self.META_IN.append(function)
|
||||
def register_plugin(self, function):
|
||||
self.PLUGINS.append(function)
|
||||
return function
|
||||
|
||||
|
||||
def metawriter(self, function):
|
||||
self.META_OUT.append(function)
|
||||
return function
|
||||
|
||||
|
||||
def metadata(self, filename: str):
|
||||
obj = {
|
||||
'path' : filename,
|
||||
|
|
@ -433,7 +434,6 @@ class OrvaniTag:
|
|||
'context' : self.__context
|
||||
}
|
||||
o = SimpleNamespace(**obj)
|
||||
for reader in self.META_IN:
|
||||
reader(o)
|
||||
for writer in self.META_OUT:
|
||||
writer(o)
|
||||
for plugin_name in self.PLUGINS:
|
||||
plugin = import_module('plugins.' + plugin_name)
|
||||
plugin.reader(o)
|
||||
Loading…
Add table
Add a link
Reference in a new issue