Fixed missing import in photoinfo.py
This commit is contained in:
parent
098159466e
commit
aee52e4cb9
@ -10,14 +10,17 @@ import os.path
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from datetime import timedelta, timezone
|
||||
from pprint import pformat
|
||||
|
||||
import yaml
|
||||
|
||||
from ._constants import _PHOTOS_5_VERSION
|
||||
from .utils import _get_resource_loc, dd_to_dms_str
|
||||
|
||||
# TODO: check pylint output
|
||||
|
||||
|
||||
class PhotoInfo:
|
||||
"""
|
||||
@ -37,8 +40,8 @@ class PhotoInfo:
|
||||
|
||||
@property
|
||||
def original_filename(self):
|
||||
""" original filename of the picture """
|
||||
""" Photos 5 mangles filenames upon import """
|
||||
""" original filename of the picture
|
||||
Photos 5 mangles filenames upon import """
|
||||
return self._info["originalFilename"]
|
||||
|
||||
@property
|
||||
@ -293,11 +296,14 @@ class PhotoInfo:
|
||||
# verify we have a valid path_edited and use that to get filename
|
||||
if not self.path_edited:
|
||||
raise FileNotFoundError(
|
||||
f"edited=True but path_edited is none; hasadjustments: {self.hasadjustments}"
|
||||
"edited=True but path_edited is none; hasadjustments: "
|
||||
f" {self.hasadjustments}"
|
||||
)
|
||||
edited_name = Path(self.path_edited).name
|
||||
edited_suffix = Path(edited_name).suffix
|
||||
filename = Path(self.filename).stem + "_edited" + edited_suffix
|
||||
edited_name = pathlib.Path(self.path_edited).name
|
||||
edited_suffix = pathlib.Path(edited_name).suffix
|
||||
filename = (
|
||||
pathlib.Path(self.filename).stem + "_edited" + edited_suffix
|
||||
)
|
||||
else:
|
||||
filename = self.filename
|
||||
|
||||
@ -459,7 +465,7 @@ class PhotoInfo:
|
||||
"original_filename": self.original_filename,
|
||||
"date": str(self.date),
|
||||
"description": self.description,
|
||||
"name": self.name,
|
||||
"title": self.title,
|
||||
"keywords": self.keywords,
|
||||
"albums": self.albums,
|
||||
"persons": self.persons,
|
||||
@ -504,8 +510,8 @@ class PhotoInfo:
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
return self.__dict__ == other.__dict__
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
@ -8,11 +8,9 @@ import os.path
|
||||
import pathlib
|
||||
import platform
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from pprint import pformat
|
||||
from shutil import copyfile
|
||||
|
||||
@ -24,15 +22,7 @@ from ._constants import (
|
||||
)
|
||||
from ._version import __version__
|
||||
from .photoinfo import PhotoInfo
|
||||
from .utils import (
|
||||
_check_file_exists,
|
||||
_get_os_version,
|
||||
_get_resource_loc,
|
||||
dd_to_dms_str,
|
||||
get_last_library_path,
|
||||
get_system_library_path,
|
||||
list_photo_libraries,
|
||||
)
|
||||
from .utils import _check_file_exists, _get_os_version, get_last_library_path
|
||||
|
||||
# TODO: find edited photos: see https://github.com/orangeturtle739/photos-export/blob/master/extract_photos.py
|
||||
# TODO: Add test for imageTimeZoneOffsetSeconds = None
|
||||
@ -45,6 +35,8 @@ from .utils import (
|
||||
|
||||
|
||||
class PhotosDB:
|
||||
""" Processes a Photos.app library database to extract information about photos """
|
||||
|
||||
def __init__(self, *args, dbfile=None):
|
||||
""" create a new PhotosDB object """
|
||||
""" path to photos library or database may be specified EITHER as first argument or as named argument dbfile=path """
|
||||
@ -134,7 +126,7 @@ class PhotosDB:
|
||||
self._db_version = self._get_db_version()
|
||||
if int(self._db_version) >= int(_PHOTOS_5_VERSION):
|
||||
logging.debug(f"version is {self._db_version}")
|
||||
dbpath = Path(self._dbfile).parent
|
||||
dbpath = pathlib.Path(self._dbfile).parent
|
||||
dbfile = dbpath / "Photos.sqlite"
|
||||
logging.debug(f"dbfile = {dbfile}")
|
||||
if not _check_file_exists(dbfile):
|
||||
@ -349,8 +341,8 @@ class PhotosDB:
|
||||
return version
|
||||
|
||||
def _process_database4(self):
|
||||
""" process the Photos database to extract info """
|
||||
""" works on Photos version <= 4.0 """
|
||||
""" process the Photos database to extract info
|
||||
works on Photos version <= 4.0 """
|
||||
|
||||
# TODO: Update strings to remove + (not needed)
|
||||
# Epoch is Jan 1, 2001
|
||||
@ -1014,6 +1006,7 @@ class PhotosDB:
|
||||
logging.debug("Photos:")
|
||||
logging.debug(pformat(self._dbphotos))
|
||||
|
||||
# TODO: fix default values to None instead of []
|
||||
def photos(self, keywords=[], uuid=[], persons=[], albums=[]):
|
||||
"""
|
||||
Return a list of PhotoInfo objects
|
||||
|
||||
@ -736,3 +736,19 @@ def test_export_13():
|
||||
with pytest.raises(Exception) as e:
|
||||
assert photos[0].export(dest)
|
||||
assert e.type == type(FileNotFoundError())
|
||||
|
||||
def test_eq():
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
photos1 = photosdb.photos(uuid=[UUID_DICT["export"]])
|
||||
photos2 = photosdb.photos(uuid=[UUID_DICT["export"]])
|
||||
assert photos1[0] == photos2[0]
|
||||
|
||||
def test_not_eq():
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
photos1 = photosdb.photos(uuid=[UUID_DICT["export"]])
|
||||
photos2 = photosdb.photos(uuid=[UUID_DICT["missing"]])
|
||||
assert photos1[0] != photos2[0]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user