picture_name_date: Remove progress bar supportsuffixes

This commit is contained in:
Geoffrey Frogeye 2022-11-04 14:09:01 +01:00
parent ceaa2d1671
commit 060e9db995
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -9,7 +9,6 @@ import typing
import coloredlogs import coloredlogs
import exifread import exifread
import progressbar
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", fmt="%(levelname)s %(message)s", logger=log) coloredlogs.install(level="DEBUG", fmt="%(levelname)s %(message)s", logger=log)
@ -38,12 +37,7 @@ def main(args: argparse.Namespace) -> None:
log.warning("Counting files...") log.warning("Counting files...")
kwargs = {"directory": args.dir, "skip_renamed": args.skip_renamed} kwargs = {"directory": args.dir, "skip_renamed": args.skip_renamed}
log.warning("Processing files...") log.warning("Processing files...")
if args.hide_bar: for full_path in get_pictures(**kwargs):
iterator = get_pictures(**kwargs)
else:
nb_imgs = len(list(get_pictures(**kwargs)))
iterator = progressbar.progressbar(get_pictures(**kwargs), max_value=nb_imgs)
for full_path in iterator:
# Find date # Find date
with open(full_path, 'rb') as fd: with open(full_path, 'rb') as fd:
exif_data = exifread.process_file(fd) exif_data = exifread.process_file(fd)
@ -62,7 +56,7 @@ def main(args: argparse.Namespace) -> None:
ext = os.path.splitext(full_path)[1].lower() ext = os.path.splitext(full_path)[1].lower()
if ext == '.jpeg': if ext == '.jpeg':
ext = '.jpg' ext = '.jpg'
new_name = date.isoformat().replace(":", "-").replace("T", "_") new_name = date.isoformat().replace(":", "-").replace("T", "_") + args.suffix
# First substitution is to allow images being sent to a NTFS filesystem # First substitution is to allow images being sent to a NTFS filesystem
# Second substitution is for esthetics # Second substitution is for esthetics
new_path = os.path.join(args.dir, f"{new_name}{ext}") new_path = os.path.join(args.dir, f"{new_name}{ext}")
@ -71,7 +65,7 @@ def main(args: argparse.Namespace) -> None:
while os.path.exists(new_path): while os.path.exists(new_path):
if full_path == new_path: if full_path == new_path:
break break
log.debug(f"{full_path} already exists, incrementing") log.debug(f"{new_path} already exists, incrementing")
i += 1 i += 1
new_path = os.path.join(args.dir, f"{new_name}_{i}{ext}") new_path = os.path.join(args.dir, f"{new_name}_{i}{ext}")
@ -103,16 +97,16 @@ if __name__ == "__main__":
help="Do not actually rename, just show old and new path", help="Do not actually rename, just show old and new path",
) )
parser.add_argument( parser.add_argument(
"-s", "-r",
"--skip-renamed", "--skip-renamed",
action="store_true", action="store_true",
help="Skip images whose filename doesn't match usual camera output filenames.", help="Skip images whose filename doesn't match usual camera output filenames.",
) )
parser.add_argument( parser.add_argument(
"-b", "-s",
"--hide-bar", "--suffix",
action="store_true", default="",
help="Do not show a progress bar. Also skip counting images", help="Text to add before the extension",
) )
args = parser.parse_args() args = parser.parse_args()
main(args) main(args)