From 8cb15d15551094dcaf1b0ef32d6ac0273be7fd37 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Wed, 18 Nov 2020 22:03:23 -0800 Subject: [PATCH] Removed debug statement in _photoinfo_export --- osxphotos/_version.py | 2 +- osxphotos/path_utils.py | 3 +- osxphotos/photoinfo/_photoinfo_export.py | 1 - osxphotos/utils.py | 38 ++++++++++++++++++++---- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 7cab838c..7804b00e 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,4 +1,4 @@ """ version info """ -__version__ = "0.36.18" +__version__ = "0.36.19" diff --git a/osxphotos/path_utils.py b/osxphotos/path_utils.py index e937a2a8..075f14e2 100644 --- a/osxphotos/path_utils.py +++ b/osxphotos/path_utils.py @@ -1,8 +1,9 @@ """ utility functions for validating/sanitizing path components """ -from ._constants import MAX_DIRNAME_LEN, MAX_FILENAME_LEN import pathvalidate +from ._constants import MAX_DIRNAME_LEN, MAX_FILENAME_LEN + def sanitize_filepath(filepath): """ sanitize a filepath """ diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index b20ebd20..daae76cf 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -1194,7 +1194,6 @@ def _exiftool_dict( timeoriginal = date.strftime(f"%H:%M:%S{offsettime}") exif["IPTC:TimeCreated"] = timeoriginal - print(f"time = {timeoriginal}") if self.date_modified is not None and not ignore_date_modified: exif["EXIF:ModifyDate"] = self.date_modified.strftime("%Y:%m:%d %H:%M:%S") diff --git a/osxphotos/utils.py b/osxphotos/utils.py index d4b25779..1cb097da 100644 --- a/osxphotos/utils.py +++ b/osxphotos/utils.py @@ -57,10 +57,12 @@ def _debug(): """ returns True if debugging turned on (via _set_debug), otherwise, false """ return _DEBUG + def noop(*args, **kwargs): """ do nothing (no operation) """ pass + def _get_os_version(): # returns tuple containing OS version # e.g. 10.13.6 = (10, 13, 6) @@ -361,9 +363,35 @@ def _db_is_locked(dbname): def normalize_unicode(value): """ normalize unicode data """ - if value is not None: - if not isinstance(value, str): - raise ValueError("value must be str") - return unicodedata.normalize(UNICODE_FORMAT, value) - else: + if value is None: return None + + if not isinstance(value, str): + raise ValueError("value must be str") + return unicodedata.normalize(UNICODE_FORMAT, value) + + +def increment_filename(filepath): + """ Return filename (1).ext, etc if filename.ext exists + + If file exists in filename's parent folder with same stem as filename, + add (1), (2), etc. until a non-existing filename is found. + + Args: + filepath: str; full path, including file name + + Returns: + new filepath (or same if not incremented) + + Note: This obviously is subject to race condition so using with caution. + """ + dest = pathlib.Path(str(filepath)) + count = 1 + dest_files = findfiles(f"{dest.stem}*", str(dest.parent)) + dest_files = [pathlib.Path(f).stem.lower() for f in dest_files] + dest_new = dest.stem + while dest_new.lower() in dest_files: + dest_new = f"{dest.stem} ({count})" + count += 1 + dest = dest.parent / f"{dest_new}{dest.suffix}" + return str(dest)