[Sugar-devel] [PATCH sugar-toolkit-gtk3 2/2] Signal to check free available space

Manuel Kaufmann humitos at gmail.com
Tue Sep 18 07:18:32 EDT 2012


Datastore will emit the 'datastore.error' signal when the free
available space will be under SPACE_THRESHOLD. This will allow
activities to handle this situation properly. For example, Browse
could cancel a download in progress.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 src/sugar3/datastore/datastore.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/sugar3/datastore/datastore.py b/src/sugar3/datastore/datastore.py
index 33100e8..6a39b4e 100644
--- a/src/sugar3/datastore/datastore.py
+++ b/src/sugar3/datastore/datastore.py
@@ -39,6 +39,11 @@ DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore'
 DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore'
 DS_DBUS_PATH = '/org/laptop/sugar/DataStore'
 
+SPACE_THRESHOLD = 52428800  # 50Mb
+
+# Error codes
+LOW_SPACE = 1
+
 _data_store = None
 
 
@@ -57,14 +62,25 @@ def _get_data_store():
     return _data_store
 
 
+def free_available_space(path='/'):
+    s = os.statvfs(path)
+    return s.f_bavail * s.f_frsize
+
+
 def __datastore_created_cb(object_id):
     metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
     updated.send(None, object_id=object_id, metadata=metadata)
+    if free_available_space() < SPACE_THRESHOLD:
+        error.send(None, errno=LOW_SPACE)
 
 
 def __datastore_updated_cb(object_id):
     metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
     updated.send(None, object_id=object_id, metadata=metadata)
+    if free_available_space() < SPACE_THRESHOLD:
+        logging.warning('Free space below SPACE_THRESHOLD: %s Kb',
+                        SPACE_THRESHOLD)
+        error.send(None, errno=LOW_SPACE)
 
 
 def __datastore_deleted_cb(object_id):
@@ -74,6 +90,8 @@ created = dispatch.Signal()
 deleted = dispatch.Signal()
 updated = dispatch.Signal()
 
+error = dispatch.Signal()
+
 _get_data_store()
 
 
-- 
1.7.11.4



More information about the Sugar-devel mailing list