From b4297f0284cbbfab0e43439ff2ae20dfa955025d Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 24 Dec 2019 04:51:08 -0600 Subject: [PATCH] added zero files detection, fixed picture mime checker properly, mostly finished for tonight i'm tired af. 5am almost --- truefile/cli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/truefile/cli.py b/truefile/cli.py index 31731b1..8b51665 100644 --- a/truefile/cli.py +++ b/truefile/cli.py @@ -19,7 +19,7 @@ def unequal(x, y): return x != '.' + y.extension @cli.command() -@click.option('-s', '--showall', is_flag=True, help='Show all files regardless of detected extension mishaps') +@click.option('-s', '--showall', is_flag=True, help='Show all files regardless of detected extension mishaps (detected =/= current).') @click.option('-p', '--picture', is_flag=True, help='Hard filter against original files being pictures.') def detect(showall, picture): colorama.init() @@ -30,14 +30,15 @@ def detect(showall, picture): 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 + if picture: + files = list(filter(lambda x : x[2].mime.split('/')[0] == 'image', files)) 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].extension}{colorama.Fore.RESET}', files))) # print with proper spacing - print(colorama.Style.RESET_ALL, end='') + if len(files) > 0: + 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].extension}{colorama.Fore.RESET}', files))) # print with proper spacing + print(colorama.Style.RESET_ALL, end='') @cli.command() def rename():