Package conduit :: Module Synchronization :: Class SyncWorker
[hide private]

Class SyncWorker

source code


Class designed to be operated within a thread used to perform the synchronization operation. Inherits from GObject because it uses signals to communcate with the main GUI.

Operates on a per Conduit basis, so a single SyncWorker may synchronize one source with many sinks within a single conduit

Instance Methods [hide private]
 
__init__(self, typeConverter, cond, do_sync) source code
 
_emit_progress(self, progress, dataUID)
Emits progress signals, if the elapsed progress since the last call to this function is greater that 5%.
source code
 
_get_data(self, source, sink, uid)
Gets the data from source.
source code
 
_put_data(self, source, sink, sourceData, sourceDataRid)
Handles exceptions when putting data from source to sink.
source code
 
_convert_data(self, source, sink, data)
Converts data into a format acceptable for sink, handling exceptions, etc.
source code
 
_apply_deleted_policy(self, sourceWrapper, sourceDataLUID, sinkWrapper, sinkDataLUID)
Applies user policy when data has been deleted from source.
source code
 
_apply_conflict_policy(self, sourceWrapper, sinkWrapper, comparison, fromData, fromDataRid, toData, toDataRid)
Applies user policy when a put() has failed.
source code
 
check_thread_not_cancelled(self, dataprovidersToCancel)
Checks if the thread has been scheduled to be cancelled.
source code
 
one_way_sync(self, source, sink)
Transfers numItems of data from source to sink.
source code
 
two_way_sync(self, source, sink)
Performs a two way sync from source to sink and back.
source code
 
run(self)
The main syncronisation state machine.
source code

Inherited from _ThreadedWorker: cancel, did_sync_conflict, did_sync_error

Inherited from _ThreadedWorker (private): _get_changes

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  PROGRESS_UPDATE_THRESHOLD = 5.0/ 100

Inherited from _ThreadedWorker: CONFIGURE_STATE, DONE_STATE, REFRESH_STATE, SYNC_STATE

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, typeConverter, cond, do_sync)
(Constructor)

source code 
Overrides: _ThreadedWorker.__init__

_emit_progress(self, progress, dataUID)

source code 
Emits progress signals, if the elapsed progress since the last call to this function is greater that 5%. This is necessary because otherwise we starve the main loop with too frequent progress events

_get_data(self, source, sink, uid)

source code 
Gets the data from source. Handles exceptions, etc.
Returns:
The data that was got or None

_put_data(self, source, sink, sourceData, sourceDataRid)

source code 
Handles exceptions when putting data from source to sink. Default is not to overwrite
Returns:
True if the data was successfully put

_apply_deleted_policy(self, sourceWrapper, sourceDataLUID, sinkWrapper, sinkDataLUID)

source code 
Applies user policy when data has been deleted from source. sourceDataLUID is the original UID of the data that has been deleted sinkDataLUID is the uid of the data in sink that should now be deleted

_apply_conflict_policy(self, sourceWrapper, sinkWrapper, comparison, fromData, fromDataRid, toData, toDataRid)

source code 
Applies user policy when a put() has failed. This may mean emitting the conflict up to the GUI or skipping altogether

check_thread_not_cancelled(self, dataprovidersToCancel)

source code 
Checks if the thread has been scheduled to be cancelled. If it has then this function sets the status of the dataproviders to indicate that they were stopped through a cancel operation.

run(self)

source code 

The main syncronisation state machine.

Takes the conduit through the refresh->get,put,get,put->done steps, setting its status at the appropriate time and performing nicely in the case of errors.

It is also threaded so remember
  1. Syncronization should not block the GUI
  2. Due to pygtk/gtk single threadedness do not attempt to communicate with the gui in any way other than signals, which since Glib 2.10 are threadsafe.
If any error occurs during sync raise a conduit.Exceptions.StopSync exception otherwise exit normally
Raises:
Overrides: threading.Thread.run