[Sugar-devel] [PATCH sugar-toolkit-gtk3 1/2] Activity class method to check enough space

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


New method to check if there is enough space to handle a file with the
size passed as argument on a specific path.

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

diff --git a/src/sugar3/activity/activity.py b/src/sugar3/activity/activity.py
index c896caf..c6f500f 100644
--- a/src/sugar3/activity/activity.py
+++ b/src/sugar3/activity/activity.py
@@ -891,6 +891,22 @@ class Activity(Window, Gtk.Container):
 
         return True
 
+    def enough_space(self, size, path='/'):
+        """Check if there is enough (size) free space on path
+
+        size -- free space requested in Kb
+
+        path -- device where the check will be done. For example: '/tmp'
+
+        This method is useful to check the free space, for example,
+        before starting a download from internet, creating a big map
+        in some game or whatever action that needs some space in the
+        Hard Disk.
+        """
+
+        free_space = datastore.free_available_space(path=path)
+        return free_space - size > datastore.SPACE_THRESHOLD
+
     def _prepare_close(self, skip_save=False):
         if not skip_save:
             try:
-- 
1.7.11.4



More information about the Sugar-devel mailing list