Skip to content

Commit

Permalink
Removed file locking, performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Apr 3, 2023
1 parent 93d22c6 commit 3ba7fc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
16 changes: 8 additions & 8 deletions osxphotos/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,21 +1427,21 @@ def cleanup_lock_files():
photo_num = 0
num_exported = 0
limit_str = f" (limit = [num]{limit}[/num])" if limit else ""
# hack to avoid passing all the options to export_photo
kwargs = {
k: v
for k, v in locals().items()
if k in inspect.getfullargspec(export_photo).args
}
kwargs["export_dir"] = dest
kwargs["export_preview"] = preview
with rich_progress(console=get_verbose_console(), mock=no_progress) as progress:
task = progress.add_task(
f"Exporting [num]{num_photos}[/] photos{limit_str}", total=num_photos
)
for p in photos:
photo_num += 1
# hack to avoid passing all the options to export_photo
kwargs = {
k: v
for k, v in locals().items()
if k in inspect.getfullargspec(export_photo).args
}
kwargs["photo"] = p
kwargs["export_dir"] = dest
kwargs["export_preview"] = preview
export_results = export_photo(**kwargs)
if post_function:
for function in post_function:
Expand Down
8 changes: 7 additions & 1 deletion osxphotos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ def lock_filename(filepath: Union[str, pathlib.Path]) -> bool:
Returns:
filepath if lock file created, False if lock file already exists
"""
return filepath

# TODO: for future implementation
lockfile = pathlib.Path(f"{filepath}.osxphotos.lock")
if lockfile.exists():
return False
Expand All @@ -447,6 +449,9 @@ def unlock_filename(filepath: Union[str, pathlib.Path]):
filepath: str or pathlib.Path; full path, including file name
"""

return

# TODO: for future implementation
lockfile = pathlib.Path(f"{filepath}.osxphotos.lock")
if lockfile.exists():
lockfile.unlink()
Expand Down Expand Up @@ -539,6 +544,7 @@ def shortuuid_to_uuid(short_uuid: str) -> str:
"""Convert shortuuid to uuid"""
return str(shortuuid.decode(short_uuid)).upper()


def under_test() -> bool:
"""Return True if running under pytest"""
return "pytest" in sys.modules
return "pytest" in sys.modules
3 changes: 1 addition & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_dd_to_dms():

@pytest.mark.skip(reason="Fails on some machines")
def test_get_system_library_path():

_, major, _ = osxphotos.utils._get_os_version()
if int(major) < 15:
assert osxphotos.utils.get_system_library_path() is None
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_list_directory():


def test_list_directory_invalid():

temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
files = list_directory(f"{temp_dir.name}/no_such_dir", glob="*.jpg")
assert len(files) == 0
Expand Down Expand Up @@ -151,6 +149,7 @@ def test_increment_filename_with_lock():
)


@pytest.mark.skip(reason="Lock files not yet implemented")
def test_increment_filename_with_lock_exists():
# test that increment_filename works with lock=True when lock file already exists

Expand Down

0 comments on commit 3ba7fc8

Please sign in to comment.