Ticket #394: sugar-toolkit-gtk3-2-2-Signal-to-check-free-available-space.patch

File sugar-toolkit-gtk3-2-2-Signal-to-check-free-available-space.patch, 2.3 KB (added by humitos, 11 years ago)

error (LOW_SPACE) signal in datastore

  • src/sugar3/datastore/datastore.py

    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' 
    3939DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore'
    4040DS_DBUS_PATH = '/org/laptop/sugar/DataStore'
    4141
     42SPACE_THRESHOLD = 52428800  # 50Mb
     43
     44# Error codes
     45LOW_SPACE = 1
     46
    4247_data_store = None
    4348
    4449
    def _get_data_store(): 
    5762    return _data_store
    5863
    5964
     65def free_available_space(path='/'):
     66    s = os.statvfs(path)
     67    return s.f_bavail * s.f_frsize
     68
     69
    6070def __datastore_created_cb(object_id):
    6171    metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
    6272    updated.send(None, object_id=object_id, metadata=metadata)
     73    if free_available_space() < SPACE_THRESHOLD:
     74        error.send(None, errno=LOW_SPACE)
    6375
    6476
    6577def __datastore_updated_cb(object_id):
    6678    metadata = _get_data_store().get_properties(object_id, byte_arrays=True)
    6779    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)
    6884
    6985
    7086def __datastore_deleted_cb(object_id):
    created = dispatch.Signal() 
    7490deleted = dispatch.Signal()
    7591updated = dispatch.Signal()
    7692
     93error = dispatch.Signal()
     94
    7795_get_data_store()
    7896
    7997