From e514223ad9d17c8872e08901af1b754d9af9f272 Mon Sep 17 00:00:00 2001 From: randogoth Date: Mon, 12 Jun 2023 01:08:50 +0300 Subject: [PATCH] finalized verbosity, bugfixes --- .context.yaml | 7 +- context.txt | 18 ++-- orvani/cmd.py | 57 +++++++++--- orvani/orvani.py | 84 ++++++++++-------- orvani/plugins/.context.yaml | 9 -- test/.context.yaml | 23 ++--- test/folder with spaces/.context.yaml | 6 -- test/office.odt | Bin 9200 -> 8940 bytes test/sub/.context.yaml | 3 - ...ent_14793553_USD_2022-11-01_2023-01-31.pdf | Bin 125125 -> 125125 bytes todo.txt | 13 --- 11 files changed, 106 insertions(+), 114 deletions(-) delete mode 100644 orvani/plugins/.context.yaml delete mode 100644 test/folder with spaces/.context.yaml delete mode 100644 todo.txt diff --git a/.context.yaml b/.context.yaml index 1d81aca..438432d 100644 --- a/.context.yaml +++ b/.context.yaml @@ -3,25 +3,22 @@ items: contexts: [] projects: [] tags: - - super - great README.md: contexts: [] projects: [] tags: - fool - - writeme TODO.md: contexts: - bbb - python note: Chawera projects: - - fool - proooo + - fool - bokertov tags: - - ttt - rusty - - frrr - xxx + - ttt diff --git a/context.txt b/context.txt index f392700..7cfe933 100644 --- a/context.txt +++ b/context.txt @@ -1,16 +1,12 @@ ./COMMANDS.md --- +coding @erfwegf #great #super This is awesome ./README.md --- @frrreee #writeme #fool -./TODO.md --- +bokertov @python #rusty Chawera #frrr -./test/chirpy.wav --- +parakeetio +sensorwatch @watch McFlu McFlu McFlu This is a title -./test/folder with spaces --- +totally #spaces -./test/office.odt --- +oopsie +orvani #whoa +orvani @this #that #whoa and a note +./TODO.md --- +bokertov +proooo +fool @bbb @python #ttt #xxx #frrr #rusty Chawera +./test/chirpy.wav --- +parakeetio +sensorwatch @Chripo @watch #funk McFlu McFlu This is a title This is a title +./test/folder with spaces/file with spaces.txt --- #spaces +./test/office.odt --- +oopsie +orvani @this #whoa #that and a note +./test/oldword.doc --- and a note ./test/sheet.xlsx --- +orvani @calc #tessssting -./test/sub --- @folder -./test/test.txt --- +test @test #faa #test frrr +./test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf --- +yeeha @pdfcontext #yay #frrrrrrrr And a comment too ./test/table.ods --- @calc #tessssting ./test/tableold.xls --- @calc #tessssting -./test/oldword.doc --- and a note -./test/word.docx --- @concon #tagz -./test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf --- +yeeha @pdfcontext #yay #frrrrrrrr And a comment too -./test/folder with spaces/file with spaces.txt --- #spaces -./orvani/plugins/hashdoubleslash.py --- +orvani @python #example It even works in Python code +./test/word.docx --- @concon #tagz #choo what is that smell? diff --git a/orvani/cmd.py b/orvani/cmd.py index 6ca5ae0..9c4b744 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -182,42 +182,73 @@ def main(): elif fb[0] == 1: console.print(f":thinking_face: File [strong]{fb[1]}[/strong] doesn't exist.") elif fb[0] == 2: - console.print(f":thinking_face: No entry for [strong]{fb[1]}[/strong] found.") + console.print(f":mag: No entry for [strong]{fb[1]}[/strong] found.") elif args.command in ['purge']: + def purge(path): target = Path(path) if target.is_file(): target = Path(target.parent) if target.is_dir(): context_file = target / CONTEXT_FILE + if context_file.exists(): + context_file.unlink(missing_ok=True) + console.print(f":wastebasket: File [strong]{context_file}[/strong] successfully purged.") cache_file = target / CACHE_FILE - context_file.unlink(missing_ok=True) - cache_file.unlink(missing_ok=True) + if cache_file.exists(): + cache_file.unlink(missing_ok=True) + console.print(f":wastebasket: File [strong]{cache_file}[/strong] successfully purged.") + if not args.file: args.file = '.' - purge(args.file) - if args.not_recursive: - for (root,dirs,files) in os.walk(args.file): - if dirs: - for dir in dirs: - purge(dir) + purge(args.file) + for (root,dirs,files) in os.walk(args.file): + if dirs: + for dir in dirs: + pp = os.path.join(root, dir) + purge(pp) elif args.command in ['clean']: if not args.file: args.file = '' - orvani.clean(args.file, args.not_recursive) + fb = orvani.clean(args.file, args.not_recursive) + if fb[0] == 0: + sub = '' + if args.not_recursive: + sub = ' and subdirectories' + console.print(f':broom: {fb[2]} entries cleaned from [strong]{fb[1]}[/strong]{sub}') elif args.command in ['write']: if args.file and args.context: - orvani.write(args.context[0], args.file) + fb = orvani.write(args.context[0], args.file) + if fb[0] == 0: + console.print(f':floppy_disk: Metadata {nice_context(fb[2])}successfully written to file [strong]{fb[1]}[/strong].') + if fb[0] == 4: + console.print(f':card_file_box: Plugin [strong]{fb[2]}[/strong] can only write to files types: [strong]{"[/strong], [strong]".join(fb[1])}[/strong].') + if fb[3]: + console.print(f':information: Plugin configuration found in folder context file.') + if fb[0] == 5: + console.print(f':disappointed: Plugin [strong]{fb[1]}[/strong] can\'t write.') elif args.command in ['export']: - orvani.export(args.file) + fb = orvani.export(args.file) + if fb[0] == 0: + console.print(f':floppy_disk: All entries successfully written to file [strong]{fb[1]}[/strong].') + elif fb[0] == 2: + console.print(f":mag: No entries found.") elif args.command in ['import']: - orvani.load(args.file) + fb = orvani.load(args.file) + if fb[0] == 0: + console.print(f':inbox_tray: [strong]{fb[2]}[/strong] entries successfully imported from file [strong]{fb[1]}[/strong].') + elif fb[0] == 1: + console.print(f":thinking_face: File [strong]{fb[1]}[/strong] doesn't exist.") + elif fb[0] == 2: + console.print(f":mag: No entries found in file [strong]{fb[1]}[/strong].") + elif fb[0] == 4: + console.print(f":thinking_face: File [strong]{fb[1]}[/strong] has wrong format. Cannot import.") if __name__ == '__main__': main() diff --git a/orvani/orvani.py b/orvani/orvani.py index 9ff7fa1..82f670f 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -288,6 +288,9 @@ class OrvaniTag: if path == '': path = '.' target = Path(path) + count = 0 + if target.is_file(): + target = Path(target.parent) if target.is_dir(): self.__cd(path) DB = self.DB.copy() @@ -296,6 +299,7 @@ class OrvaniTag: if not f.is_file(): if file in self.DB: del DB[file] + count += 1 self.DB = DB self.__save() if not self.DB: @@ -305,10 +309,9 @@ class OrvaniTag: if dirs: for dir in dirs: rpath = os.path.join(root, dir) - self.clean(rpath, False) - return [0, str(target)] - else: - return [3, str(target)] + fb = self.clean(rpath, False) + count += fb[2] + return [0, str(target), count] def list(self, path: str='./', exact=True, either=False, recursive: bool=True, cache: bool=False, delete_cache: bool=False, *search: str): """ @@ -511,7 +514,7 @@ class OrvaniTag: for context_key in context.keys(): self.__updateindex(filename, context, context_key) - def __collect_contexts(self, context: dict, delineate: bool = False): + def __collect_contexts(self, context: dict): elements = [] context_keys = list(CONTEXTS.keys()) for context_key in context_keys: @@ -525,10 +528,7 @@ class OrvaniTag: if not type(context[context_key]) == str: elements.append(' '.join([prefix + tag for tag in context[context_key]])) else: - if delineate: - elements.append(f"'{context[context_key]}'") - else: - elements.append(context[context_key]) + elements.append(context[context_key]) return elements def write(self, filename: str, method: str): @@ -551,6 +551,11 @@ class OrvaniTag: if plugin_name in self.CONFIG: if 'types' in self.CONFIG[plugin_name]: suffixes = self.CONFIG[plugin_name]['types'] + for suffix in suffixes: + if not suffix in plugin.TYPES: + suffixes.remove(suffix) + if not suffixes: + suffixes = plugin.TYPES o.file = Path(filename) if o.file.suffix in suffixes: self.__makeindex(o.file.parent, recursive=False) @@ -564,7 +569,7 @@ class OrvaniTag: else: return [5, plugin_name] else: - return [4, suffixes, plugin_name in self.CONFIG] + return [4, suffixes, plugin_name, plugin_name in self.CONFIG] def export(self, filename:str): if filename == '' or filename == None: @@ -590,35 +595,40 @@ class OrvaniTag: imported = file.read_text().split('\n') if len(imported): known = self.list(file.parent, False, False, True, False, False, '')['index']['items'] + count = 0 for import_line in imported: - line_elements = import_line.split('---') - if len(line_elements) > 1: - context = {} - path = line_elements[0].strip() - new_file = Path(path) - if new_file.exists(): - string = line_elements[1].strip() - if string: - new_file_context = self.__context(self.get_argv(string)) - if path in known.keys(): - known_file_context = known[path] - context = new_file_context.copy() - for new_context in new_file_context: - if type(new_file_context[new_context]) == list: - for context_item in new_file_context[new_context]: + if len(import_line) > 5: + line_elements = import_line.split(' --- ') + if len(line_elements) > 1: + context = {} + path = line_elements[0].strip() + new_file = Path(path) + if new_file.exists(): + string = line_elements[1].strip() + if string: + new_file_context = self.__context(self.get_argv(string)) + if path in known.keys(): + known_file_context = known[path] + context = new_file_context.copy() + for new_context in new_file_context: + if type(new_file_context[new_context]) == list: + for context_item in new_file_context[new_context]: + if new_context in known_file_context.keys(): + if context_item in known_file_context[new_context]: + context[new_context].remove(context_item) + else: if new_context in known_file_context.keys(): - if context_item in known_file_context[new_context]: - context[new_context].remove(context_item) - else: - if new_context in known_file_context.keys(): - if new_file_context[new_context] == known_file_context[new_context]: - del context[new_context] - ctx_str = self.__collect_contexts(context) - if ctx_str: - self.add(path, *ctx_str) - return [0, filename, len(context.keys())] - else: - return [4, filename] + if new_file_context[new_context] == known_file_context[new_context]: + del context[new_context] + ctx_str = self.__collect_contexts(context) + if ctx_str: + count += 1 + argv = self.get_argv(' '.join(ctx_str)) + print(argv) + self.add(path, *argv) + else: + return [4, filename] + return [0, filename, count] else: return [2, filename] else: diff --git a/orvani/plugins/.context.yaml b/orvani/plugins/.context.yaml deleted file mode 100644 index cfdc427..0000000 --- a/orvani/plugins/.context.yaml +++ /dev/null @@ -1,9 +0,0 @@ -items: - hashdoubleslash.py: - contexts: - - python - note: It even works in Python code - projects: - - orvani - tags: - - example \ No newline at end of file diff --git a/test/.context.yaml b/test/.context.yaml index 332f365..5a75a24 100644 --- a/test/.context.yaml +++ b/test/.context.yaml @@ -1,30 +1,19 @@ -config: - id3: - map: - contexts: artist - note: title - projects: album - tags: genre items: chirpy.wav: - contexts: [] - note: McFlu McFlu McFlu This is a title + contexts: + - Chripo projects: - - parakeetio - sensorwatch tags: [] office.odt: contexts: [] projects: - oopsie - - orvani tags: - whoa - - that - test.txt: - contexts: - - bbb - note: dededede + word.docx: + contexts: [] + note: what is that smell? projects: [] tags: - - ttt + - choo diff --git a/test/folder with spaces/.context.yaml b/test/folder with spaces/.context.yaml deleted file mode 100644 index 3ea5c7b..0000000 --- a/test/folder with spaces/.context.yaml +++ /dev/null @@ -1,6 +0,0 @@ -items: - file with spaces.txt: - contexts: [] - projects: [] - tags: - - spaces diff --git a/test/office.odt b/test/office.odt index 01eb5e983c307277a14eeac3e62b459b497a4a7a..bcf4fb8810d2126979d5876e7d268f8b8ea84118 100644 GIT binary patch delta 2506 zcmez1{>HUFz?+#xgaHI38P0@(Xc!h?U|?|0&r8cpFD*(e$;{6yHqytfnv;Qn!Phm! zQP0CRl?{U`qq`%%--?Q2mwLRBrFfzdW z3~`3oh6knlI2ag&4Hy`>7#J9eODc0xi}fmUbKXWp_ut+nSoePY=3K#T94HQ)v~kBH zBPIq0Ue?L;nWgJp7RhbP5#AQG#lc@wYJuK`Xotz!ooju#R75T7<7Z8hIqo@8Y*)u_ zTsNd2$NHFfQ%3-gx!H+26-LYji>SVJc zsjm33^Mw2-O)F*_lc>K;X@z3(wOOub50^~%8gu?NrIUc2S>fwx!KkItL6 zzA3AEO08t>xd|sVmu0TZ431T^TKY4!CzS83&I?0BS)og7_pfeYy&UkYYR|EU2cxrN zrX2S3c))!9?t{_~k)GV_*-eLHm+z|E~xZTUvj&Tm3jH-g5s}wCH=~e`sm%*{PEo(ikVF^D5Q9=J`<%{iLpKo&P^Wchkq-bDP($RfwLz(|D_BLdxxvhAuxCW@)Za zV+vh7Q{!SwS`rictj%t`h8{BxIyCQC)TOxU{SWOvZ|i-v-#&2~L>pA>`n7XSu~!BY zS_Dk-Zs*ozWMEKbWZ5h$=f%hkDQFl#h1X!FtV2yOM~UI!KY2z{Yw z)qpolC!~-?)B_9*JP=)Aa!X?!sK`w%Dap)B2N${lXgXoF#N;w%f%+|tm)IE?lJoOQ zQu9hcMKroX`b1RCI0V zwFg3*2rqJ7g02rye?TfRguY**3=FxcC5c$PCmRMSFc=s%F*7ho!1RD!86+_|pI1r; z-5z)XXJKFvMbYq1a2i6J;jeM0YjJ zsM#_T7s{boldmYQ5AxAv8O+vFNq&A#Qeu%ly1QZKamr52#OE@3lt6HloxD*&S%ei- T1Tcs)h%!X5GBDK1g46&2S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~8%5V-14VIGkSgEF?_|V93lj5EbM&#OVFRgYWteYt!!fHI1B0(?h@-Bj apWEc0^86yK;J6cH5M)SYVPGf)rvd<4G(8yr diff --git a/test/sub/.context.yaml b/test/sub/.context.yaml index 3456507..65e0f78 100644 --- a/test/sub/.context.yaml +++ b/test/sub/.context.yaml @@ -4,6 +4,3 @@ items: projects: [] tags: - yay - - frrrrrrrr - frrr.txt: - frrr diff --git a/test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf b/test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf index 614e6d81ab69e8f62792ce8d327c2b7af4d3f3c8..82cb63ef517df26e3082d49ccfc1a368527ff016 100644 GIT binary patch delta 30 gcmX?lk^SgJ_6hBLm5G%K%4tPV&^UGLR7Qgr0MWh;WdHyG delta 30 gcmX?lk^SgJ_6hBLX+=<=pj??)**JCUR7Qgr0M%&?WdHyG diff --git a/todo.txt b/todo.txt deleted file mode 100644 index 8d12d6d..0000000 --- a/todo.txt +++ /dev/null @@ -1,13 +0,0 @@ -./COMMANDS.md --- +coding @erfwegf #great #super This is awesome -./README.md --- @frrreee #fool #writeme -./TODO.md --- +bokertov @python #rusty #frrr Chawera -./orvani/plugins/hashdoubleslash.py --- +orvani @python #example It even works in Python code -./test/chirpy.wav --- +parakeetio +sensorwatch @watch @Chripo @Chripo McFlu #funk McFlu McFlu This is a title This is a title; This is a title -./test/folder with spaces/file with spaces.txt --- #spaces -./test/office.odt --- +oopsie +orvani @this #whoa #that and a note -./test/oldword.doc --- and a note -./test/sheet.xlsx --- +orvani @calc #tessssting -./test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf --- +yeeha @pdfcontext #frrrrrrrr #yay And a comment too -./test/table.ods --- @calc #tessssting -./test/tableold.xls --- @calc #tessssting -./test/word.docx --- @concon #tagz