Add option to select quality measurement method to use

This commit is contained in:
Kristóf Tóth 2018-02-24 21:16:19 +01:00
parent 05e077105a
commit 7a186ec82e

View File

@ -50,17 +50,20 @@ class imgrate:
if __name__ == '__main__': if __name__ == '__main__':
from os import remove from os import remove
from sys import exit
def parse_arguments(): def parse_arguments():
ap = ArgumentParser() ap = ArgumentParser()
ap.add_argument('images', type=str, nargs='+', help='') ap.add_argument('images', type=str, nargs='+', help='')
ap.add_argument('-d', '--delete', action='store_true', help='Delete all but the best quality image.') ap.add_argument('-d', '--delete', action='store_true', help='Delete all but the best quality image.')
ap.add_argument('-q', '--quiet', action='store_true', help='Print quality measurements only.') ap.add_argument('-q', '--quiet', action='store_true', help='Print quality measurements only.')
ap.add_argument('-m', '--method', type=str, default='quality', help='Select quality measurement to use.')
return ap.parse_args() return ap.parse_args()
def run(args): def run(args):
ratings = {image: imgrate(image).quality for image in args.images} try: ratings = {image: getattr(imgrate(image), args.method) for image in args.images}
except AttributeError: exit('Invalid --method option!')
maximum = max(ratings, key=ratings.get) maximum = max(ratings, key=ratings.get)
for rating in ratings.keys(): for rating in ratings.keys():