Let rejpg take glob patterns.
This commit is contained in:
parent
8edefba1ad
commit
7fdda50a13
1 changed files with 5 additions and 9 deletions
14
rejpg.py
14
rejpg.py
|
@ -11,20 +11,15 @@ import sys
|
||||||
|
|
||||||
from voussoirkit import bytestring
|
from voussoirkit import bytestring
|
||||||
from voussoirkit import imagetools
|
from voussoirkit import imagetools
|
||||||
|
from voussoirkit import pipeable
|
||||||
|
from voussoirkit import spinal
|
||||||
|
|
||||||
PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True
|
PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
|
||||||
def rejpg_argparse(args):
|
def rejpg_argparse(args):
|
||||||
if args.recurse:
|
patterns = pipeable.input_many(args.patterns, skip_blank=True, strip=True)
|
||||||
from voussoirkit import spinal
|
files = spinal.walk(recurse=args.recurse, glob_filenames=patterns)
|
||||||
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]
|
|
||||||
|
|
||||||
files = [f for f in files if f.extension in ['.jpg', '.jpeg']]
|
|
||||||
files = [f.absolute_path for f in files]
|
files = [f.absolute_path for f in files]
|
||||||
|
|
||||||
bytes_saved = 0
|
bytes_saved = 0
|
||||||
|
@ -55,6 +50,7 @@ def rejpg_argparse(args):
|
||||||
def main(argv):
|
def main(argv):
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
|
||||||
|
parser.add_argument('patterns', nargs='+', default={'*.jpg', '*.jpeg'})
|
||||||
parser.add_argument('--recurse', dest='recurse', action='store_true')
|
parser.add_argument('--recurse', dest='recurse', action='store_true')
|
||||||
parser.set_defaults(func=rejpg_argparse)
|
parser.set_defaults(func=rejpg_argparse)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue