[Dextrose] [PATCH 2/5][dextrose2][sugar] Updater cancel while checking

Martin Abente martin.abente.lahaye at gmail.com
Tue Apr 19 17:21:25 EDT 2011


Consideing that the microformat file is retrived
asynchronously, it makes sense to be able to
cancel it.

---
 .../cpsection/updater/backends/microformat.py      |    7 +++++++
 extensions/cpsection/updater/model.py              |    2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/extensions/cpsection/updater/backends/microformat.py b/extensions/cpsection/updater/backends/microformat.py
index c3d7b18..6175cbe 100644
--- a/extensions/cpsection/updater/backends/microformat.py
+++ b/extensions/cpsection/updater/backends/microformat.py
@@ -163,6 +163,10 @@ class _UpdateFetcher(gobject.GObject):
         sp_version = '%s.%s' % (major, int(minor) + int(minor) % 2)
         self._data = ''
         self._completion_cb = completion_cb
+        self._cancelling = False
+
+    def cancel(self):
+        self._cancelling = True
 
     def download_bundle_updates(self):
         self.emit('progress', ACTION_CHECKING, 'Fetching update '
@@ -191,6 +195,9 @@ class _UpdateFetcher(gobject.GObject):
         stream.read_async(4096, self.__stream_read_cb)
 
     def __stream_read_cb(self, stream, result):
+        if self._cancelling:
+            self._completion_cb({}, '')
+            return
         data = stream.read_finish(result)
         if not data:
             self._data_finished()
diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py
index 9bbb506..3342ffe 100755
--- a/extensions/cpsection/updater/model.py
+++ b/extensions/cpsection/updater/model.py
@@ -214,6 +214,8 @@ class UpdateModel(gobject.GObject):
 
     def cancel(self):
         self._cancelling = True
+        if self._fetcher != None:
+            self._fetcher.cancel()
 
     def _cancel_checking(self):
         logging.debug('UpdateModel._cancel_checking')
-- 
1.7.4.4



More information about the Dextrose mailing list