taskbridgeapp.reminders.model.remindercontainer.ReminderContainer

class taskbridgeapp.reminders.model.remindercontainer.ReminderContainer(local_list, remote_calendar, sync)

Bases: object

Represents a folder or calendar containing reminders. A link is established here between the local list and the remote calendar. Also contains a list of the reminders in this container, both local and remote.

Methods

assoc_list_local_remote

Associate local reminder lists with remote lists.

assoc_list_remote_local

Associate remote reminder lists with local lists.

count_local_completed

Counts the number of completed reminders.

create_linked_containers

Creates an association between local reminder lists and remote task calendars.

delete_local_completed

Deletes completed reminders.

get_saved_reminders

Get the list of saved reminders from the database.

load_caldav_calendars

Loads the list of CalDav calendars which support VTODO components (i.e. task calendars).

load_local_lists

Load the list of local reminder lists.

load_local_reminders

Load the list of local reminders in this local container (list) via an AppleScript script.

load_remote_reminders

Load the list of remote reminders (tasks) in this remote container (calendar) via CalDav.

persist_containers

Save the list of containers to SQLite.

persist_reminders

Save the list of reminders to SQLite.

seed_container_table

Creates the initial structure for the table storing containers in SQLite.

seed_reminder_table

Creates the initial structure for the table storing reminders in SQLite.

sync_container_deletions

Synchronises deletions to reminder containers.

sync_local_reminders_to_remote

Sync local reminders to remote tasks.

sync_reminder_deletions

Synchronises deletions to reminders.

sync_reminders

Synchronises reminders.

sync_remote_reminders_to_local

Sync remote tasks to local reminders.

Attributes

CONTAINER_LIST

List of all found reminder containers

CONTAINER_LIST: List[ReminderContainer] = []

List of all found reminder containers

__empty_reminder_table(fail)

Empties the reminder table

Parameters:

fail (str) – the part of the process to intentionally fail (used for test coverage).

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if reminder table is successfully emptied.

-data (str) - error message on failure or success message.

__get_current_reminders(container, fail)

Get the current local and remote reminders for this container

Parameters:
  • container (ReminderContainer) – the container to fetch reminders for.

  • fail (str) – the part of the process to intentionally fail (used for test coverage).

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if both local and remote reminders are loaded successfully.

-data (str) - error message on failure or success message.

__init__(local_list, remote_calendar, sync)

Create a new reminder container.

Parameters:
  • local_list (LocalList | None) – the local list containing the local reminders.

  • remote_calendar (RemoteCalendar | None) – the remote calendar containing the remote tasks.

  • sync (bool) – True if the local list and remote calendar should be synchronised.

static _delete_local_containers(removed_remote_containers, removed_local_containers, discovered_local, to_sync, result, fail=False)

Deletes remote reminder containers which have been deleted locally.

Parameters:
  • removed_remote_containers (List[Row]) – list of containers which have been deleted remotely.

  • removed_local_containers (List[Row]) – list of containers which have been deleted locally.

  • discovered_local (List[LocalList]) – the list of local reminder lists.

  • to_sync (List[str]) – the list of lists/calendars which should be synchronised.

  • result (dict) – dictionary where changes are appended

  • fail (bool) – method will fail if this is True (used for test coverage)

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if container deletions are successfully carried out.

-data (str) - error message on failure or success message.

static _delete_local_reminders(container_saved_remote, container, result, fail=False)

Delete local reminders which have been deleted remotely.

Parameters:
  • container_saved_remote (List[Row]) – list of reminders from last sync.

  • container (ReminderContainer) – the reminder container.

  • result (dict) – dictionary where changes are appended.

  • fail (bool) – deletion will fail if this is true (used for test coverage).

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if reminder deletions are successfully synchronised.

-data (str) - error message on failure or success message.

static _delete_remote_containers(removed_local_containers, discovered_remote, to_sync, result, fail=False)

Deletes remote reminder containers which have been deleted locally.

Parameters:
  • removed_local_containers (List[Row]) – list of containers which have been deleted locally.

  • discovered_remote (List[RemoteCalendar]) – the list of remote task calendars.

  • to_sync (List[str]) – the list of lists/calendars which should be synchronised.

  • result (dict) – dictionary where changes are appended

  • fail (bool) – method will fail if this is True (used for test coverage)

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if container deletions are successfully carried out.

-data (str) - error message on failure or success message.

static _delete_remote_reminders(container_saved_local, container, result)

Delete remote reminders which have been deleted locally.

Parameters:
  • container_saved_local (List[Row]) – list of reminders from last sync.

  • container (ReminderContainer) – the reminder container

  • result (dict) – dictionary where changes are appended

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if reminder deletions are successfully synchronised.

-data (str) - error message on failure or success message.

static assoc_list_local_remote(local_lists, remote_calendars, to_sync)

Associate local reminder lists with remote lists.

Parameters:
  • local_lists (List[LocalList]) – discovered local lists

  • remote_calendars (List[RemoteCalendar]) – discovered remote calendars

  • to_sync (List[str]) – list of containers to keep in sync

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the containers are successfully linked.

-data (str) - error message on failure, or success message.

static assoc_list_remote_local(local_lists, remote_calendars, to_sync, fail=False)

Associate remote reminder lists with local lists.

Parameters:
  • local_lists (List[LocalList]) – discovered local lists

  • remote_calendars (List[RemoteCalendar]) – discovered remote calendars

  • to_sync (List[str]) – list of containers to keep in sync

  • fail (bool) – set this to True to fail this task (used for test coverage)

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the containers are successfully linked.

-data (str) - error message on failure, or success message.

static count_local_completed(fail=False)

Counts the number of completed reminders.

Parameters:

fail (bool) – if set to True, this method fails on purpose (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, int]

Returns:

-success (bool) - true if the number of completed reminders is successfully retrieved

-data (str | :py:class`int`) - error message or number of completed reminders.

static create_linked_containers(local_lists, remote_calendars, to_sync)

Creates an association between local reminder lists and remote task calendars. Missing containers are created; for example, if the list foo is present locally, and sync is set to True, this method will check if the remote calendar foo exists and, if not, creates it.

The list of containers is saved to an SQLite database.

Important: The local list ‘Reminders’ is ALWAYS associated with the remote calendar ‘Tasks’.

Parameters:
  • local_lists (List[LocalList]) – list of local reminder lists.

  • remote_calendars (List[RemoteCalendar]) – list of remote task calendars.

  • to_sync (List[str]) – list of reminder/task lists/calendars to synchronise. Sync is always bidirectional.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the containers are successfully linked.

-data (str) - error message on fail, or success message.

static delete_local_completed()

Deletes completed reminders. This is important, as too many reminders can cause synchronisation to be very slow.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if completed reminders are successfully deleted

-data (str) - error message or fail, or success message.

static get_saved_reminders()

Get the list of saved reminders from the database.

Return type:

tuple[bool, str] | tuple[bool, List[Row]]

Returns:

-success (bool) - true if database reminders are successfully loaded

-data (str | dict) - error message on failure or list of saved reminders.

static load_caldav_calendars()

Loads the list of CalDav calendars which support VTODO components (i.e. task calendars).

Return type:

tuple[bool, str] | tuple[bool, List[RemoteCalendar]]

Returns:

-success (bool) - true if the list of remote calendars is successfully loaded.

-data (str | :py:class`List[RemoteCalendar]`) - error message on failure or list of remote calendars.

static load_local_lists(fail=False)

Load the list of local reminder lists.

Parameters:

fail (bool) – if set to True, this method fails on purpose (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, List[LocalList]]

Returns:

-success (bool) - true if the list of local reminder lists is successfully loaded.

-data (str | :py:class`List[LocalList]`) - error message on failure or list of local reminder lists.

load_local_reminders(fail=None)

Load the list of local reminders in this local container (list) via an AppleScript script. The reminders are saved in a pipe-separated .psv file in a temporary folder, and then parsed from there.

Parameters:

fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, int]

Returns:

-success (bool) - true if the reminders are successfully loaded.

-data (str | int) - error message on failure or number of loaded reminders on success.

load_remote_reminders()

Load the list of remote reminders (tasks) in this remote container (calendar) via CalDav.

Return type:

tuple[bool, str] | tuple[bool, int]

Returns:

-success (bool) - true if the reminders are successfully loaded.

-data (str | int) - error message on failure or number of loaded reminders on success.

static persist_containers()

Save the list of containers to SQLite.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the containers are successfully saved.

-data (str) - error message on failure or success message.

static persist_reminders()

Save the list of reminders to SQLite. Due to the fact that local reminder UUIDs are read-only, this list may contain reminders without an associated remote UID. For this reason, the reminder’s summary (which is typically the only text content) has to be saved to the database. Without this, many reminders couldn’t be matched. The database is stored locally.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the reminders as successfully saved.

-data (str) - error message on failure or success message.

static seed_container_table()

Creates the initial structure for the table storing containers in SQLite.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the table is successfully seeded.

-data (str) - error message on failure or success message.

static seed_reminder_table()

Creates the initial structure for the table storing reminders in SQLite.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the table is successfully seeded.

-data (str) - error message on failure or success message.

static sync_container_deletions(discovered_local, discovered_remote, to_sync, fail=None)

Synchronises deletions to reminder containers.

The list of containers found during the last sync is loaded from SQLite and compared to the local and remote lists found now. Any lists in the database which are no longer present will have their counterpart deleted. For example, if the local list foo is deleted, the remote calendar foo will be deleted during sync.

Note that container deletions only apply if the list/calendar is found in the to_sync argument.

On success, this method returns a dictionary with changes, containing the following keys:

  • updated_local_list - the list of local reminder lists, taking into account deleted lists.

  • updated_remote_list - the list of remote task calendars, taking into account deleted calendars.

Parameters:
  • discovered_local (List[LocalList]) – the list of local reminder lists.

  • discovered_remote (List[RemoteCalendar]) – the list of remote task calendars.

  • to_sync (List[str]) – the list of lists/calendars which should be synchronised.

  • fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, dict]

Returns:

-success (bool) - true if container deletions are successfully synchronised.

-data (str | dict) - error message on failure or result as above on success.

sync_local_reminders_to_remote(result, fail=None)

Sync local reminders to remote tasks.

Parameters:
  • result (dict) – dictionary where actions are appended

  • fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the reminders are successfully synchronised.

-data (str) - error message on failure or success message.

static sync_reminder_deletions(fail=None)

Synchronises deletions to reminders.

The list of reminders found during the last sync is loaded from SQLite and compared to the local and remote reminders found now. Any reminders in the database which are no longer present will have their counterpart deleted. For example, if the local reminder foo is deleted, the remote reminder foo will be deleted during sync.

Note that reminder deletion only applies to those containers with sync set to True.

On success, this method returns a dictionary with changes, containing the following keys:

  • deleted_local_reminders - a list of local reminders deleted as List[Reminder].

  • deleted_remote_reminders - a list of remote tasks deleted as List[Reminder].

A reminder not being found is not considered an error, as the user may have deleted the reminder manually prior to the sync running.

Parameters:

fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, dict]

Returns:

-success (bool) - true if reminder deletions are successfully synchronised.

-data (str | dict) - error message on failure or result as above on success.

sync_reminders(fail=None)

Synchronises reminders. This method only synchronises reminders for containers with sync set to True. On success, the method returns a dictionary with the following keys:

  • remote_added - name of reminders added to the remote calendar as List[str].

  • remote_updated - name of reminders updated in the remote calendar as List[str].

  • local_added - name of reminders added to the local list as List[str].

  • local_updated - name of reminders updated in the local list as List[str].

Any of the above may be empty if no changes were made.

Parameters:

fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str] | tuple[bool, dict]

Returns:

-success (bool) - true if the reminders are successfully synchronised.

-data (str | dict) - error message on failure or dict with results as above.

sync_remote_reminders_to_local(result, fail=None)

Sync remote tasks to local reminders.

Parameters:
  • result (dict) – dictionary where actions are appended

  • fail (str) – the part of the process to intentionally fail (used for test coverage)

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the reminders are successfully synchronised.

-data (str) - error message on failure or success message.