pretty rich output
This commit is contained in:
parent
8ed492915c
commit
9efbd434c7
5 changed files with 56 additions and 29 deletions
51
orvani.py
51
orvani.py
|
|
@ -1,7 +1,10 @@
|
|||
import os
|
||||
import sys
|
||||
import yaml
|
||||
import shutil
|
||||
from argparse import ArgumentParser as argp, SUPPRESS, RawTextHelpFormatter as raw
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
# Defaults
|
||||
|
||||
|
|
@ -258,10 +261,13 @@ class OrvaniTag:
|
|||
continue
|
||||
if exact:
|
||||
if search == context:
|
||||
result['found'] = self.INDEX[ctx][context]
|
||||
if self.INDEX[ctx][context] not in result['found']:
|
||||
result['found'] += self.INDEX[ctx][context]
|
||||
else:
|
||||
if search in context:
|
||||
result['found'] = self.INDEX[ctx][context]
|
||||
if self.INDEX[ctx][context] not in result['found']:
|
||||
result['found'] += self.INDEX[ctx][context]
|
||||
result['found'] = sorted(list(set(result['found'])), key=lambda x: x.count('/'))
|
||||
return result
|
||||
|
||||
def __indexfolder(self, sub: str):
|
||||
|
|
@ -279,12 +285,34 @@ class OrvaniTag:
|
|||
self.INDEX['files'].update( { path : self.DB[file]} )
|
||||
for ctx in self.CTX.keys():
|
||||
for item in self.DB[file][ctx]:
|
||||
if item:
|
||||
filelist = [path]
|
||||
if ctx in self.INDEX:
|
||||
if item in self.INDEX[ctx]:
|
||||
filelist += self.INDEX[ctx][item]
|
||||
self.INDEX.update( { ctx : { item : filelist } } )
|
||||
filelist = [path]
|
||||
if ctx in self.INDEX:
|
||||
if item in self.INDEX[ctx]:
|
||||
filelist += self.INDEX[ctx][item]
|
||||
self.INDEX[ctx][item] = filelist
|
||||
|
||||
def mktable(query: str, index: dict):
|
||||
table = Table(title=f"Results for `{query}`")
|
||||
table.add_column("Path", justify="right", style="white", no_wrap=True)
|
||||
table.add_column("Note", style="#cccccc")
|
||||
table.add_column("Projects", justify="center", style="cyan")
|
||||
table.add_column("Contexts", justify="center", style="magenta")
|
||||
table.add_column("Tags", justify="center", style="green")
|
||||
note = tags = projects = contexts = tags = ''
|
||||
for file in index['found']:
|
||||
path = file
|
||||
fc = index['index']['files'][file]
|
||||
if 'note' in fc:
|
||||
note = fc['note']
|
||||
else:
|
||||
note = ''
|
||||
tags = ' '.join(['#' + tag for tag in fc['tags']])
|
||||
projects = ' '.join(['+' + p for p in fc['projects']])
|
||||
contexts = ' '.join(['@' + c for c in fc['contexts']])
|
||||
table.add_row(path, note, projects, contexts, tags)
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
||||
def main():
|
||||
|
||||
|
|
@ -305,8 +333,8 @@ def main():
|
|||
"""
|
||||
|
||||
p = argp(description="OrvaniTagger", formatter_class=raw)
|
||||
p.add_argument("--not-recursive", "-nr", action="store_true", help="Include subdirectories in search")
|
||||
p.add_argument("--no-file_operation", "-nf", action="store_true", help="Copy/Move/Delete file, not just context")
|
||||
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("--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("--cache", action="store_true", help="Cache index search (useful with deep directory trees)")
|
||||
|
|
@ -350,9 +378,8 @@ def main():
|
|||
if args.command in ['listtag', 'lst', 'lt'] or args.context_filter == 'tag':
|
||||
args.context_filter = 'tags'
|
||||
if query:
|
||||
print(args.exact)
|
||||
r = orvani.list(query, args.path, args.context_filter, args.exact, args.not_recursive, args.cache)
|
||||
print(r)
|
||||
mktable(' '.join(sys.argv[1:]), r)
|
||||
|
||||
elif args.command in ['copy', 'cp']:
|
||||
if args.file and args.context:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue