From 3a8aaddae197a297716c77e944a7b586cd9371c0 Mon Sep 17 00:00:00 2001 From: randogoth Date: Fri, 9 Jun 2023 01:32:20 +0300 Subject: [PATCH] plugin switch --- orvani/cmd.py | 3 ++- orvani/orvani.py | 12 +++++++----- orvani/plugins/office.py | 4 ++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/orvani/cmd.py b/orvani/cmd.py index fd77b7d..23acd71 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -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: diff --git a/orvani/orvani.py b/orvani/orvani.py index 961a4d5..bd9defa 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -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) diff --git a/orvani/plugins/office.py b/orvani/plugins/office.py index 302b20e..e3136e4 100644 --- a/orvani/plugins/office.py +++ b/orvani/plugins/office.py @@ -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()