This commit is contained in:
randogoth 2023-06-07 00:15:45 +03:00
parent 42c9cbf002
commit 534152eb9f
5 changed files with 88 additions and 20 deletions

View file

@ -1,14 +1,20 @@
TODO.md:
contexts: []
note: The TODO file of this project
projects:
- tagger
tags:
- frr
orvani.py:
contexts:
- private
projects:
- tagger
tags:
- python
config:
index:
- md
- wav
- txt
files:
TODO.md:
contexts: []
note: The TODO file of this project
projects:
- tagger
tags:
- frr
orvani.py:
contexts:
- private
projects:
- tagger
tags:
- python

View file

@ -1,3 +1,10 @@
---
project:
- test
- test2
context:
- frrr
---
# Orvani Tagger
(From עוֹרְבָנִי, the Hebrew name for th Eurasian Jay)

View file

@ -1,3 +1,4 @@
+ support for textfiles //
+ support for Markdown metadata
+ support for RST metadata
+ command to remove all contexts recursively
+ plugin API
+ support for frontmatter
+ support for Comment ID3 tag

26
metareaders.py Normal file
View file

@ -0,0 +1,26 @@
import taglib
with taglib.File("/home/flux/Documents/230605-191750.wav", save_on_exit=True) as song:
import frontmatter
with open('README.md', 'r') as data:
y = frontmatter.load(data)
print(y.metadata)
@orvani.metareader
def yaml_read(conf, db):
for (root,dirs,files) in os.walk(path):
if files:
for file in files:
rpath = os.path.join(root, dir)
f, ext = os.path.splitext(file)
if ext[1:] in conf['index'] and ext[1:] in ['md', 'txt']:
with open(file, 'r') as data:
y = frontmatter.load(data)
print(y)
if y.metadata:
for meta in y.metadata:
db[file][meta] = y.metadata[meta]
return db

View file

@ -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()