suppress traceback errors

This commit is contained in:
randogoth 2023-06-12 01:25:40 +03:00
parent e514223ad9
commit 5f8875389e
2 changed files with 136 additions and 133 deletions

View file

@ -2,5 +2,4 @@
tags:
- frrr
---
+ documentation
+ rich verbosity
+ documentation

View file

@ -114,141 +114,145 @@ def main():
orvani.ENABLE_PLUGINS = args.no_plugins
if args.command in ['add', 'a']:
if args.file and args.context:
fb = orvani.add(args.file, *args.context)
if fb[0] == 0:
console.print(f':label: Entry {nice_context(fb[2])}successfully added to file [strong]{fb[1]}[/strong].')
elif fb[0] == 1:
console.print(f":thinking_face: File [strong]{fb[1]}[/strong] doesn't exist.")
try:
if args.command in ['add', 'a']:
if args.file and args.context:
fb = orvani.add(args.file, *args.context)
if fb[0] == 0:
console.print(f':label: Entry {nice_context(fb[2])}successfully added to file [strong]{fb[1]}[/strong].')
elif fb[0] == 1:
console.print(f":thinking_face: File [strong]{fb[1]}[/strong] doesn't exist.")
elif args.command in ['remove', 'rem', 'r']:
if args.file and args.context:
fb = orvani.remove(args.file, *args.context)
elif args.command in ['remove', 'rem', 'r']:
if args.file and args.context:
fb = orvani.remove(args.file, *args.context)
if fb[0] == 0:
console.print(f':wastebasket: Entry {nice_context(fb[2])}successfully removed 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 match found for [white][strong]{fb[1]}[/strong][/white] and {nice_context(fb[2])}")
elif args.command in ['list', 'ls', 'dir', 'l']:
query = [args.file] + args.context
if query:
r = orvani.list(args.path, args.exact, args.either, args.not_recursive, args.cache, args.delete_cache, *query)
filter = None
if args.files:
filter = 'files'
elif args.dirs:
filter = 'dirs'
mktable(' '.join(sys.argv[1:]), r, filter)
elif args.command in ['copy', 'cp']:
if args.file and args.context:
fb = orvani.move(args.file, args.context[0], True, args.no_file_operation)
if fb[0] == 0:
console.print(f':dancers: File [strong]{fb[1]}[/strong] with entry {nice_context(fb[3])}successfully copied to [strong]{fb[2]}[/strong]')
elif fb[0] == 1:
if fb[3] == False and fb[4] == True:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] doesn't exist.")
elif fb[3] == True and fb[4] == False:
console.print(f":thinking_face: Destination [strong]{fb[2]}[/strong] doesn't exist.")
elif fb[3] == False and fb[4] == False:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] and destination [strong]{fb[2]}[/strong] don't exist.")
elif args.command in ['move', 'mv']:
if args.file and args.context:
fb = orvani.move(args.file, args.context[0], False, args.no_file_operation)
if fb[0] == 0:
console.print(f':dancers: File [strong]{fb[1]}[/strong] with entry {nice_context(fb[3])}successfully moved to [strong]{fb[2]}[/strong]')
elif fb[0] == 1:
if fb[3] == False and fb[4] == True:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] doesn't exist.")
elif fb[3] == True and fb[4] == False:
console.print(f":thinking_face: Destination [strong]{fb[2]}[/strong] doesn't exist.")
elif fb[3] == False and fb[4] == False:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] and destination [strong]{fb[2]}[/strong] don't exist.")
elif args.command in ['del', 'rm']:
if args.file:
fb = orvani.delete(args.file, args.no_file_operation)
if fb[0] == 0:
status = f':wastebasket: Entry for [strong]{fb[1]}[/strong] successfully removed.'
if fb[3]:
status += f'\n:wastebasket: File [strong]{fb[1]}[/strong] successfully deleted.'
if not fb[2] == None:
status += f'\n:wastebasket: File [strong]{fb[2]}[/strong] automatically deleted.'
console.print(status)
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 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
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)
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 = ''
fb = orvani.clean(args.file, args.not_recursive)
if fb[0] == 0:
console.print(f':wastebasket: Entry {nice_context(fb[2])}successfully removed from file [strong]{fb[1]}[/strong].')
elif fb[0] == 1:
console.print(f":thinking_face: File [strong]{fb[1]}[/strong] doesn't exist.")
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:
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']:
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 match found for [white][strong]{fb[1]}[/strong][/white] and {nice_context(fb[2])}")
console.print(f":mag: No entries found.")
elif args.command in ['list', 'ls', 'dir', 'l']:
query = [args.file] + args.context
if query:
r = orvani.list(args.path, args.exact, args.either, args.not_recursive, args.cache, args.delete_cache, *query)
filter = None
if args.files:
filter = 'files'
elif args.dirs:
filter = 'dirs'
mktable(' '.join(sys.argv[1:]), r, filter)
elif args.command in ['copy', 'cp']:
if args.file and args.context:
fb = orvani.move(args.file, args.context[0], True, args.no_file_operation)
if fb[0] == 0:
console.print(f':dancers: File [strong]{fb[1]}[/strong] with entry {nice_context(fb[3])}successfully copied to [strong]{fb[2]}[/strong]')
elif fb[0] == 1:
if fb[3] == False and fb[4] == True:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] doesn't exist.")
elif fb[3] == True and fb[4] == False:
console.print(f":thinking_face: Destination [strong]{fb[2]}[/strong] doesn't exist.")
elif fb[3] == False and fb[4] == False:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] and destination [strong]{fb[2]}[/strong] don't exist.")
elif args.command in ['move', 'mv']:
if args.file and args.context:
fb = orvani.move(args.file, args.context[0], False, args.no_file_operation)
if fb[0] == 0:
console.print(f':dancers: File [strong]{fb[1]}[/strong] with entry {nice_context(fb[3])}successfully moved to [strong]{fb[2]}[/strong]')
elif fb[0] == 1:
if fb[3] == False and fb[4] == True:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] doesn't exist.")
elif fb[3] == True and fb[4] == False:
console.print(f":thinking_face: Destination [strong]{fb[2]}[/strong] doesn't exist.")
elif fb[3] == False and fb[4] == False:
console.print(f":thinking_face: Source file [strong]{fb[1]}[/strong] and destination [strong]{fb[2]}[/strong] don't exist.")
elif args.command in ['del', 'rm']:
if args.file:
fb = orvani.delete(args.file, args.no_file_operation)
if fb[0] == 0:
status = f':wastebasket: Entry for [strong]{fb[1]}[/strong] successfully removed.'
if fb[3]:
status += f'\n:wastebasket: File [strong]{fb[1]}[/strong] successfully deleted.'
if not fb[2] == None:
status += f'\n:wastebasket: File [strong]{fb[2]}[/strong] automatically deleted.'
console.print(status)
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 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
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)
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 = ''
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:
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']:
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']:
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.")
elif args.command in ['import']:
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.")
except Exception as e:
console.print(f":scream: An Exception occurred: [italic]{e}[/italic]")
if __name__ == '__main__':
main()