[Dextrose] [PATCH sugar] More robust completed activity downloads

Anish Mangal anish at activitycentral.org
Mon Feb 14 22:07:10 EST 2011


On Sat, Feb 5, 2011 at 20:46, Aleksey Lim <alsroot at member.fsf.org> wrote:
> Previous code relies on percent==1, that might happen in two cases, one for
> regular progress event and one when completed download was detected.
> ---
>  extensions/cpsection/updater/model.py |   36 ++++++++++++++------------------
>  1 files changed, 16 insertions(+), 20 deletions(-)
>
> diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py
> index 059d112..ff2eb2c 100755
> --- a/extensions/cpsection/updater/model.py
> +++ b/extensions/cpsection/updater/model.py
> @@ -150,7 +150,7 @@ class UpdateModel(gobject.GObject):
>
>         self._downloader = _Downloader(bundle_update)
>         self._downloader.connect('progress', self.__downloader_progress_cb)
> -        self._downloader.connect('error', self.__downloader_error_cb)
> +        self._downloader.connect('finish', self.__downloader_finish_cb)
>
>     def __downloader_progress_cb(self, downloader, progress):
>         logging.debug('__downloader_progress_cb %r', progress)
> @@ -166,21 +166,20 @@ class UpdateModel(gobject.GObject):
>                   self._downloader.bundle_update.bundle.get_name(),
>                   current, total)
>
> -        if progress == 1:
> -            self._install_update(self._downloader.bundle_update,
> -                                 self._downloader.get_local_file_path())
> -            self._downloader = None
> -
> -    def __downloader_error_cb(self, downloader, error_message):
> -        logging.error('Error downloading update:\n%s', error_message)
> -
> +    def __downloader_finish_cb(self, downloader, success):
>         if self._cancelling:
>             self._cancel_updating()
>             return
>
> -        total = self._total_bundles_to_update
> -        current = total - len(self._bundles_to_update)
> -        self.emit('progress', UpdateModel.ACTION_UPDATING, '', current, total)
> +        if success:
> +            self._install_update(self._downloader.bundle_update,
> +                                 self._downloader.get_local_file_path())
> +        else:
> +            total = self._total_bundles_to_update
> +            current = total - len(self._bundles_to_update)
> +            self.emit('progress', UpdateModel.ACTION_UPDATING, '', current, total)
> +
> +        self._downloader = None
>
>         if self._bundles_to_update:
>             # do it in idle so the UI has a chance to refresh
> @@ -212,10 +211,6 @@ class UpdateModel(gobject.GObject):
>                   bundle_update.bundle.get_name(),
>                   current + 0.5, total)
>
> -        if self._bundles_to_update:
> -            # do it in idle so the UI has a chance to refresh
> -            gobject.idle_add(self._download_next_update)
> -
>     def cancel(self):
>         self._cancelling = True
>
> @@ -261,9 +256,9 @@ class _Downloader(gobject.GObject):
>         'progress': (gobject.SIGNAL_RUN_FIRST,
>                      gobject.TYPE_NONE,
>                      ([float])),
> -        'error': (gobject.SIGNAL_RUN_FIRST,
> +        'finish': (gobject.SIGNAL_RUN_FIRST,
>                   gobject.TYPE_NONE,
> -                  ([str])),
> +                  ([bool])),
>     }
>
>     def __init__(self, bundle_update):
> @@ -290,7 +285,8 @@ class _Downloader(gobject.GObject):
>         try:
>             self._input_stream = self._input_file.read_finish(result)
>         except:
> -            self.emit('error', traceback.format_exc())
> +            logging.exception('Error downloading update')
> +            self.emit('finish', False)
>             return
>
>         temp_file_path = self._get_temp_file_path(self.bundle_update.link)
> @@ -373,4 +369,4 @@ class _Downloader(gobject.GObject):
>             logging.debug('closing output stream')
>             self._output_stream.close()
>
> -            self.emit('progress', 1.0)
> +            self.emit('finish', True)
> --
> 1.7.3.4
>
>

Committed to dextrose/mainline:
http://git.sugarlabs.org/dextrose/mainline/commit/6e031895ecef7c8f2296678d23a176ab079e4149

Reviewed-by: Anish Mangal <anish at activitycentral.org>
Acked-by: Anish Mangal <anish at activitycentral.org>


More information about the Dextrose mailing list