~gary-lasker/software-center/installedview-search-fixes

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/panes/unused__installedpane.py

mergedĀ fromĀ lp:~alexeftimie/software-center/backend-refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from softwarecenter.ui.gtk3.views.appview import AppViewFilter
40
40
import softwarecenter.ui.gtk3.dialogs as dialogs
41
41
 
 
42
LOG=logging.getLogger(__name__)
 
43
 
42
44
def interrupt_build_and_wait(f):
43
45
    """ decorator that ensures that a build of the categorised installed apps
44
46
        is interrupted before a new build commences.
47
49
    def wrapper(*args, **kwargs):
48
50
        self = args[0]
49
51
        if self._build_in_progress:
50
 
            print 'Waiting for build to exit...'
 
52
            LOG.debug('Waiting for build to exit...')
51
53
            self._halt_build = True
52
54
            GObject.timeout_add(200, lambda: wrapper(*args, **kwargs))
53
55
            return False
174
176
 
175
177
    #~ @interrupt_build_and_wait
176
178
    def _build_categorised_view(self):
177
 
        print 'Rebuilding categorised installedview...'
 
179
        LOG.debug('Rebuilding categorised installedview...')
178
180
        self.cat_docid_map = {}
179
181
        enq = self.enquirer
180
182
        model = self.base_model # base model not treefilter
187
189
            # node to tree_view
188
190
            if not self._use_category(cat): continue
189
191
            query = self.get_query_for_cat(cat)
 
192
            LOG.debug("filter.instaleld_only: %s" % self.state.filter.installed_only)
190
193
            enq.set_query(query,
191
194
                          sortmode=SortMethods.BY_ALPHABET,
192
195
                          nonapps_visible=self.nonapps_visible,
278
281
                                        self.state.search_term)
279
282
 
280
283
    def get_query_for_cat(self, cat):
281
 
        #~ print self.state.channel
 
284
        LOG.debug("self.state.channel: %s" % self.state.channel)
282
285
        if self.state.channel and self.state.channel.query:
283
286
            query = xapian.Query(xapian.Query.OP_AND,
284
287
                                 cat.query,
384
387
                                    length) % { 'amount' : length, }
385
388
 
386
389
    def display_overview_page(self, page, view_state):
 
390
        LOG.debug("view_state: %s" % view_state)
387
391
        self._build_categorised_view()
388
392
 
389
393
        if self.state.search_term:
423
427
 
424
428
if __name__ == "__main__":
425
429
 
426
 
    from softwarecenter.paths import XAPIAN_BASE_PATH
427
 
    from softwarecenter.db.database import StoreDatabase
428
 
 
429
 
    #logging.basicConfig(level=logging.DEBUG)
430
 
 
431
 
    if len(sys.argv) > 1:
432
 
        datadir = sys.argv[1]
433
 
    elif os.path.exists("./data"):
434
 
        datadir = "./data"
435
 
    else:
436
 
        datadir = "/usr/share/software-center"
437
 
 
438
 
    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
439
 
    icons = get_sc_icon_theme(datadir)
440
 
 
441
 
    Gtk.Window.set_default_icon_name("softwarecenter")
442
 
 
443
 
    from softwarecenter.db.pkginfo import get_pkg_info
444
 
    cache = get_pkg_info()
445
 
    cache.open()
446
 
 
447
 
    # xapian
448
 
    xapian_base_path = XAPIAN_BASE_PATH
449
 
    pathname = os.path.join(xapian_base_path, "xapian")
450
 
    try:
451
 
        db = StoreDatabase(pathname, cache)
452
 
        db.open()
453
 
    except xapian.DatabaseOpeningError:
454
 
        # Couldn't use that folder as a database
455
 
        # This may be because we are in a bzr checkout and that
456
 
        #   folder is empty. If the folder is empty, and we can find the
457
 
        # script that does population, populate a database in it.
458
 
        if os.path.isdir(pathname) and not os.listdir(pathname):
459
 
            from softwarecenter.db.update import rebuild_database
460
 
            logging.info("building local database")
461
 
            rebuild_database(pathname)
462
 
            db = StoreDatabase(pathname, cache)
463
 
            db.open()
464
 
    except xapian.DatabaseCorruptError, e:
465
 
        logging.exception("xapian open failed")
466
 
        dialogs.error(None, 
467
 
                      _("Sorry, can not open the software database"),
468
 
                      _("Please re-install the 'software-center' "
469
 
                        "package."))
470
 
        # FIXME: force rebuild by providing a dbus service for this
471
 
        sys.exit(1)
 
430
    from softwarecenter.testutils import (get_test_db,
 
431
                                          get_test_datadir,
 
432
                                          get_test_gtk3_viewmanager,
 
433
                                          get_test_pkg_info,
 
434
                                          get_test_icon_cache,
 
435
                                          )
 
436
    # needed because available pane will try to get it
 
437
    vm = get_test_gtk3_viewmanager()
 
438
    vm # make pyflakes happy
 
439
    db = get_test_db()
 
440
    cache = get_test_pkg_info()
 
441
    datadir = get_test_datadir()
 
442
    icons = get_test_icon_cache()
472
443
 
473
444
    w = InstalledPane(cache, db, 'Ubuntu', icons, datadir)
474
445
    w.show()