plugin switch

This commit is contained in:
randogoth 2023-06-09 01:32:20 +03:00
parent 0e7862ee4a
commit 3a8aaddae1
3 changed files with 13 additions and 6 deletions

View file

@ -61,6 +61,7 @@ def main():
p = argp(description="OrvaniTagger", formatter_class=raw)
p.add_argument("--not-recursive", "-nr", action="store_false", help="Include subdirectories in search")
p.add_argument("--no-file_operation", "-nf", action="store_false", help="Copy/Move/Delete file, not just context")
p.add_argument("--no-plugins", "-np", action="store_false", help="Don't use plug-ins to search file metadata")
p.add_argument("--path", "-p", action="store", type=str, help="List/search custom path", default='')
p.add_argument("--exact", "-e", action="store_true", help="Match exact search term")
p.add_argument("--either", "-or", action="store_true", help="Combine search terms by OR instead of AND")
@ -91,7 +92,7 @@ def main():
id3.reader(o)
office.reader(o)
# orvani.metadata()
orvani.PLUGINS = args.no_plugins
if args.command in ['add', 'a']:
if args.file and args.context:

View file

@ -29,6 +29,7 @@ class OrvaniTag:
FILENAME = '' # folder context data filename ('.context.yaml')
FILE = '' # holds the folder context file path
CTX = {}
PLUGINS = True
def __init__(self, path: str=CONTEXT_FILE, cache: str=CACHE_FILE, contexts=CONTEXTS):
"""
@ -286,11 +287,12 @@ class OrvaniTag:
self.__indexfolder(path)
if recursive:
for (root,dirs,files) in os.walk(path):
if files:
for file in files:
fpath = os.path.join(root, file)
self.__cd(root)
self.metadata(fpath)
if self.PLUGINS:
if files:
for file in files:
fpath = os.path.join(root, file)
self.__cd(root)
self.metadata(fpath)
if dirs:
for dir in dirs:
rpath = os.path.join(root, dir)

View file

@ -38,6 +38,7 @@ def reader(o):
tmp_folder = Path('unzip__' + file.stem)
file_type = unzip_file(o.path, tmp_folder)
tags = note = []
# OpenOffice / LibreOffice / Open Document Format
if file_type in ['odt', 'ods', 'odp']:
meta_file = tmp_folder / 'meta.xml'
@ -53,6 +54,7 @@ def reader(o):
for context_key in context.keys():
o.update(o.path, context, context_key)
shutil.rmtree(tmp_folder)
# Microsoft Office Format
elif file_type in ['docx', 'xlsx', 'pptx']:
meta_file = tmp_folder / 'docProps' / 'core.xml'
@ -68,6 +70,8 @@ def reader(o):
for context_key in context.keys():
o.update(o.path, context, context_key)
shutil.rmtree(tmp_folder)
# Legacy Microsoft Office Format
elif file_type in ['application/msword', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint']:
ole = OleFileIO(o.path)
meta = ole.get_metadata()