Add option to append special characters to whitelist

This commit is contained in:
Kjistóf 2017-05-28 19:55:21 +02:00 committed by Kristóf Tóth
parent 0da93de25a
commit e20f442016

View File

@ -5,18 +5,26 @@ from os.path import basename, dirname
from os.path import join as joinpath
from argparse import ArgumentParser
parser = ArgumentParser(description='Eliminate funky stuff from filenames.')
parser.add_argument('--separator', '-s', type=str, nargs='?', default='_',
help='Set separator to use (to replace spaces with).')
parser.add_argument('--allow', '-a', type=str, nargs='?', action='append',
help='Specify a special character to allow (it will not be removed).')
parser.add_argument('--whitelist', '-w', type=str,
help='Overwrite default whitelist (format: whitespace separated string).')
parser.add_argument('files', type=str, nargs='+',
help='File(s) to normalise the name of (relative or absolute path).')
args = parser.parse_args()
# special characters that will not be removed
whitelist = {' ', '.', '-'}
if args.whitelist: whitelist = set(args.whitelist.split())
whitelist.add(args.separator)
if args.allow: whitelist = whitelist.union(set(args.allow))
for path in args.files:
dir = dirname(path)