Skip to content

Commit 116ec8c

Browse files
committed
Removed dependency on distutils.strtobool
1 parent 2aa8205 commit 116ec8c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

difPy/dif.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from multiprocessing import Pool
88
import numpy as np
99
from PIL import Image
10-
from distutils.util import strtobool
1110
import os
1211
from datetime import datetime
1312
from pathlib import Path
@@ -889,25 +888,31 @@ def _convert_str_to_int(x):
889888
except:
890889
return x
891890

891+
def _strtobool(value: str) -> bool:
892+
value = value.lower()
893+
if value in ("y", "yes", "on", "1", "true", "t"):
894+
return True
895+
return False
896+
892897
if __name__ == '__main__':
893898
# Parameters for when launching difPy via CLI
894899
parser = argparse.ArgumentParser(description='Find duplicate or similar images with difPy - https://github.com/elisemercury/Duplicate-Image-Finder')
895900
parser.add_argument('-D', '--directory', type=str, nargs='+', help='Paths of the directories to be searched. Default is working dir.', required=False, default=[os.getcwd()])
896901
parser.add_argument('-Z', '--output_directory', type=str, help='Output directory path for the difPy result files. Default is working dir.', required=False, default=None)
897-
parser.add_argument('-r', '--recursive', type=lambda x: bool(strtobool(x)), help='Search recursively within the directories.', required=False, choices=[True, False], default=True)
898-
parser.add_argument('-i', '--in_folder', type=lambda x: bool(strtobool(x)), help='Search for matches in the union of directories.', required=False, choices=[True, False], default=False)
899-
parser.add_argument('-le', '--limit_extensions', type=lambda x: bool(strtobool(x)), help='Limit search to known image file extensions.', required=False, choices=[True, False], default=True)
902+
parser.add_argument('-r', '--recursive', type=lambda x: bool(_help._strtobool(x)), help='Search recursively within the directories.', required=False, choices=[True, False], default=True)
903+
parser.add_argument('-i', '--in_folder', type=lambda x: bool(_help._strtobool(x)), help='Search for matches in the union of directories.', required=False, choices=[True, False], default=False)
904+
parser.add_argument('-le', '--limit_extensions', type=lambda x: bool(_help._strtobool(x)), help='Limit search to known image file extensions.', required=False, choices=[True, False], default=True)
900905
parser.add_argument('-px', '--px_size', type=int, help='Compression size of images in pixels.', required=False, default=50)
901906
parser.add_argument('-s', '--similarity', type=_help._convert_str_to_int, help='Similarity grade (mse).', required=False, default='duplicates')
902-
parser.add_argument('-ro', '--rotate', type=lambda x: bool(strtobool(x)), help='Rotate images during comparison process.', required=False, choices=[True, False], default=True)
903-
parser.add_argument('-la', '--lazy', type=lambda x: bool(strtobool(x)), help='Compares image dimensions before comparison process.', required=False, choices=[True, False], default=True)
907+
parser.add_argument('-ro', '--rotate', type=lambda x: bool(_help._strtobool(x)), help='Rotate images during comparison process.', required=False, choices=[True, False], default=True)
908+
parser.add_argument('-la', '--lazy', type=lambda x: bool(_help._strtobool(x)), help='Compares image dimensions before comparison process.', required=False, choices=[True, False], default=True)
904909
parser.add_argument('-mv', '--move_to', type=str, help='Output directory path of lower quality images among matches.', required=False, default=None)
905-
parser.add_argument('-d', '--delete', type=lambda x: bool(strtobool(x)), help='Delete lower quality images among matches.', required=False, choices=[True, False], default=False)
906-
parser.add_argument('-sd', '--silent_del', type=lambda x: bool(strtobool(x)), help='Suppress the user confirmation when deleting images.', required=False, choices=[True, False], default=False)
907-
parser.add_argument('-p', '--show_progress', type=lambda x: bool(strtobool(x)), help='Show the real-time progress of difPy.', required=False, choices=[True, False], default=True)
910+
parser.add_argument('-d', '--delete', type=lambda x: bool(_help._strtobool(x)), help='Delete lower quality images among matches.', required=False, choices=[True, False], default=False)
911+
parser.add_argument('-sd', '--silent_del', type=lambda x: bool(_help._strtobool(x)), help='Suppress the user confirmation when deleting images.', required=False, choices=[True, False], default=False)
912+
parser.add_argument('-p', '--show_progress', type=lambda x: bool(_help._strtobool(x)), help='Show the real-time progress of difPy.', required=False, choices=[True, False], default=True)
908913
parser.add_argument('-proc', '--processes', type=_help._convert_str_to_int, help=' Number of worker processes for multiprocessing.', required=False, default=None)
909914
parser.add_argument('-ch', '--chunksize', type=_help._convert_str_to_int, help='Only relevant when dataset > 5k images. Sets the batch size at which the job is simultaneously processed when multiprocessing.', required=False, default=None)
910-
parser.add_argument('-l', '--logs', type=lambda x: bool(strtobool(x)), help='(Deprecated) Collect statistics during the process.', required=False, choices=[True, False], default=None)
915+
parser.add_argument('-l', '--logs', type=lambda x: bool(_help._strtobool(x)), help='(Deprecated) Collect statistics during the process.', required=False, choices=[True, False], default=None)
911916

912917
args = parser.parse_args()
913918

0 commit comments

Comments
 (0)