From 7fdda50a131bc9051bc25a4cdb67516ee75e1b0d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 8 Feb 2021 02:52:08 -0800 Subject: [PATCH] Let rejpg take glob patterns. --- rejpg.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rejpg.py b/rejpg.py index 6997102..d46feb8 100644 --- a/rejpg.py +++ b/rejpg.py @@ -11,20 +11,15 @@ import sys from voussoirkit import bytestring from voussoirkit import imagetools +from voussoirkit import pipeable +from voussoirkit import spinal PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True def rejpg_argparse(args): - if args.recurse: - from voussoirkit import spinal - walker = spinal.walk_generator() - files = list(walker) - else: - from voussoirkit import pathclass - files = pathclass.cwd().listdir() - files = [f for f in files if f.is_file] + patterns = pipeable.input_many(args.patterns, skip_blank=True, strip=True) + files = spinal.walk(recurse=args.recurse, glob_filenames=patterns) - files = [f for f in files if f.extension in ['.jpg', '.jpeg']] files = [f.absolute_path for f in files] bytes_saved = 0 @@ -55,6 +50,7 @@ def rejpg_argparse(args): def main(argv): parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('patterns', nargs='+', default={'*.jpg', '*.jpeg'}) parser.add_argument('--recurse', dest='recurse', action='store_true') parser.set_defaults(func=rejpg_argparse)