taskbridgeapp.notes.model.notefolder.NoteFolder
- class taskbridgeapp.notes.model.notefolder.NoteFolder(local_folder=None, remote_folder=None, sync_direction=0)
Bases:
objectRepresents a folder containing notes. A link is established here between the local folder and the remote one. Also contains a list of notes in this folder.
Methods
Associate local folders with remote folders.
Associate remote folders with local folders.
Creates an association between local and remote folders.
Delete notes from local which were deleted remotely.
Delete notes from remote which were deleted locally.
Loads the list of local folders by calling an AppleScript script.
Calls an AppleScript script to fetch the notes in the local folder.
Loads the list of remote folders by checking the filesystem.
Loads the Markdown notes from the remote notes folder.
Save the list of linked note folders to SQLite.
Stores a list of notes in SQLite.
Reset the folder list to empty.
Creates the initial structure for the table storing folders in SQLite.
Creates the initial structure for the table storing notes in SQLite.
Sync folders that have been marked for bidirectional or local -> remote sync.
Synchronises deletions to folders.
Sync local notes to remote.
Sync all the local notes in this folder to remote.
Synchronises deletions to notes.
Synchronises notes.
Sync folders that have been marked for local <- remote sync.
Sync remote notes to local.
Sync all remote notes in this folder to local.
Attributes
List of all found note folders
Synchronise changes from both folders.
Update the remote folder with the changes in the local one (One-way).
Do not sync this folder
Update the local folder with the changes in the remote one (One-way).
-
FOLDER_LIST:
List[NoteFolder] = [] List of all found note folders
-
SYNC_BOTH:
int= 3 Synchronise changes from both folders.
-
SYNC_LOCAL_TO_REMOTE:
int= 1 Update the remote folder with the changes in the local one (One-way).
-
SYNC_NONE:
int= 0 Do not sync this folder
-
SYNC_REMOTE_TO_LOCAL:
int= 2 Update the local folder with the changes in the remote one (One-way).
- __init__(local_folder=None, remote_folder=None, sync_direction=0)
Create a new note folder.
- Parameters:
local_folder (
LocalNoteFolder|None) – the local folder containing the local notes.remote_folder (
RemoteNoteFolder|None) – the remote folder containing the remote notes.sync_direction (
int) – how to sync the folders.
sync_direction:NoteFolder.NO_SYNC- these folders will not be synchronised.NoteFolder.SYNC_LOCAL_TO_REMOTE- local notes will be pushed to remote.NoteFolder.SYNC_REMOTE_TO_LOCAL- remote notes will be pulled to local.NoteFolder.SYNC_BOTH- bidirectional sync based on the note’s modification date/time.
- static assoc_local_remote(local_folders, remote_folders, remote_notes_path, associations)
Associate local folders with remote folders.
- Parameters:
local_folders (
List[LocalNoteFolder]) – the list of local note folders.remote_folders (
List[RemoteNoteFolder]) – the list of remote note folders.remote_notes_path (
Path) – path to the remote folders, i.e. where on the local filesystem the remote notes are stored.associations (
dict) – list of folder associations.
- Return type:
None
- static assoc_remote_local(local_folders, remote_folders, associations)
Associate remote folders with local folders.
- Parameters:
local_folders (
List[LocalNoteFolder]) – the list of local note folders.remote_folders (
List[RemoteNoteFolder]) – the list of remote note folders.associations (
dict) – list of folder associations.
- Return type:
None
- static create_linked_folders(local_folders, remote_folders, remote_notes_path, associations)
Creates an association between local and remote folders. Missing folders are created; for example, if the folder foo is present locally, and set to
SYNC_LOCAL_TO_REMOTEorSYNC_BOTHthis method will check whether the remote folder foo exists and, if not, creates it.The list of folders is saved to an SQLite database.
- Parameters:
local_folders (
List[LocalNoteFolder]) – the list of local note folders.remote_folders (
List[RemoteNoteFolder]) – the list of remote note folders.remote_notes_path (
Path) – path to the remote folders, i.e. where on the local filesystem the remote notes are stored.associations (
dict) – list of folder associations.
The associations dictionary must contain the following keys:
local_to_remote- notes to push from local to remote as :py:class`List[str]`.remote_to_local- notes to pull from remote to local as :py:class`List[str]`.bi_directional- notes to synchronise in both folders as :py:class`List[str]`.
Any other folders found which are not listed above are not synchronised.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if the folders are successfully linked.-data (
str) - error message on failure, or success message.
- static delete_local_notes(folder, result)
Delete notes from local which were deleted remotely.
- Parameters:
folder (
NoteFolder) – the folder data.result (
dict) – dictionary where results are appended.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if local notes are successfully deleted.-data (
str) - error message on failure, or success message.
- static delete_remote_notes(folder, remote_folder, result)
Delete notes from remote which were deleted locally.
- Parameters:
folder (
NoteFolder) – the folder data.remote_folder (
Path) – the remote folder.result (
dict) – dictionary where results are appended.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if remote notes are successfully deleted.-data (
str) - error message on failure, or success message.
- static load_local_folders()
Loads the list of local folders by calling an AppleScript script.
- Return type:
tuple[bool,str] |tuple[bool,List[LocalNoteFolder]]- Returns:
-success (
bool) - true if folders are successfully loaded.-data (
str|List[LocalNoteFolder]) - error message on failure, list of folders on success.
- load_local_notes()
Calls an AppleScript script to fetch the notes in the local folder. The script saves each note with a
.stagedfile name in a temporary folder. Each file is then read, parsed and added as aNoteinstance in the inlocal_notes.- Return type:
tuple[bool,str] |tuple[bool,int]- Returns:
-success (
bool) - true if notes are successfully loaded.-data (
str|int) - error message on failure, or number of notes loaded on success.
- static load_remote_folders(remote_notes_path)
Loads the list of remote folders by checking the filesystem.
- Return type:
tuple[bool,List[RemoteNoteFolder]]- Returns:
-success (
bool) - true if folders are successfully loaded.-data (
str|List[RemoteNoteFolder]) - error message on failure, list of folders on success.
- load_remote_notes()
Loads the Markdown notes from the remote notes folder. Each note is then parsed and added as a
Noteinstance inremote_notes.- Return type:
tuple[bool,str] |tuple[bool,int]- Returns:
-success (
bool) - true if notes are successfully loaded.-data (
str|int) - error message on failure, or number of notes loaded on success.
- static persist_folders()
Save the list of linked note folders to SQLite.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if folders are successfully saved.-data (
str) - error message on failure, or success message.
- static persist_notes()
Stores a list of notes in SQLite. Note that the only ‘sensitive’ part of the note which is stored is the note’s name. The database is stored locally.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if table notes are successfully saved to the database.-data (
str) - error message on failure, or success message.
- static reset_list()
Reset the folder list to empty.
- static seed_folder_table()
Creates the initial structure for the table storing folders in SQLite.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if table is successfully seeded.-data (
str) - error message on failure, or success message.
- static seed_note_table()
Creates the initial structure for the table storing notes in SQLite.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if table is successfully created.-data (
str) - error message on failure, or success message.
- static sync_bidirectional_local_deletions(discovered_local)
Sync folders that have been marked for bidirectional or local -> remote sync.
- Parameters:
discovered_local (
List[LocalNoteFolder]) – list of currently discovered local note folders.- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if folder deletions are successfully synchronised.-data (
str) - error message on failure, or success message.
- static sync_folder_deletions(discovered_local, discovered_remote)
Synchronises deletions to folders.
The list of folders found during the last sync is loaded from SQLite and compared to the local and remote folders found now. Any folders in the database which are no longer present will then have their counterpart deleted. For example, if the local folder foo is deleted, the remote folder foo will be deleted during sync.
Note that folder deletions only apply in the sync direction. In the example above, foo will only be deleted if
sync_directionis set toSYNC_LOCAL_TO_REMOTEorSYNC_BOTH.- Parameters:
discovered_local (
List[LocalNoteFolder]) – List of currently discovered local note folders.discovered_remote (
List[RemoteNoteFolder]) – List of currently discovered remote note folders.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if folder deletions are successfully synchronised.-data (
str) - error message on failure, or success message.
- sync_local_note_to_remote(local, remote, result)
Sync local notes to remote. This performs an update or an insert.
- Parameters:
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if notes are successfully synchronised.-data (
str) - error message on failure, or dictionary of changes.
- sync_local_to_remote(result)
Sync all the local notes in this folder to remote.
- Parameters:
result (
dict) – dictionary where results will be saved.- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if notes are successfully synchronised.-data (
str) - error message on failure, or success message.
- static sync_note_deletions(remote_folder)
Synchronises deletions to notes.
The list of notes found during the last sync is loaded from SQLite and compared to the local and remote notes found now. Any notes in the database which are no longer present will then have their counterpart deleted. For example, if the local note foo is deleted, the remote note foo will be deleted during sync.
Note that note deletions only apply in the sync direction. In the example above, foo will only be deleted if
sync_directionis set toSYNC_LOCAL_TO_REMOTEorSYNC_BOTH.On success, this method returns a dictionary with changes, containing the following keys:
remote_deleted- name of deleted remote notes asList[str].local_deleted- name of deleted local notes asList[str].remote_not_found- name of notes marked for remote deletion which were not found asList[str].local_not_found- name of notes marked for local deletion which were not found asList[str].
A note not being found is not considered an error, as the user may have deleted the note manually prior to the sync running.
- Parameters:
remote_folder (
Path) – Path to the folder on the filesystem containing the remote notes.- Return type:
tuple[bool,str] |tuple[bool,dict]- Returns:
-success (
bool) - true if note deletions are successfully synchronised.-data (
str| :py:class`dict`) - error message on failure, or result as above on success.
- sync_notes()
Synchronises notes. This method checks the
sync_directionof this folder to determine what to do. On success, it returns a dictionary with the following keys:remote_added- name of notes added to the remote folder asList[str].remote_updated- name of notes updated in the remote folder asList[str].local_added- name of notes added to the local folder asList[str].local_updated- name of notes updated in the local folder asList[str].
Any of the above may be empty if no such changes were made.
- Return type:
tuple[bool,dict] |tuple[bool,str]- Returns:
-success (
bool) - true if notes are successfully synchronised.-data (
str|dict) - error message on failure, ordictwith results as above.
- static sync_remote_deletions(discovered_remote)
Sync folders that have been marked for local <- remote sync.
- Parameters:
discovered_remote (
List[RemoteNoteFolder]) – list of currently discovered remote note folders.- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if folder deletions are successfully synchronised.-data (
str) - error message on failure, or success message.
- sync_remote_note_to_local(local, remote, result)
Sync remote notes to local. This performs an update or an insert. Since the Apple Notes modified date is read only, we have to update the modified date of the remote note as well, otherwise the remote note will be overwritten on the next sync.
- Parameters:
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if notes are successfully synchronised.-data (
str) - error message on failure, or success message.
- sync_remote_to_local(result)
Sync all remote notes in this folder to local.
- Parameters:
result – dictionary where results will be saved.
- Return type:
tuple[bool,str]- Returns:
-success (
bool) - true if notes are successfully synchronised.-data (
str) - error message on failure, or success message.
-
FOLDER_LIST: