Fixed missing import in photoinfo.py

This commit is contained in:
Rhet Turnbull
2019-12-25 00:29:14 -08:00
parent 098159466e
commit aee52e4cb9
3 changed files with 41 additions and 26 deletions

View File

@@ -10,14 +10,17 @@ import os.path
import pathlib import pathlib
import re import re
import subprocess import subprocess
from datetime import datetime, timedelta, timezone import sys
from pathlib import Path from datetime import timedelta, timezone
from pprint import pformat
import yaml import yaml
from ._constants import _PHOTOS_5_VERSION from ._constants import _PHOTOS_5_VERSION
from .utils import _get_resource_loc, dd_to_dms_str from .utils import _get_resource_loc, dd_to_dms_str
# TODO: check pylint output
class PhotoInfo: class PhotoInfo:
""" """
@@ -37,8 +40,8 @@ class PhotoInfo:
@property @property
def original_filename(self): def original_filename(self):
""" original filename of the picture """ """ original filename of the picture
""" Photos 5 mangles filenames upon import """ Photos 5 mangles filenames upon import """
return self._info["originalFilename"] return self._info["originalFilename"]
@property @property
@@ -293,11 +296,14 @@ class PhotoInfo:
# verify we have a valid path_edited and use that to get filename # verify we have a valid path_edited and use that to get filename
if not self.path_edited: if not self.path_edited:
raise FileNotFoundError( 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 = pathlib.Path(self.path_edited).name
edited_suffix = pathlib.Path(edited_name).suffix
filename = (
pathlib.Path(self.filename).stem + "_edited" + edited_suffix
) )
edited_name = Path(self.path_edited).name
edited_suffix = Path(edited_name).suffix
filename = Path(self.filename).stem + "_edited" + edited_suffix
else: else:
filename = self.filename filename = self.filename
@@ -459,7 +465,7 @@ class PhotoInfo:
"original_filename": self.original_filename, "original_filename": self.original_filename,
"date": str(self.date), "date": str(self.date),
"description": self.description, "description": self.description,
"name": self.name, "title": self.title,
"keywords": self.keywords, "keywords": self.keywords,
"albums": self.albums, "albums": self.albums,
"persons": self.persons, "persons": self.persons,
@@ -504,7 +510,7 @@ class PhotoInfo:
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, self.__class__): if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__ return self.__dict__ == other.__dict__
else:
return False return False
def __ne__(self, other): def __ne__(self, other):

View File

@@ -8,11 +8,9 @@ import os.path
import pathlib import pathlib
import platform import platform
import sqlite3 import sqlite3
import subprocess
import sys import sys
import tempfile import tempfile
from datetime import datetime, timedelta, timezone from datetime import datetime
from pathlib import Path
from pprint import pformat from pprint import pformat
from shutil import copyfile from shutil import copyfile
@@ -24,15 +22,7 @@ from ._constants import (
) )
from ._version import __version__ from ._version import __version__
from .photoinfo import PhotoInfo from .photoinfo import PhotoInfo
from .utils import ( from .utils import _check_file_exists, _get_os_version, get_last_library_path
_check_file_exists,
_get_os_version,
_get_resource_loc,
dd_to_dms_str,
get_last_library_path,
get_system_library_path,
list_photo_libraries,
)
# TODO: find edited photos: see https://github.com/orangeturtle739/photos-export/blob/master/extract_photos.py # TODO: find edited photos: see https://github.com/orangeturtle739/photos-export/blob/master/extract_photos.py
# TODO: Add test for imageTimeZoneOffsetSeconds = None # TODO: Add test for imageTimeZoneOffsetSeconds = None
@@ -45,6 +35,8 @@ from .utils import (
class PhotosDB: class PhotosDB:
""" Processes a Photos.app library database to extract information about photos """
def __init__(self, *args, dbfile=None): def __init__(self, *args, dbfile=None):
""" create a new PhotosDB object """ """ create a new PhotosDB object """
""" path to photos library or database may be specified EITHER as first argument or as named argument dbfile=path """ """ 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() self._db_version = self._get_db_version()
if int(self._db_version) >= int(_PHOTOS_5_VERSION): if int(self._db_version) >= int(_PHOTOS_5_VERSION):
logging.debug(f"version is {self._db_version}") logging.debug(f"version is {self._db_version}")
dbpath = Path(self._dbfile).parent dbpath = pathlib.Path(self._dbfile).parent
dbfile = dbpath / "Photos.sqlite" dbfile = dbpath / "Photos.sqlite"
logging.debug(f"dbfile = {dbfile}") logging.debug(f"dbfile = {dbfile}")
if not _check_file_exists(dbfile): if not _check_file_exists(dbfile):
@@ -349,8 +341,8 @@ class PhotosDB:
return version return version
def _process_database4(self): def _process_database4(self):
""" process the Photos database to extract info """ """ process the Photos database to extract info
""" works on Photos version <= 4.0 """ works on Photos version <= 4.0 """
# TODO: Update strings to remove + (not needed) # TODO: Update strings to remove + (not needed)
# Epoch is Jan 1, 2001 # Epoch is Jan 1, 2001
@@ -1014,6 +1006,7 @@ class PhotosDB:
logging.debug("Photos:") logging.debug("Photos:")
logging.debug(pformat(self._dbphotos)) logging.debug(pformat(self._dbphotos))
# TODO: fix default values to None instead of []
def photos(self, keywords=[], uuid=[], persons=[], albums=[]): def photos(self, keywords=[], uuid=[], persons=[], albums=[]):
""" """
Return a list of PhotoInfo objects Return a list of PhotoInfo objects

View File

@@ -736,3 +736,19 @@ def test_export_13():
with pytest.raises(Exception) as e: with pytest.raises(Exception) as e:
assert photos[0].export(dest) assert photos[0].export(dest)
assert e.type == type(FileNotFoundError()) 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]