~mvo/software-center/hopefully-fix-lp1008229

« back to all changes in this revision

Viewing changes to softwarecenter/backend/channel_impl/aptchannels.py

  • Committer: Michael Vogt
  • Date: 2012-01-03 11:27:15 UTC
  • mto: This revision was merged to the branch mainline in revision 2622.
  • Revision ID: michael.vogt@ubuntu.com-20120103112715-0ju4gulzjtdea683
move channels-check/update code into a seperate script to avoid UI stall

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import logging
22
22
import xapian
23
23
 
 
24
import softwarecenter.paths
 
25
 
24
26
from gi.repository import GObject
25
27
 
26
28
from aptsources.sourceslist import SourceEntry, SourcesList
151
153
        run a background timer to see if the a-x-i data we have is 
152
154
        still fresh or if the cache has changed since
153
155
        """
154
 
        if not self.db._aptcache.ready:
155
 
            return True
156
 
        # see if we need a a-x-i update
157
 
        if self._check_for_channel_updates():
158
 
            # this will trigger a "channels-changed" signal from
159
 
            # the backend object once a-x-i is finished
160
 
            self._logger.debug("running update_xapian_index")
161
 
            self.backend.update_xapian_index()
162
 
        return False
 
156
        # this is expensive and does not need UI to we shove it out
 
157
        channel_update = os.path.join(
 
158
            softwarecenter.paths.datadir, "update-software-center-channels")
 
159
        (pid, stdin, stdout, stderr) = GObject.spawn_async(
 
160
            [channel_update],                     
 
161
            flags=GObject.SPAWN_DO_NOT_REAP_CHILD)
 
162
        GObject.child_watch_add(
 
163
            pid, self._on_check_for_channel_updates_finished)
163
164
 
164
 
    def _check_for_channel_updates(self):
165
 
        """ 
166
 
        check current set of channel origins in a-x-i and
167
 
        compare it to the apt cache to see if 
168
 
        anything has changed, 
169
 
        
170
 
        returns True is a update is needed
171
 
        """
172
 
        # the operation get_origins can take some time (~60s?)
173
 
        cache_origins = set(self.db._aptcache.get_all_origins())
174
 
        db_origins = set(self.db.get_origins_from_db())
175
 
        # origins
176
 
        self._logger.debug("cache_origins: %s" % cache_origins)
177
 
        self._logger.debug("db_origins: %s" % db_origins)
178
 
        # the db_origins will contain origins from the s-c-agent, so
179
 
        # we don't need to rebuild if the db has more origins then
180
 
        # the cache, but we need to rebuild if the cache has origins
181
 
        # that a-x-i does not have
182
 
        if not cache_origins.issubset(db_origins):
183
 
            return True
184
 
        return False
 
165
    def _on_check_for_channel_updates_finished(self, pid, condition):
 
166
        # exit status of 1 means stuff changed
 
167
        if os.WEXITSTATUS(condition) == 1:
 
168
            self.db.reopen()
185
169
    
186
170
    def _get_channels(self, installed_only=False):
187
171
        """