[Sugar-devel] [PATCH] Avoid popping an empty list in the
Michael Stone
michael at laptop.org
Wed May 26 00:27:07 EDT 2010
> On Sun, May 23, 2010 at 02:50:16PM -0400, Michael Stone wrote:
> > When you run Sugar with no activities installed,
> > UpdateModel._bundles_to_check is empty. Attempting to unconditionally
> > pop this list results in an IndexError. Instead, the updater should
> > stop trying to update bundles when it determines that it has no more
> > bundles to check.
> >
> > Signed-off-by: Michael Stone <michael at laptop.org>
>
> It will work where it is, but the check could go another two lines
> higher up, or even in check_updates.
>
> It's also odd that you're returning False and the function otherwise
> returns None. gobject.idle_add is specified as removing the function
> from the main loop when False is returned, but I've tested and it is
> doing so with a None return as well.
>
> The patch below (on top of your two patches) implements what I mean:
>
> diff --git a/main/extensions/cpsection/updater/model.py b/main/extensions/cpsection/updater/model.py
> index 5bb8cf4..9bf0330 100755
> --- a/main/extensions/cpsection/updater/model.py
> +++ b/main/extensions/cpsection/updater/model.py
> @@ -64,14 +64,13 @@ class UpdateModel(gobject.GObject):
> def check_updates(self):
> self.updates = []
> self._bundles_to_check = list(bundleregistry.get_registry())
> - self._check_next_update()
> + if len(self._bundles_to_check) > 0:
> + self._check_next_update()
>
> def _check_next_update(self):
> total = len(bundleregistry.get_registry())
> current = total - len(self._bundles_to_check)
>
> - if len(self._bundles_to_check) == 0:
> - return False
> bundle = self._bundles_to_check.pop()
> self.emit('progress', UpdateModel.ACTION_CHECKING, bundle.get_name(),
> current, total)
Good suggestion.
Michael
More information about the Sugar-devel
mailing list