diff --git a/.context.yaml b/.context.yaml new file mode 100644 index 0000000..1d81aca --- /dev/null +++ b/.context.yaml @@ -0,0 +1,27 @@ +items: + COMMANDS.md: + contexts: [] + projects: [] + tags: + - super + - great + README.md: + contexts: [] + projects: [] + tags: + - fool + - writeme + TODO.md: + contexts: + - bbb + - python + note: Chawera + projects: + - fool + - proooo + - bokertov + tags: + - ttt + - rusty + - frrr + - xxx diff --git a/.gitignore b/.gitignore index 79a8c5d..bbdd57d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ __pycache__/ -.context.yaml \ No newline at end of file +#.context.yaml \ No newline at end of file diff --git a/orvani/cmd.py b/orvani/cmd.py index 7b7b4be..6ca5ae0 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -145,31 +145,64 @@ def main(): elif args.command in ['copy', 'cp']: if args.file and args.context: - orvani.move(args.file, args.context[0], True, args.no_file_operation) + 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: - orvani.move(args.file, args.context[0], False, args.no_file_operation) + 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: - orvani.delete(args.file, args.no_file_operation) + 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":thinking_face: 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 + cache_file = target / CACHE_FILE + context_file.unlink(missing_ok=True) + cache_file.unlink(missing_ok=True) if not args.file: args.file = '.' - target = Path(args.file) - context_file = target / CONTEXT_FILE - cache_file = target / CACHE_FILE - context_file.unlink(missing_ok=True) - cache_file.unlink(missing_ok=True) + purge(args.file) if args.not_recursive: for (root,dirs,files) in os.walk(args.file): if dirs: for dir in dirs: - rpath = os.path.join(root, dir) - Path(CONTEXT_FILE).unlink(missing_ok=True) - Path(CACHE_FILE).unlink(missing_ok=True) + purge(dir) elif args.command in ['clean']: if not args.file: diff --git a/orvani/orvani.py b/orvani/orvani.py index f71db23..9ff7fa1 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -233,7 +233,7 @@ class OrvaniTag: if target.name in self.DB: del self.DB[target.name] else: - return [2, target.name] + return [2, file] saved = self.__save() if not self.DB: Path(self.FILE).unlink(missing_ok=True) @@ -271,10 +271,11 @@ class OrvaniTag: if retain: shutil.copy2(source, dest) else: - shutil.move(source, dest, copy_function=shutil.copy2) + shutil.copy2(source, dest) + os.remove(source) return [0, source, dest, sourcedata] else: - return [1, os.path.isfile(source), os.path.isdir(os.path.dirname(dest))] + return [1, source, dest, os.path.isfile(source), os.path.isdir(os.path.dirname(dest))] def clean(self, path: str='.', recursive=True): diff --git a/orvani/plugins/.context.yaml b/orvani/plugins/.context.yaml new file mode 100644 index 0000000..cfdc427 --- /dev/null +++ b/orvani/plugins/.context.yaml @@ -0,0 +1,9 @@ +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/folder with spaces/.context.yaml b/test/folder with spaces/.context.yaml new file mode 100644 index 0000000..3ea5c7b --- /dev/null +++ b/test/folder with spaces/.context.yaml @@ -0,0 +1,6 @@ +items: + file with spaces.txt: + contexts: [] + projects: [] + tags: + - spaces diff --git a/test/sub/.context.yaml b/test/sub/.context.yaml new file mode 100644 index 0000000..3456507 --- /dev/null +++ b/test/sub/.context.yaml @@ -0,0 +1,9 @@ +items: + statement_14793553_USD_2022-11-01_2023-01-31.pdf: + contexts: [] + projects: [] + tags: + - yay + - frrrrrrrr + frrr.txt: + frrr