[Sugar-devel] [PATCH sugar] Handle datastore.error signal

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


datastore.error signal is raised when available free space is under
datastore.SPACE_THRESHOLD (50Mb). At the moment it's sent with the
datastore.LOW_SPACE constant as keyword argument (errno). This allow
us to handle different errors in the future.

When this signal is received by JournalActivity, it shows a ModalAlert
telling the user that his Journal is full and he should remove some
entries.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 src/jarabe/journal/journalactivity.py | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 23a0b38..18d0f63 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -29,6 +29,8 @@ import os
 from sugar3.graphics.window import Window
 from sugar3.graphics.alert import ErrorAlert
 
+from sugar3.datastore import datastore
+
 from sugar3.bundle.bundle import ZipExtractException, RegistrationException
 from sugar3 import env
 from sugar3.activity import activityfactory
@@ -52,7 +54,6 @@ J_DBUS_SERVICE = 'org.laptop.Journal'
 J_DBUS_INTERFACE = 'org.laptop.Journal'
 J_DBUS_PATH = '/org/laptop/Journal'
 
-_SPACE_TRESHOLD = 52428800
 _BUNDLE_ID = 'org.laptop.JournalActivity'
 
 _journal = None
@@ -148,7 +149,17 @@ class JournalActivity(JournalWindow):
         self.iconify()
 
         self._critical_space_alert = None
-        self._check_available_space()
+
+        # connect the error datastore signal to manage LOW_SPACE
+        datastore.error.connect(self.__datastore_error_cb)
+
+    def __datastore_error_cb(self, sender, **kwargs):
+        logging.debug('__datastore_error_cb')
+        if kwargs.get('errno', -1) == datastore.LOW_SPACE:
+            self._critical_space_alert = ModalAlert()
+            self._critical_space_alert.connect('destroy',
+                                               self.__alert_closed_cb)
+            self._critical_space_alert.show()
 
     def __volume_error_cb(self, gobject, message, severity):
         alert = ErrorAlert(title=severity, msg=message)
@@ -262,7 +273,6 @@ class JournalActivity(JournalWindow):
     def __model_created_cb(self, sender, **kwargs):
         self._check_for_bundle(kwargs['object_id'])
         self._main_toolbox.refresh_filters()
-        self._check_available_space()
 
     def __model_updated_cb(self, sender, **kwargs):
         self._check_for_bundle(kwargs['object_id'])
@@ -271,8 +281,6 @@ class JournalActivity(JournalWindow):
                 kwargs['object_id'] == self._detail_view.props.metadata['uid']:
             self._detail_view.refresh()
 
-        self._check_available_space()
-
     def __model_deleted_cb(self, sender, **kwargs):
         if self.canvas == self._secondary_view and \
                 kwargs['object_id'] == self._detail_view.props.metadata['uid']:
@@ -333,23 +341,6 @@ class JournalActivity(JournalWindow):
         visible = event.get_state() != Gdk.VisibilityState.FULLY_OBSCURED
         self._list_view.set_is_visible(visible)
 
-    def _check_available_space(self):
-        """Check available space on device
-
-            If the available space is below 50MB an alert will be
-            shown which encourages to delete old journal entries.
-        """
-
-        if self._critical_space_alert:
-            return
-        stat = os.statvfs(env.get_profile_path())
-        free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
-        if free_space < _SPACE_TRESHOLD:
-            self._critical_space_alert = ModalAlert()
-            self._critical_space_alert.connect('destroy',
-                                               self.__alert_closed_cb)
-            self._critical_space_alert.show()
-
     def __alert_closed_cb(self, data):
         self.show_main_view()
         self.reveal()
-- 
1.7.11.4



More information about the Sugar-devel mailing list