[Dextrose] [PATCH 3/5][dx3][sugar] multi-selection model
Martin Abente
martin.abente.lahaye at gmail.com
Tue Jun 7 17:46:24 EDT 2011
Implements the synchronous copy and delete multiple operations.
Add a "_sync_signals_enabled" global boolean that acts as filter
for the "created" and "deleted" module signals. This is a tentative
approach to avoid a massive signals spam.
Makes no sense and is a big scalability problem, to update the view
for every entry _after_ a synchronous multiple operation. In those
situations just one view redraw is required.
The only "negative" side effect of this approach is that none of the
bundles that get copied to the datastore will be installed. Considering
the hardware specs of the laptops that actually run sugar, this could be
a wise decision.
A better approach could be to specify that every "atomic" operation
will not emit the signal, but it will require to modify the datastore.
Signed-off-by: Martin Abente <martin.abente.lahaye at gmail.com>
---
src/jarabe/journal/model.py | 55 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index fd25681..abbc94c 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -55,6 +55,16 @@ created = dispatch.Signal()
updated = dispatch.Signal()
deleted = dispatch.Signal()
+_sync_signals_enabled = True
+def _emit_created(object_id):
+ global _sync_signals_enabled
+ if _sync_signals_enabled:
+ created.send(None, object_id=object_id)
+
+def _emit_deleted(object_id):
+ global _sync_signals_enabled
+ if _sync_signals_enabled:
+ deleted.send(None, object_id=object_id)
class _Cache(object):
@@ -419,6 +429,42 @@ class InplaceResultSet(BaseResultSet):
return
+def _set_signals_state(state, callback=None, data=None):
+ global _sync_signals_enabled
+ _sync_signals_enabled = state
+ if callback:
+ callback(data)
+
+def copy_entries(entries_set, mount_point):
+ _set_signals_state(False)
+ status, message = True, ''
+ for entry_uid in entries_set:
+ try:
+ metadata = get(entry_uid)
+ copy(metadata, mount_point)
+ except ValueError:
+ logging.warning('Entry %s has nothing to copied', entry_uid)
+ except (OSError, IOError):
+ status, message = False, _('No available space to continue')
+ break
+ gobject.idle_add(_set_signals_state, True)
+ return (status, message)
+
+def delete_entries(entries_set, mount_point):
+ _set_signals_state(False)
+ for entry_uid in entries_set:
+ try:
+ delete(entry_uid)
+ except (OSError, IOError):
+ logging.warning('Entry %s could not be deleted', entry_uid)
+ gobject.idle_add(_set_signals_state, True,
+ __post_delete_entries_cb, mount_point)
+
+def __post_delete_entries_cb(mount_point):
+ if mount_point is '/':
+ mount_point = 'abcde'
+ _emit_deleted(mount_point)
+
def _get_file_metadata(path, stat, fetch_preview=True):
"""Return the metadata from the corresponding file.
@@ -500,9 +546,8 @@ def _get_datastore():
return _datastore
-
def _datastore_created_cb(object_id):
- created.send(None, object_id=object_id)
+ _emit_created(object_id)
def _datastore_updated_cb(object_id):
@@ -510,7 +555,7 @@ def _datastore_updated_cb(object_id):
def _datastore_deleted_cb(object_id):
- deleted.send(None, object_id=object_id)
+ _emit_deleted(object_id)
def find(query_, page_size):
@@ -608,7 +653,7 @@ def delete(object_id):
except EnvironmentError:
logging.error('Could not remove metadata=%s '
'for file=%s', old_file, filename)
- deleted.send(None, object_id=object_id)
+ _emit_deleted(object_id)
def copy(metadata, mount_point):
@@ -738,7 +783,7 @@ def _write_entry_on_external_device(metadata, file_path):
metadata_dir_path)
object_id = destination_path
- created.send(None, object_id=object_id)
+ _emit_created(object_id)
return object_id
--
1.7.4.4
More information about the Dextrose
mailing list