From 8d4eabe79c3513a34529aafe7ad47300e426cb3e Mon Sep 17 00:00:00 2001 From: Sam Schott Date: Mon, 18 May 2020 15:50:58 +0200 Subject: [PATCH] some refactoring --- maestral/client.py | 2 +- maestral/main.py | 10 +++++----- maestral/sync.py | 30 +++++++++++++++--------------- tests/test_sync.py | 10 +++++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/maestral/client.py b/maestral/client.py index 9b3ba3e9..ed1e1462 100644 --- a/maestral/client.py +++ b/maestral/client.py @@ -118,7 +118,7 @@ def to_maestral_error(dbx_path_arg=None, local_path_arg=None): return decorator -class MaestralApiClient: +class DropboxClient: """Client for the Dropbox SDK. This client defines basic methods to wrap Dropbox Python SDK calls, such as creating, diff --git a/maestral/main.py b/maestral/main.py index cec34acb..781adf38 100644 --- a/maestral/main.py +++ b/maestral/main.py @@ -37,8 +37,8 @@ import sdnotify # local imports from maestral import __version__ from maestral.oauth import OAuth2Session -from maestral.client import MaestralApiClient, to_maestral_error -from maestral.sync import MaestralMonitor +from maestral.client import DropboxClient, to_maestral_error +from maestral.sync import SyncMonitor from maestral.errors import ( MaestralApiError, NotLinkedError, NoDropboxDirError, NotFoundError, PathError @@ -241,8 +241,8 @@ class Maestral: self._setup_logging() self._auth = OAuth2Session(config_name) - self.client = MaestralApiClient(config_name=self.config_name, access_token='none') - self.monitor = MaestralMonitor(self.client) + self.client = DropboxClient(config_name=self.config_name, access_token='none') + self.monitor = SyncMonitor(self.client) self.sync = self.monitor.sync # periodically check for updates and refresh account info @@ -821,7 +821,7 @@ class Maestral: def list_folder(self, dbx_path, **kwargs): """ List all items inside the folder given by ``dbx_path``. Keyword arguments are - passed on the the Dropbox API call :meth:`client.MaestralApiClient.list_folder`. + passed on the the Dropbox API call :meth:`client.DropboxClient.list_folder`. :param dbx_path: Path to folder on Dropbox. :returns: List of Dropbox item metadata as dicts or ``False`` if listing failed diff --git a/maestral/sync.py b/maestral/sync.py index 9666773d..7eaba6d2 100644 --- a/maestral/sync.py +++ b/maestral/sync.py @@ -120,7 +120,7 @@ class FSEventHandler(FileSystemEventHandler): :param Event syncing: Set when syncing is running. :param Event startup: Set when startup is running. - :param UpDownSync sync: UpDownSync instance. + :param SyncEngine sync: UpDownSync instance. :cvar int ignore_timeout: Timeout in seconds after which ignored paths will be discarded. @@ -251,13 +251,13 @@ class FSEventHandler(FileSystemEventHandler): self.local_file_event_queue.put(event) -class MaestralStateWrapper(abc.MutableSet): +class PersistentStateMutableSet(abc.MutableSet): """ A wrapper for a list of strings in the saved state that implements a MutableSet interface. All strings are stored as lower-case, reflecting Dropbox's case-insensitive file system. - :param str config_name: Name of config. + :param str config_name: Name of config (determines name of state file). :param str section: Section name in state file. :param str option: Option name in state file. """ @@ -359,7 +359,7 @@ def catch_sync_issues(download=False): return decorator -class UpDownSync: +class SyncEngine: """ Class that contains methods to sync local file events with Dropbox and vice versa. @@ -431,7 +431,7 @@ class UpDownSync: finally confirm the successful upload and check if Dropbox has renamed the item to a conflicting copy. In the latter case, we apply those changes locally. - :param MaestralApiClient client: Dropbox API client instance. + :param DropboxClient client: Dropbox API client instance. """ @@ -452,10 +452,10 @@ class UpDownSync: self._state = MaestralState(self.config_name) self._notifier = MaestralDesktopNotifier.for_config(self.config_name) - self.download_errors = MaestralStateWrapper( + self.download_errors = PersistentStateMutableSet( self.config_name, section='sync', option='download_errors' ) - self.pending_downloads = MaestralStateWrapper( + self.pending_downloads = PersistentStateMutableSet( self.config_name, section='sync', option='pending_downloads' ) @@ -2595,7 +2595,7 @@ def helper(mm): and syncing has not been paused by the user. 3) Triggers weekly reindexing. - :param MaestralMonitor mm: MaestralMonitor instance. + :param SyncMonitor mm: MaestralMonitor instance. """ while mm.running.is_set(): @@ -2623,7 +2623,7 @@ def download_worker(sync, syncing, running, connected): """ Worker to sync changes of remote Dropbox with local folder. - :param UpDownSync sync: Instance of :class:`UpDownSync`. + :param SyncEngine sync: Instance of :class:`SyncEngine`. :param Event syncing: Event that indicates if workers are running or paused. :param Event running: Event to shutdown local file event handler and worker threads. :param Event connected: Event that indicates if we can connect to Dropbox. @@ -2669,7 +2669,7 @@ def download_worker_added_item(sync, syncing, running, connected): """ Worker to download items which have been newly included in sync. - :param UpDownSync sync: Instance of :class:`UpDownSync`. + :param SyncEngine sync: Instance of :class:`SyncEngine`. :param Event syncing: Event that indicates if workers are running or paused. :param Event running: Event to shutdown local file event handler and worker threads. :param Event connected: Event that indicates if we can connect to Dropbox. @@ -2707,7 +2707,7 @@ def upload_worker(sync, syncing, running, connected): """ Worker to sync local changes to remote Dropbox. - :param UpDownSync sync: Instance of :class:`UpDownSync`. + :param SyncEngine sync: Instance of :class:`SyncEngine`. :param Event syncing: Event that indicates if workers are running or paused. :param Event running: Event to shutdown local file event handler and worker threads. :param Event connected: Event that indicates if we can connect to Dropbox. @@ -2748,7 +2748,7 @@ def startup_worker(sync, syncing, running, connected, startup, paused_by_user): """ Worker to sync local changes to remote Dropbox. - :param UpDownSync sync: Instance of :class:`UpDownSync`. + :param SyncEngine sync: Instance of :class:`SyncEngine`. :param Event syncing: Event that indicates if workers are running or paused. :param Event running: Event to shutdown local file event handler and worker threads. :param Event connected: Event that indicates if we can connect to Dropbox. @@ -2827,7 +2827,7 @@ def startup_worker(sync, syncing, running, connected, startup, paused_by_user): # Main Monitor class to start, stop and coordinate threads # ======================================================================================== -class MaestralMonitor: +class SyncMonitor: """ Class to sync changes between Dropbox and a local folder. It creates five threads: `observer` to retrieve local file system events, `startup_thread` to carry out any @@ -2835,7 +2835,7 @@ class MaestralMonitor: Dropbox, `download_thread` to query for and download remote changes, and `helper_thread` which periodically checks the connection to Dropbox servers. - :param MaestralApiClient client: The Dropbox API client, a wrapper around the Dropbox + :param DropboxClient client: The Dropbox API client, a wrapper around the Dropbox Python SDK. """ @@ -2845,7 +2845,7 @@ class MaestralMonitor: self.client = client self.config_name = self.client.config_name - self.sync = UpDownSync(self.client) + self.sync = SyncEngine(self.client) self.connected = Event() self.syncing = Event() diff --git a/tests/test_sync.py b/tests/test_sync.py index d35b7c44..512543e2 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -20,7 +20,7 @@ from maestral.sync import ( from maestral.sync import delete, move from maestral.sync import is_child from maestral.sync import get_local_hash, DirectorySnapshot -from maestral.sync import UpDownSync, Observer, FSEventHandler +from maestral.sync import SyncEngine, Observer, FSEventHandler from maestral.errors import NotFoundError, FolderConflictError from maestral.main import Maestral from maestral.main import get_log_path @@ -30,7 +30,7 @@ import unittest from unittest import TestCase -class DummyUpDownSync(UpDownSync): +class DummySyncEngine(SyncEngine): def __init__(self, dropbox_path=''): self._dropbox_path = dropbox_path @@ -50,7 +50,7 @@ def path(i): class TestCleanLocalEvents(TestCase): def setUp(self): - self.sync = DummyUpDownSync() + self.sync = DummySyncEngine() def test_single_file_events(self): @@ -286,7 +286,7 @@ class TestCleanLocalEvents(TestCase): class TestIgnoreLocalEvents(TestCase): def setUp(self): - self.sync = DummyUpDownSync() + self.sync = DummySyncEngine() self.dummy_dir = Path(os.getcwd()).parent / 'dropbox_dir' delete(self.dummy_dir) @@ -296,7 +296,7 @@ class TestIgnoreLocalEvents(TestCase): startup = Event() syncing.set() - self.sync = DummyUpDownSync(self.dummy_dir) + self.sync = DummySyncEngine(self.dummy_dir) self.fs_event_handler = FSEventHandler(syncing, startup, self.sync) self.observer = Observer()