From ab09e6be383e25526cb1216555786f2f9a445c7a Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 24 Dec 2019 04:35:21 -0600 Subject: [PATCH] completed picture detection filtering via preservation of original filetype object --- truefile/cli.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/truefile/cli.py b/truefile/cli.py index 94a9d30..31731b1 100644 --- a/truefile/cli.py +++ b/truefile/cli.py @@ -11,12 +11,12 @@ def cli(): def guess(*args, **kwargs): try: g = filetype.guess(*args, **kwargs) - return g.extension if g is not None else g + return g if g is not None else g except PermissionError: return None def unequal(x, y): - return x != y + return x != '.' + y.extension @cli.command() @click.option('-s', '--showall', is_flag=True, help='Show all files regardless of detected extension mishaps') @@ -29,11 +29,14 @@ def detect(showall, picture): files = filter(os.path.isfile, files) # file not directory files = zip(files, map(guess, files)) # get scan of file type files = filter(lambda x : x[1] is not None, files) # filter for only images - files = list(map(lambda x : (x[0], os.path.splitext(x[0])[1], '.' + x[1]), files)) # find just the file extension and put into tuple + files = list(map(lambda x : (x[0], os.path.splitext(x[0])[1], x[1]), files)) # find just the file extension and put into tuple if not showall: files = list(filter(lambda x : unequal(x[1], x[2]), files)) # filter for differing extensions + if picture: + files = list(filter(lambda x : x.mimetype == 'image', files)) + print(f'Scanned {len(files)} files.') largest = max(map(lambda x : len(x[0]), files)) # get length of the longest file name - print('\n'.join(map(lambda x : f'{x[0].ljust(largest)} | {colorama.Fore.RED if unequal(x[1], x[2]) else colorama.Fore.GREEN}{x[1]} -> {x[2]}{colorama.Fore.RESET}', files))) # print with proper spacing + print('\n'.join(map(lambda x : f'{x[0].ljust(largest)} | {colorama.Fore.RED if unequal(x[1], x[2]) else colorama.Fore.GREEN}{x[1]} -> {x[2].extension}{colorama.Fore.RESET}', files))) # print with proper spacing print(colorama.Style.RESET_ALL, end='') @cli.command()