From patchwork Tue Sep 18 11:18:32 2012
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [sugar-toolkit-gtk3,2/2] Signal to check free available space
Date: Tue, 18 Sep 2012 16:18:32 -0000
From: Manuel Kaufmann <humitos@gmail.com>
X-Patchwork-Id: 1750
Message-Id: <1347967112-4960-2-git-send-email-humitos@gmail.com>
To: simon@laptop.org
Cc: Manuel Kaufmann <humitos@gmail.com>, sugar-devel@lists.sugarlabs.org
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@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
|
b
|
DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore' |
39 | 39 | DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore' |
40 | 40 | DS_DBUS_PATH = '/org/laptop/sugar/DataStore' |
41 | 41 | |
| 42 | SPACE_THRESHOLD = 52428800 # 50Mb |
| 43 | |
| 44 | # Error codes |
| 45 | LOW_SPACE = 1 |
| 46 | |
42 | 47 | _data_store = None |
43 | 48 | |
44 | 49 | |
… |
… |
def _get_data_store(): |
57 | 62 | return _data_store |
58 | 63 | |
59 | 64 | |
| 65 | def free_available_space(path='/'): |
| 66 | s = os.statvfs(path) |
| 67 | return s.f_bavail * s.f_frsize |
| 68 | |
| 69 | |
60 | 70 | def __datastore_created_cb(object_id): |
61 | 71 | metadata = _get_data_store().get_properties(object_id, byte_arrays=True) |
62 | 72 | updated.send(None, object_id=object_id, metadata=metadata) |
| 73 | if free_available_space() < SPACE_THRESHOLD: |
| 74 | error.send(None, errno=LOW_SPACE) |
63 | 75 | |
64 | 76 | |
65 | 77 | def __datastore_updated_cb(object_id): |
66 | 78 | metadata = _get_data_store().get_properties(object_id, byte_arrays=True) |
67 | 79 | updated.send(None, object_id=object_id, metadata=metadata) |
| 80 | if free_available_space() < SPACE_THRESHOLD: |
| 81 | logging.warning('Free space below SPACE_THRESHOLD: %s Kb', |
| 82 | SPACE_THRESHOLD) |
| 83 | error.send(None, errno=LOW_SPACE) |
68 | 84 | |
69 | 85 | |
70 | 86 | def __datastore_deleted_cb(object_id): |
… |
… |
created = dispatch.Signal() |
74 | 90 | deleted = dispatch.Signal() |
75 | 91 | updated = dispatch.Signal() |
76 | 92 | |
| 93 | error = dispatch.Signal() |
| 94 | |
77 | 95 | _get_data_store() |
78 | 96 | |
79 | 97 | |