Added tests and README for AlbumInfo and FolderInfo
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.26.1"
|
||||
__version__ = "0.27.0"
|
||||
|
||||
@@ -10,7 +10,9 @@ Represents a single Folder in the Photos library and provides access to the fold
|
||||
PhotosDB.folders() returns a list of FolderInfo objects
|
||||
"""
|
||||
|
||||
from ._constants import _PHOTOS_5_ALBUM_KIND, _PHOTOS_5_FOLDER_KIND
|
||||
import logging
|
||||
|
||||
from ._constants import _PHOTOS_5_ALBUM_KIND, _PHOTOS_5_FOLDER_KIND, _PHOTOS_5_VERSION
|
||||
|
||||
|
||||
class AlbumInfo:
|
||||
@@ -50,6 +52,11 @@ class AlbumInfo:
|
||||
the folder list is in form:
|
||||
["Top level folder", "sub folder 1", "sub folder 2", ...]
|
||||
returns empty list if album is not in any folders """
|
||||
|
||||
if self._db._db_version < _PHOTOS_5_VERSION:
|
||||
logging.warning("Folders not yet implemented for this DB version")
|
||||
return []
|
||||
|
||||
try:
|
||||
return self._folder_names
|
||||
except AttributeError:
|
||||
@@ -57,11 +64,16 @@ class AlbumInfo:
|
||||
return self._folder_names
|
||||
|
||||
@property
|
||||
def folders(self):
|
||||
def folder_list(self):
|
||||
""" return hierarchical list of folders the album is contained in
|
||||
as list of FolderInfo objects in form
|
||||
["Top level folder", "sub folder 1", "sub folder 2", ...]
|
||||
returns empty list if album is not in any folders """
|
||||
|
||||
if self._db._db_version < _PHOTOS_5_VERSION:
|
||||
logging.warning("Folders not yet implemented for this DB version")
|
||||
return []
|
||||
|
||||
try:
|
||||
return self._folders
|
||||
except AttributeError:
|
||||
@@ -71,6 +83,10 @@ class AlbumInfo:
|
||||
@property
|
||||
def parent(self):
|
||||
""" returns FolderInfo object for parent folder or None if no parent (e.g. top-level album) """
|
||||
if self._db._db_version < _PHOTOS_5_VERSION:
|
||||
logging.warning("Folders not yet implemented for this DB version")
|
||||
return None
|
||||
|
||||
try:
|
||||
return self._parent
|
||||
except AttributeError:
|
||||
|
||||
@@ -343,7 +343,8 @@ class PhotosDB:
|
||||
def folders(self):
|
||||
""" return list of top-level folders in the photos database """
|
||||
if self._db_version < _PHOTOS_5_VERSION:
|
||||
raise AttributeError("Not yet implemented for this DB version")
|
||||
logging.warning("Folders not yet implemented for this DB version")
|
||||
return []
|
||||
|
||||
folders = [
|
||||
FolderInfo(db=self, uuid=album)
|
||||
@@ -354,6 +355,23 @@ class PhotosDB:
|
||||
]
|
||||
return folders
|
||||
|
||||
@property
|
||||
def folder_names(self):
|
||||
""" return list of top-level folder names in the photos database """
|
||||
if self._db_version < _PHOTOS_5_VERSION:
|
||||
logging.warning("Folders not yet implemented for this DB version")
|
||||
return []
|
||||
|
||||
folder_names = [
|
||||
detail["title"]
|
||||
for detail in self._dbalbum_details.values()
|
||||
if detail["intrash"] == 0
|
||||
and detail["kind"] == _PHOTOS_5_FOLDER_KIND
|
||||
and detail["parentfolder"] == self._folder_root_pk
|
||||
]
|
||||
return folder_names
|
||||
|
||||
|
||||
@property
|
||||
def albums(self):
|
||||
""" return list of AlbumInfo objects for each album in the photos database """
|
||||
@@ -362,6 +380,7 @@ class PhotosDB:
|
||||
AlbumInfo(db=self, uuid=album)
|
||||
for album in self._dbalbums_album.keys()
|
||||
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is None
|
||||
and self._dbalbum_details[album]["intrash"] == 0
|
||||
]
|
||||
return albums
|
||||
|
||||
@@ -381,6 +400,7 @@ class PhotosDB:
|
||||
AlbumInfo(db=self, uuid=album)
|
||||
for album in self._dbalbums_album.keys()
|
||||
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is not None
|
||||
and self._dbalbum_details[album]["intrash"] == 0
|
||||
]
|
||||
return albums_shared
|
||||
|
||||
@@ -395,6 +415,7 @@ class PhotosDB:
|
||||
self._dbalbum_details[album]["title"]
|
||||
for album in self._dbalbums_album.keys()
|
||||
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is None
|
||||
and self._dbalbum_details[album]["intrash"] == 0
|
||||
}
|
||||
return list(albums)
|
||||
|
||||
@@ -418,6 +439,7 @@ class PhotosDB:
|
||||
self._dbalbum_details[album]["title"]
|
||||
for album in self._dbalbums_album.keys()
|
||||
if self._dbalbum_details[album]["cloudownerhashedpersonid"] is not None
|
||||
and self._dbalbum_details[album]["intrash"] == 0
|
||||
}
|
||||
return list(albums)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user