Ejemplo n.º 1
0
    def __update_rich_list(self):
        """
        This is the timeout callback called to update the gui
        in the find phase
        """

        working = False

        for upd_obj in self.p_window.update_eng.list:
            upd_obj.lock.acquire()

            try:
                # Check if we are working
                if upd_obj.status == LATEST_GETTING:
                    working = True

                # Update the row
                row = upd_obj.object
                row.message = upd_obj.label
            finally:
                upd_obj.lock.release()

        # No locking from here we have finished

        if not working:
            # Mark as finished
            self.p_window.update_eng.stop()
            self.find_updates_btn.set_sensitive(True)

            lst = filter( \
                lambda x: (x.status == LATEST_GETTED) and (x) or (None),\
                self.p_window.update_eng.list \
            )
            elst = filter( \
                lambda x: (x.status == LATEST_ERROR) and (x) or (None),\
                self.p_window.update_eng.list \
            )

            if not lst and not elst:
                self.p_window.toolbar.unset_status()

                self.p_window.animated_bar.label = \
                    _('<b>No updates found</b>')
                self.p_window.animated_bar.start_animation(True)

                self.richlist.clear()
                self.populate()

                self.menu_enabled = True
            else:
                # Now prepare the download page

                if not elst:
                    self.p_window.toolbar.show_message( \
                        _("<b>Updates found: %d</b>") % len(lst), \
                        stock=gtk.STOCK_APPLY \
                    )
                else:
                    self.p_window.toolbar.show_message( \
                        _('<b>Updates found: %d with %d errors</b>')  \
                        % (len(lst), len(elst)), stock=gtk.STOCK_APPLY \
                    )

                for obj in self.p_window.update_eng.list:
                    row = obj.object
                    active = (obj.status == LATEST_GETTED)

                    if active:
                        obj.last_update_idx = 0
                        row.show_include = True

                        log.debug("Connecting 'query-tooltip' for %s" % obj)

                        # The tooltip is showed and hidden continuously
                        row.versions_button.props.has_tooltip = True
                        row.versions_button.connect(
                            'query-tooltip',
                            self.__query_tooltip_versions_button, obj)

                        row.versions_model.clear()

                        row.versions_model.append(
                            [gtk.STOCK_CANCEL, _("Skip")])

                        for update in obj.updates:
                            cur_v = Version(row.reader.version)
                            new_v = Version(update.version)

                            if new_v > cur_v:
                                row.versions_model.append([
                                    gtk.STOCK_GO_UP, _("Update to %s") % \
                                    update.version
                                ])
                            elif new_v == cur_v:
                                row.versions_model.append([
                                    gtk.STOCK_REFRESH, _("Reinstall %s") % \
                                    update.version
                                ])
                            else:
                                row.versions_model.append([
                                    gtk.STOCK_GO_DOWN, _("Downgrade to %s") % \
                                    update.version
                                ])

                        row.versions_button.set_active(0)
                        row.message = obj.label
                    else:
                        row.saturate = True

                if lst:
                    self.install_updates_btn.show()

                self.find_updates_btn.hide()
                self.skip_install_btn.show()

        return working
Ejemplo n.º 2
0
    def __process_manifest(self, file, data, exc, obj):
        """
        Callback to parse latest.xml file containing meta information about
        the avaiable update.
        """

        if isinstance(exc, ErrorNetException):
            obj.lock.acquire()

            try:
                if obj.last_update_idx + 1 < len(obj.object.reader.update):
                    obj.last_update_idx += 1

                    obj.status = LATEST_GETTING
                    obj.label = _('Cycling to next update url. Waiting...')

                    self.update_lst.append(obj)
                elif isinstance(exc, ErrorNetException):
                    obj.status = LATEST_ERROR
                    obj.label = _(
                        'Cannot find newer version (%s)') % exc.reason

                self.__process_next()
                return
            finally:
                obj.lock.release()

        elif isinstance(exc, StopNetException):
            try:
                obj.parse_latest_file()
            except Exception, exc:

                if obj.last_update_idx + 1 < len(obj.object.reader.update):
                    obj.last_update_idx += 1

                    obj.status = LATEST_GETTING
                    obj.label = _('Cycling to next update url. Waiting...')

                    self.update_lst.append(obj)
                else:
                    obj.status = LATEST_ERROR
                    obj.label = _('Cannot find newer version (%s)') % str(exc)

                self.__process_next()
                return

            version = None
            type = -1  # -1 no action / 0 update / 1 downgrade

            # If we have only 1 update..
            if len(obj.updates) == 1:
                version = obj.updates[0].version

                new_v = Version(version)
                cur_v = Version(obj.object.reader.version)

                if new_v > cur_v:
                    type = 0
                elif cur_v < new_v:
                    type = 1

            obj.lock.acquire()

            try:
                if obj.updates:

                    # We check if the path is the plugins in config_dir


                    if os.path.dirname(obj.object.reader.get_path()) != PM_PLUGINS_DIR and \
                       os.access(PM_PLUGINS_DIR, os.O_RDWR):

                        obj.status = LATEST_ERROR

                        if type == -1:
                            obj.label = _(
                                'Various versions available but require manual intervention.'
                            )
                        elif type == 0:
                            obj.label = _(
                                'Version %s available but need manual update.'
                            ) % version
                        elif type == 1:
                            obj.label = _(
                                'Version %s available but need manual downgrade.'
                            ) % version
                    else:
                        obj.status = LATEST_GETTED
                        if type == -1:
                            obj.label = _('Various versions available')
                        else:
                            obj.label = _('Version %s available.') % version

                else:
                    obj.status = LATEST_ERROR

                    if type < 0:
                        obj.label = _('Unable to parse latest.xml')
                    else:
                        obj.label = _('No applicable updates found')

                self.__process_next()
            finally:
                obj.lock.release()