added zero files detection, fixed picture mime checker properly, mostly finished for tonight

i'm tired af. 5am almost
This commit is contained in:
Xevion
2019-12-24 04:51:08 -06:00
parent ab09e6be38
commit b4297f0284

View File

@@ -19,7 +19,7 @@ def unequal(x, y):
return x != '.' + y.extension return x != '.' + y.extension
@cli.command() @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.') @click.option('-p', '--picture', is_flag=True, help='Hard filter against original files being pictures.')
def detect(showall, picture): def detect(showall, picture):
colorama.init() colorama.init()
@@ -30,14 +30,15 @@ def detect(showall, picture):
files = zip(files, map(guess, files)) # get scan of file type 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 = 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 picture:
files = list(filter(lambda x : x[2].mime.split('/')[0] == 'image', files))
if not showall: if not showall:
files = list(filter(lambda x : unequal(x[1], x[2]), files)) # filter for differing extensions 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.') print(f'Scanned {len(files)} files.')
largest = max(map(lambda x : len(x[0]), files)) # get length of the longest file name if len(files) > 0:
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 largest = max(map(lambda x : len(x[0]), files)) # get length of the longest file name
print(colorama.Style.RESET_ALL, end='') 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() @cli.command()
def rename(): def rename():