finalized verbosity, bugfixes
This commit is contained in:
parent
07ad688af6
commit
e514223ad9
11 changed files with 106 additions and 114 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
items:
|
||||
hashdoubleslash.py:
|
||||
contexts:
|
||||
- python
|
||||
note: It even works in Python code
|
||||
projects:
|
||||
- orvani
|
||||
tags:
|
||||
- example
|
||||
Loading…
Add table
Add a link
Reference in a new issue