maestral.database
This module contains the definitions of our database tables which store the index, sync
history and cache of content hashes. Each table is defined by a subclass of
maestral.utils.orm.Model
with properties representing database columns. Class
instances then represent table rows.
- class maestral.database.SyncDirection(value)[source]
Bases:
enum.Enum
Enumeration of sync directions
- Up = 'up'
- Down = 'down'
- class maestral.database.SyncStatus(value)[source]
Bases:
enum.Enum
Enumeration of sync status
- Queued = 'queued'
- Syncing = 'syncing'
- Done = 'done'
- Failed = 'failed'
- Skipped = 'skipped'
- Aborted = 'aborted'
- class maestral.database.ItemType(value)[source]
Bases:
enum.Enum
Enumeration of SyncEvent types
- File = 'file'
- Folder = 'folder'
- Unknown = 'unknown'
- class maestral.database.ChangeType(value)[source]
Bases:
enum.Enum
Enumeration of SyncEvent change types
- Added = 'added'
- Removed = 'removed'
- Moved = 'moved'
- Modified = 'modified'
- class maestral.database.SyncEvent(**kwargs)[source]
Bases:
maestral.utils.orm.Model
Represents a file or folder change in the sync queue
This class is used to represent both local and remote file system changes and track their sync progress. Some instance attributes will depend on the state of the sync session, e.g.,
local_path
will depend on the current path of the local Dropbox folder. They may therefore become invalid between sync sessions.The class methods
from_dbx_metadata()
andfrom_file_system_event()
should be used to properly construct aSyncEvent
from adropbox.files.Metadata
instance or awatchdog.events.FileSystemEvent
instance, respectively.Initialise with keyword arguments corresponding to column names and values.
- Parameters
kwargs – Keyword arguments assigning values to table columns.
- Return type
None
- property id: Any
A unique identifier of the SyncEvent.
- property direction: Any
The
SyncDirection
.
- property sync_time: Any
The time the SyncEvent was registered.
- property dbx_id: Any
A unique dropbox ID for the file or folder. Will only be set for download events which are not deletions.
- property dbx_path: Any
Correctly cased Dropbox path of the item to sync. If the sync represents a move operation, this will be the destination path. Follows the casing from the path_display attribute of Dropbox metadata.
- property dbx_path_lower: Any
Dropbox path of the item to sync. If the sync represents a move operation, this will be the destination path. This is normalised as the path_lower attribute of Dropbox metadata.
- property local_path: Any
Local path of the item to sync. If the sync represents a move operation, this will be the destination path. This will be correctly cased.
- property dbx_path_from: Any
Dropbox path that this item was moved from. Will only be set if
change_type
isChangeType.Moved
. Follows the casing from the path_display attribute of Dropbox metadata.
- property dbx_path_from_lower: Any
Dropbox path that this item was moved from. Will only be set if
change_type
isChangeType.Moved
. This is normalised as the path_lower attribute of Dropbox metadata.
- property local_path_from: Any
Local path that this item was moved from. Will only be set if
change_type
isChangeType.Moved
. This will be correctly cased.
- property rev: Any
The file revision. Will only be set for remote changes. Will be
'folder'
for folders andNone
for deletions.
- property content_hash: Any
A hash representing the file content. Will be
'folder'
for folders andNone
for deletions. Set for both local and remote changes.
- property symlink_target: Any
If the file is a symlink, its target path. This should only be set for files.
- property change_type: Any
The
ChangeType
. Remote SyncEvents currently do not generate moved events but are reported as deleted and added at the new location.
- property change_time: Any
Local ctime or remote
client_modified
time for files.None
for folders or for remote deletions. Note thatclient_modified
may not be reliable as it is set by other clients and not verified.
- property change_dbid: Any
The Dropbox ID of the account which performed the changes. This may not be set for added folders or deletions on the server.
- property change_user_name: Any
The user name corresponding to
change_dbid
, if the account still exists. This field may not be set for performance reasons.
- property status: Any
The
SyncStatus
.
- property size: Any
Size of the item in bytes. Always zero for folders.
- property completed: Any
File size in bytes which has already been uploaded or downloaded. Always zero for folders.
- property change_time_or_sync_time: float
Change time when available, otherwise sync time. This can be used for sorting or user information purposes.
- classmethod from_dbx_metadata(md, sync_engine)[source]
Initializes a SyncEvent from the given Dropbox metadata.
- Parameters
md (dropbox.files.Metadata) – Dropbox Metadata.
sync_engine (SyncEngine) – SyncEngine instance.
- Returns
An instance of this class with attributes populated from the given Dropbox Metadata.
- Return type
- classmethod from_file_system_event(event, sync_engine)[source]
Initializes a SyncEvent from the given local file system event.
- Parameters
event (watchdog.events.FileSystemEvent) – Local file system event.
sync_engine (SyncEngine) – SyncEngine instance.
- Returns
An instance of this class with attributes populated from the given SyncEvent.
- Return type
- class maestral.database.IndexEntry(**kwargs)[source]
Bases:
maestral.utils.orm.Model
Represents an entry in our local sync index
Initialise with keyword arguments corresponding to column names and values.
- Parameters
kwargs – Keyword arguments assigning values to table columns.
- Return type
None
- property dbx_path_lower: Any
Dropbox path of the item in lower case. This acts as a primary key for the SQLites database since there can only be one entry per case-insensitive Dropbox path. Corresponds to the path_lower field of Dropbox metadata.
- property dbx_path_cased: Any
Dropbox path of the item, correctly cased. Corresponds to the path_display field of Dropbox metadata.
- property dbx_id: Any
The unique dropbox ID for the item.
- property last_sync: Any
The last time a local change was uploaded. Should be the ctime of the local item.
- property rev: Any
The file revision. Will be
'folder'
for folders.
- property content_hash: Any
A hash representing the file content. Will be
'folder'
for folders. May beNone
if not yet calculated.
- property symlink_target: Any
If the file is a symlink, its target path. This should only be set for files.
- class maestral.database.HashCacheEntry(**kwargs)[source]
Bases:
maestral.utils.orm.Model
Represents an entry in our cache of content hashes
Initialise with keyword arguments corresponding to column names and values.
- Parameters
kwargs – Keyword arguments assigning values to table columns.
- Return type
None
- property inode: Any
The inode of the item.
- property local_path: Any
The local path of the item.
- property hash_str: Any
The content hash of the item.
- property mtime: Any
The mtime of the item just before the hash was computed. When the current mtime is newer, the hash will need to be recalculated.