-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add event_bus to gphotos_backup, and docstrings, and types (#30)
* feat: add event_bus to gphotos_uploader, and types * wip * wip * wip * wip * wip
- Loading branch information
Showing
15 changed files
with
563 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
A module used to store events emitted from the GPhotosBackup class. | ||
""" | ||
|
||
STARTED_UPLOADING = "backup:started_uploading" | ||
UPLOADED_PHOTO = "backup:uploaded_photo" | ||
FINISHED_UPLOADING = "backup:finished_uploading" | ||
|
||
STARTED_DELETING = "backup:started_deleting" | ||
DELETED_PHOTO = "backup:deleted_photo" | ||
FINISHED_DELETING = "backup:started_deleting" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
from event_bus import EventBus | ||
|
||
from sharded_google_photos.shared.gphotos_client import GPhotosClient | ||
|
||
from . import gphotos_uploader_events as events | ||
|
||
|
||
class GPhotosUploader: | ||
def __init__(self, gphoto_client: GPhotosClient): | ||
def __init__(self, gphoto_client: GPhotosClient, event_bus: EventBus = None): | ||
self.gphoto_client = gphoto_client | ||
self.event_bus = event_bus if event_bus is not None else EventBus() | ||
|
||
def upload_photos(self, file_paths: list[str], file_names: list[str]) -> list[str]: | ||
""" | ||
Uploads a list of photos | ||
Args: | ||
file_paths (list[str]): A list of the photos' file paths to upload | ||
file_names (list[str]): A list of the corresponding photos' file names | ||
def upload_photos(self, file_paths: list[str], file_names: list[str]): | ||
Returns: | ||
list[str]: A list of upload tokens to add to a Google Photos album | ||
""" | ||
upload_tokens = [] | ||
self.event_bus.emit(events.STARTED_UPLOADING, file_paths) | ||
|
||
for file_path, file_name in zip(file_paths, file_names): | ||
upload_token = self.gphoto_client.media_items().upload_photo_in_chunks( | ||
file_path, file_name | ||
) | ||
self.event_bus.emit(events.UPLOADED_PHOTO, file_path) | ||
upload_tokens.append(upload_token) | ||
|
||
self.event_bus.emit(events.FINISHED_UPLOADING) | ||
return upload_tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
A module used to store events emitted from the GPhotosUploader class. | ||
""" | ||
|
||
STARTED_UPLOADING = "uploader:started_uploading" | ||
UPLOADED_PHOTO = "uploader:uploaded_photo" | ||
FINISHED_UPLOADING = "uploader:finished_uploading" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.