Ticket #1361: sugar-1361.patch

File sugar-1361.patch, 11.0 KB (added by alsroot, 15 years ago)
  • extensions/cpsection/updater/backends/aslo.py

    From 066d4b59ef30fcafb0c261e51260448877f26e78 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Wed, 16 Sep 2009 12:28:11 +0000
    Subject: Cancel updating process in Update control panel component #1361
    
    ---
     extensions/cpsection/updater/backends/aslo.py |    9 ++-
     extensions/cpsection/updater/model.py         |   37 ++++++++++++-
     extensions/cpsection/updater/view.py          |   75 ++++++++++++++++++------
     3 files changed, 98 insertions(+), 23 deletions(-)
    
    diff --git a/extensions/cpsection/updater/backends/aslo.py b/extensions/cpsection/updater/backends/aslo.py
    index 443fd1c..5f257f9 100644
    a b _FIND_VERSION = './/{http://www.mozilla.org/2004/em-rdf#}version' 
    6262_FIND_LINK = './/{http://www.mozilla.org/2004/em-rdf#}updateLink'
    6363_FIND_SIZE = './/{http://www.mozilla.org/2004/em-rdf#}updateSize'
    6464
    65 _UPDATE_PATH = 'http://activities.sugarlabs.org/services/update.php'
     65_UPDATE_PATH = 'http://activities.sugarlabs.org/services/update-aslo.php'
    6666
    6767_fetcher = None
    6868
    class _UpdateFetcher(object): 
    7272    _CHUNK_SIZE = 10240
    7373
    7474    def __init__(self, bundle, completion_cb):
     75        # ASLO knows only about stable SP releases
     76        major, minor = config.version.split('.')[0:2]
     77        sp_version = '%s.%s' % (major, int(minor) + int(minor) % 2)
    7578
    7679        url = '%s?id=%s&appVersion=%s' % \
    77                 (_UPDATE_PATH, bundle.get_bundle_id(), config.version)
     80                (_UPDATE_PATH, bundle.get_bundle_id(), sp_version)
     81
     82        logging.debug('Fetch %s', url)
    7883
    7984        self._completion_cb = completion_cb
    8085        self._file = gio.File(url)
  • extensions/cpsection/updater/model.py

    diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py
    index 102edea..30f4557 100755
    a b class UpdateModel(gobject.GObject): 
    5959        self._bundles_to_check = None
    6060        self._bundles_to_update = None
    6161        self._total_bundles_to_update = 0
     62        self._bundles_updated = 0
    6263        self._downloader = None
     64        self._is_canceled = False
     65
     66    def cancel(self):
     67        logging.debug('Cancel updating')
     68
     69        self._is_canceled = True
     70        if self._downloader is not None:
     71            self._downloader.cancel()
    6372
    6473    def check_updates(self):
     74        self._is_canceled = False
    6575        self.updates = []
    6676        self._bundles_to_check = \
    6777                [bundle for bundle in bundleregistry.get_registry()]
    class UpdateModel(gobject.GObject): 
    8595        if version is not None and version > bundle.get_activity_version():
    8696            self.updates.append(BundleUpdate(bundle, version, link, size))
    8797
     98        if self._is_canceled:
     99            self.emit('progress', UpdateModel.ACTION_CHECKING, None, 0, 0)
     100            return
     101
    88102        if self._bundles_to_check:
    89103            gobject.idle_add(self._check_next_update)
    90104        else:
    class UpdateModel(gobject.GObject): 
    97111                      total)
    98112
    99113    def update(self, bundle_ids):
     114        self._is_canceled = False
    100115        self._bundles_to_update = []
    101116        for bundle_update in self.updates:
    102117            if bundle_update.bundle.get_bundle_id() in bundle_ids:
    103118                self._bundles_to_update.append(bundle_update)
    104119
    105120        self._total_bundles_to_update = len(self._bundles_to_update)
     121        self._bundles_updated = 0
     122
    106123        self._download_next_update()
    107124
    108125    def _download_next_update(self):
     126        if self._is_canceled:
     127            self.emit('progress', UpdateModel.ACTION_DOWNLOADING, None, 0, 0)
     128            return
     129
    109130        bundle_update = self._bundles_to_update.pop()
    110131
    111132        total = self._total_bundles_to_update * 2
    class UpdateModel(gobject.GObject): 
    145166
    146167    def _install_update(self, bundle_update, local_file_path):
    147168
     169        self._bundles_updated += 1
    148170        total = self._total_bundles_to_update * 2
    149171        current = total - len(self._bundles_to_update) * 2 - 1
    150172
    class UpdateModel(gobject.GObject): 
    175197            gobject.idle_add(self._download_next_update)
    176198
    177199    def get_total_bundles_to_update(self):
    178         return self._total_bundles_to_update
     200        return self._bundles_updated
    179201
    180202
    181203class BundleUpdate(object):
    class _Downloader(gobject.GObject): 
    208230        self._input_file = gio.File(bundle_update.link)
    209231        self._output_file = None
    210232        self._downloaded_size = 0
     233        self._is_canceled = False
    211234
    212235        self._input_file.read_async(self.__file_read_async_cb)
    213236
    class _Downloader(gobject.GObject): 
    217240        except:
    218241            self.emit('error', traceback.format_exc())
    219242            return
    220            
     243
    221244        temp_file_path = self._get_temp_file_path(self.bundle_update.link)
    222245        self._output_file = gio.File(temp_file_path)
    223246        self._output_stream = self._output_file.create()
    class _Downloader(gobject.GObject): 
    225248        self._input_stream.read_async(self._CHUNK_SIZE, self.__read_async_cb,
    226249                                      gobject.PRIORITY_LOW)
    227250
     251    def cancel(self):
     252        logging.debug('Cancel downloading')
     253        self._is_canceled = True
     254
    228255    def __read_async_cb(self, input_stream, result):
     256        if self._is_canceled:
     257            self._input_stream.close()
     258            self._output_stream.close()
     259            self.emit('error', 'downloading canceled')
     260            return
     261
    229262        data = input_stream.read_finish(result)
    230263
    231264        if data is None:
  • extensions/cpsection/updater/view.py

    diff --git a/extensions/cpsection/updater/view.py b/extensions/cpsection/updater/view.py
    index 9a77743..b39e555 100644
    a b class ActivityUpdater(SectionView): 
    6666
    6767        self._update_box = None
    6868        self._progress_pane = None
     69        self._finish_box = None
    6970
    7071        self._refresh()
    7172
     73    def _clear_center(self):
     74        if self._progress_pane in self.get_children():
     75            self.remove(self._progress_pane)
     76            self._progress_pane = None
     77
     78        if self._update_box in self.get_children():
     79            self.remove(self._update_box)
     80            self._update_box = None
     81
     82        if self._finish_box in self.get_children():
     83            self.remove(self._finish_box)
     84            self._finish_box = None
     85
    7286    def _switch_to_update_box(self):
    7387        if self._update_box in self.get_children():
    7488            return
    7589
    76         if self._progress_pane in self.get_children():
    77             self.remove(self._progress_pane)
    78             self._progress_pane = None
     90        self._clear_center()
    7991
    8092        if self._update_box is None:
    8193            self._update_box = UpdateBox(self._model)
    class ActivityUpdater(SectionView): 
    91103        if self._progress_pane in self.get_children():
    92104            return
    93105
    94         if self._update_box in self.get_children():
    95             self.remove(self._update_box)
    96             self._update_box = None
     106        self._clear_center()
    97107
    98108        if self._progress_pane is None:
    99109            self._progress_pane = ProgressPane()
     110            self._progress_pane.cancel_button.connect('clicked',
     111                    self.__cancel_button_clicked_cb)
    100112
    101113        self.pack_start(self._progress_pane, expand=True, fill=False)
    102114        self._progress_pane.show()
    103115
    104     def _clear_center(self):
    105         if self._progress_pane in self.get_children():
    106             self.remove(self._progress_pane)
    107             self._progress_pane = None
     116    def __cancel_button_clicked_cb(self, button):
     117        self._model.cancel()
    108118
    109         if self._update_box in self.get_children():
    110             self.remove(self._update_box)
    111             self._update_box = None
     119    def _switch_to_finish_box(self):
     120        if self._finish_box in self.get_children():
     121            return
     122
     123        self._clear_center()
     124
     125        if self._finish_box is None:
     126            self._finish_box = FinishBox()
     127            self._finish_box.refresh_button.connect('clicked',
     128                    self.__refresh_button_clicked_cb)
     129
     130        self.pack_start(self._finish_box, expand=True, fill=True)
     131        self._finish_box.show()
    112132
    113133    def __progress_cb(self, model, action, bundle_name, current, total):
    114134        if current == total and action == UpdateModel.ACTION_CHECKING:
    class ActivityUpdater(SectionView): 
    141161            top_message = gobject.markup_escape_text(top_message)
    142162
    143163        self._top_label.set_markup('<big>%s</big>' % top_message)
    144        
     164
    145165        if not available_updates:
    146             self._clear_center()
     166            self._switch_to_finish_box()
    147167        else:
    148168            self._switch_to_update_box()
    149169            self._update_box.refresh()
    class ActivityUpdater(SectionView): 
    167187        top_message = top_message % installed_updates
    168188        top_message = gobject.markup_escape_text(top_message)
    169189        self._top_label.set_markup('<big>%s</big>' % top_message)
    170         self._clear_center()
     190        self._switch_to_finish_box()
    171191
    172192
    173193class ProgressPane(gtk.VBox):
    class ProgressPane(gtk.VBox): 
    195215        self.pack_start(alignment_box)
    196216        alignment_box.show()
    197217
    198         cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
    199         alignment_box.add(cancel_button)
    200         cancel_button.show()
     218        self.cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
     219        alignment_box.add(self.cancel_button)
     220        self.cancel_button.show()
    201221
    202222    def set_message(self, message):
    203223        self._label.set_text(message)
    class UpdateBox(gtk.VBox): 
    280300        return bundles_to_update
    281301
    282302
     303class FinishBox(gtk.VBox):
     304
     305    def __init__(self):
     306        gtk.VBox.__init__(self)
     307
     308        self.set_spacing(style.DEFAULT_PADDING)
     309
     310        bottom_box = gtk.HBox()
     311        bottom_box.set_spacing(style.DEFAULT_SPACING)
     312        self.pack_end(bottom_box, expand=False)
     313        bottom_box.show()
     314
     315        self.refresh_button = gtk.Button(stock=gtk.STOCK_REFRESH)
     316        bottom_box.pack_end(self.refresh_button, expand=False)
     317        self.refresh_button.show()
     318
     319
    283320class UpdateList(gtk.TreeView):
    284321
    285322    def __init__(self, model):
  • extensions/cpsection/updater/model.py

    -- 
    1.6.3.3
    
    
    From 51ae02853de2c81fbb1efa8ec80ea37a95691e76 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Wed, 16 Sep 2009 12:29:16 +0000
    Subject: Update control panel module fails on downloading new bundle #1324
    
    ---
     extensions/cpsection/updater/model.py |    2 ++
     1 files changed, 2 insertions(+), 0 deletions(-)
    
    diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py
    index 30f4557..9bbf952 100755
    a b class _Downloader(gobject.GObject): 
    303303                urlparse(uri)
    304304        path = os.path.basename(path)
    305305
     306        os.makedirs(env.get_user_activities_path())
     307
    306308        base_name, extension_ = os.path.splitext(path)
    307309        fd, file_path = tempfile.mkstemp(dir=env.get_user_activities_path(),
    308310                prefix=base_name, suffix='.xo')