simplified

This commit is contained in:
randogoth 2023-06-08 02:29:14 +03:00
parent 0d92741480
commit f17796e513
3 changed files with 13 additions and 76 deletions

View file

@ -74,12 +74,7 @@ def main():
'copy', 'cp',
'move', 'mv',
'del', 'rm',
'clear', 'c',
'listproj', 'lsprj',
'listcon', 'lsc',
'listtag', 'lst',
'clean', 'purge',
'read'
])
p.add_argument("file", nargs="?", type=str, help=SUPPRESS)
p.add_argument("context", nargs="*", type=str, help=SUPPRESS)
@ -103,14 +98,8 @@ def main():
if args.file and args.context:
orvani.remove(args.file, *args.context)
elif args.command in ['list', 'ls', 'dir', 'l', 'listproj', 'lsprj', 'lp', 'listcon', 'lsc', 'lc', 'listtag', 'lst', 'lt']:
elif args.command in ['list', 'ls', 'dir', 'l']:
query = [args.file] + args.context
if args.command in ['listproj', 'lsprj', 'lp'] or args.context_filter == 'project':
args.context_filter = 'projects'
if args.command in ['listcon', 'lsc', 'lc'] or args.context_filter == 'context':
args.context_filter = 'contexts'
if args.command in ['listtag', 'lst', 'lt'] or args.context_filter == 'tag':
args.context_filter = 'tags'
if query:
r = orvani.list(args.path, args.context_filter, args.exact, args.not_recursive, args.cache, *query)
mktable(' '.join(sys.argv[1:]), r)
@ -146,10 +135,7 @@ def main():
elif args.command in ['clean']:
if not args.file:
args.file = ''
orvani.purge(args.file, args.not_recursive)
elif args.command in ['read']:
orvani.read_meta()
orvani.clean(args.file, args.not_recursive)
if __name__ == '__main__':
main()

View file

@ -198,7 +198,7 @@ class OrvaniTag:
else:
shutil.move(source, dest, copy_function=shutil.copy2)
def purge(self, path: str='.', recursive=True):
def clean(self, path: str='.', recursive=True):
"""
Removes context data from folder if files do not exist
@ -225,7 +225,7 @@ class OrvaniTag:
if dirs:
for dir in dirs:
rpath = os.path.join(root, dir)
self.purge(rpath, False)
self.clean(rpath, False)
def list(self, path: str='./', filter=None, exact=True, recursive: bool=True, cache: bool=False, *search: str):
"""
@ -242,7 +242,7 @@ class OrvaniTag:
if path == '':
path = './'
self.__makeindex(path, recursive, cache)
result = self.__search(search, exact)
result = self.__search(search, filter, exact)
return result
@ -362,9 +362,14 @@ class OrvaniTag:
haystack = self.INDEX[param].keys()
for hay in haystack:
for needle in needles:
if needle in hay:
if self.INDEX[param][hay] not in return_dict[param]:
return_dict[param] += self.INDEX[param][hay]
if exact:
if needle == hay:
if self.INDEX[param][hay] not in return_dict[param]:
return_dict[param] += self.INDEX[param][hay]
else:
if needle in hay:
if self.INDEX[param][hay] not in return_dict[param]:
return_dict[param] += self.INDEX[param][hay]
if len(search) > 1:
result['found'] = list(set(self.__intersect(return_dict)))
else: