[Dextrose] [PATCH sugar 03/11] Journal:show error message on write failure: #1842

Aleksey Lim alsroot at member.fsf.org
Sat Jan 15 09:10:42 EST 2011


From: anishmangal2002 <anishmangal2002 at gmail.com>

volumestoolbar.py now catches the IOError and ValueError
exceptions and emits 'volume-error'signal. This signal is
caught in journalactivity.py which displays the error as
an ErrorAlert message.

Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
---
 src/jarabe/journal/journalactivity.py |   13 +++++--------
 src/jarabe/journal/volumestoolbar.py  |   28 +++++++++++++++++-----------
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 52a677e..5d74ae9 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -142,15 +142,13 @@ class JournalActivity(JournalWindow):
         self._critical_space_alert = None
         self._check_available_space()
 
-    def _alert_notify_cb(self, gobject, strerror, severity):
-        alert = ErrorAlert()
-        alert.props.title= severity
-        alert.props.msg = strerror
-        alert.connect('response', self._alert_response_cb)
+    def __alert_notify_cb(self, gobject, strerror, severity):
+        alert = ErrorAlert(title=severity, msg=strerror)
+        alert.connect('response', self.__alert_response_cb)
         self.add_alert(alert)
         alert.show()
 
-    def _alert_response_cb(self, alert, response_id):
+    def __alert_response_cb(self, alert, response_id):
         self.remove_alert(alert)
 
     def __realize_cb(self, window):
@@ -176,8 +174,7 @@ class JournalActivity(JournalWindow):
         self._volumes_toolbar = VolumesToolbar()
         self._volumes_toolbar.connect('volume-changed',
                                       self.__volume_changed_cb)
-        self._volumes_toolbar.connect('volume-error', self._alert_notify_cb,
-                                      'Error')
+        self._volumes_toolbar.connect('volume-error', self.__alert_notify_cb)
         self._main_view.pack_start(self._volumes_toolbar, expand=False)
 
         search_toolbar = self._main_toolbox.search_toolbar
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 36e22d7..dd6fcec 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -15,6 +15,7 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 import logging
+import os
 from gettext import gettext as _
 
 import gobject
@@ -40,7 +41,7 @@ class VolumesToolbar(gtk.Toolbar):
                            ([str])),
         'volume-error': (gobject.SIGNAL_RUN_FIRST,
                            gobject.TYPE_NONE,
-                           ([str]))
+                           ([str, str]))
     }
 
     def __init__(self):
@@ -107,7 +108,7 @@ class VolumesToolbar(gtk.Toolbar):
         button = VolumeButton(mount)
         button.props.group = self._volume_buttons[0]
         button.connect('toggled', self._button_toggled_cb)
-        button.connect('volume-error', self._volume_error_cb)
+        button.connect('volume-error', self.__volume_error_cb)
         position = self.get_item_index(self._volume_buttons[-1]) + 1
         self.insert(button, position)
         button.show()
@@ -117,8 +118,8 @@ class VolumesToolbar(gtk.Toolbar):
         if len(self.get_children()) > 1:
             self.show()
 
-    def _volume_error_cb(self, button, strerror):
-        self.emit('volume-error', strerror)
+    def __volume_error_cb(self, button, strerror, severity):
+        self.emit('volume-error', strerror, severity)
 
     def _button_toggled_cb(self, button):
         if button.props.active:
@@ -157,7 +158,7 @@ class BaseButton(RadioToolButton):
     __gsignals__ = {
         'volume-error': (gobject.SIGNAL_RUN_FIRST,
                            gobject.TYPE_NONE,
-                           ([str]))
+                           ([str, str]))
     }
 
     def __init__(self, mount_point):
@@ -174,14 +175,19 @@ class BaseButton(RadioToolButton):
                                info, timestamp):
         object_id = selection_data.data
         metadata = model.get(object_id)
+        file_path = model.get_file(metadata['uid'])
+        if not file_path or not os.path.exists(file_path):
+            logging.warn('File does not exist')
+            self.emit('volume-error', _('Entries without a file cannot'
+                ' be copied'), _('Warning'))
+            return
+
         try:
             model.copy(metadata, self.mount_point)
-        except IOError as (errno, strerror):
-            logging.error('BaseButton._drag_data_received_cb: IOError: %s; %s' % (errno, strerror))
-            self.emit('volume-error', strerror)
-        except ValueError as (strerror):
-            logging.error('BaseButton._drag_data_received_cb: ValueError: %s' % (strerror))
-            self.emit('volume-error', strerror)
+        except IOError:
+            logging.exception('BaseButton._drag_data_received_cb: Error'
+                'while copying')
+            self.emit('volume-error', _('Input/Output error'), _('Error'))
 
 class VolumeButton(BaseButton):
     def __init__(self, mount):
-- 
1.7.3.4



More information about the Dextrose mailing list