def setUp(self): # create a fake database to simualte a run of software-center-agent # create a StoreDatabase and add our other db self.db = get_test_db() self.db.add_database(xapian.Database(TEST_DB)) self.db.open(use_axi=True) self.enquire = AppEnquire(self.db._aptcache, self.db)
def test_app_store(self): # get a enquire object enquirer = AppEnquire(self.cache, self.db) enquirer.set_query(xapian.Query("")) # get a AppListStore and run functions on it model = AppListStore(self.db, self.cache, self.icons) # test if set from matches works self.assertEqual(len(model), 0) model.set_from_matches(enquirer.matches) self.assertTrue(len(model) > 0) # ensure the first row has a xapian doc type self.assertEqual(type(model[0][0]), xapian.Document) # lazy loading of the docs self.assertEqual(model[100][0], None) # test the load range stuff model.load_range(indices=[100], step=15) self.assertEqual(type(model[100][0]), xapian.Document) # ensure buffer_icons works and loads stuff into the cache model.buffer_icons() self.assertEqual(len(model.icon_cache), 0) while Gtk.events_pending(): Gtk.main_iteration() self.assertTrue(len(model.icon_cache) > 0) # ensure clear works model.clear() self.assertEqual(model.current_matches, None)
def test_app_enquire(self): db = StoreDatabase(cache=self.cache) db.open() # test the AppEnquire engine enquirer = AppEnquire(self.cache, db) enquirer.set_query(xapian.Query("a"), nonblocking_load=False) self.assertTrue(len(enquirer.get_docids()) > 0)
def get_test_window(): import softwarecenter.log softwarecenter.log.root.setLevel(level=logging.DEBUG) softwarecenter.log.add_filters_from_string("performance") fmt = logging.Formatter("%(name)s - %(message)s", None) softwarecenter.log.handler.setFormatter(fmt) from softwarecenter.paths import XAPIAN_BASE_PATH xapian_base_path = XAPIAN_BASE_PATH pathname = os.path.join(xapian_base_path, "xapian") # the store from softwarecenter.db.pkginfo import get_pkg_info cache = get_pkg_info() cache.open() # the db from softwarecenter.db.database import StoreDatabase db = StoreDatabase(pathname, cache) db.open() # additional icons come from app-install-data icons = Gtk.IconTheme.get_default() icons.prepend_search_path("/usr/share/app-install/icons/") icons.prepend_search_path("/usr/share/software-center/icons/") # create a filter from softwarecenter.db.appfilter import AppFilter filter = AppFilter(db, cache) filter.set_supported_only(False) filter.set_installed_only(True) # appview from softwarecenter.ui.gtk3.models.appstore2 import AppListStore from softwarecenter.db.enquire import AppEnquire enquirer = AppEnquire(cache, db) store = AppListStore(db, cache, icons) from softwarecenter.ui.gtk3.views.appview import AppView view = AppView(db, cache, icons, show_ratings=True) view.set_model(store) entry = Gtk.Entry() entry.stamp = 0 entry.connect("changed", on_entry_changed, (view, enquirer)) entry.set_text("gtk3") scroll = Gtk.ScrolledWindow() box = Gtk.VBox() box.pack_start(entry, False, True, 0) box.pack_start(scroll, True, True, 0) win = Gtk.Window() win.connect("destroy", lambda x: Gtk.main_quit()) scroll.add(view) win.add(box) win.set_size_request(600, 400) win.show_all() return win
def __init__(self, cache, db, icons, apps_filter, apps_limit=0, root_category=None): CategoriesView.__init__(self, cache, db, icons, apps_filter, apps_limit) # state self._built = False # data self.root_category = root_category self.enquire = AppEnquire(self.cache, self.db) self.properties_helper = AppPropertiesHelper(self.db, self.cache, self.icons) # sections self.current_category = None self.departments = None self.top_rated = None self.recommended_for_you_in_cat = None self.appcount = None # widgetry self.vbox.set_margin_left(StockEms.MEDIUM - 2) self.vbox.set_margin_right(StockEms.MEDIUM - 2) self.vbox.set_margin_top(StockEms.MEDIUM) return
def get_test_enquirer_matches(db, query=None, limit=20, sortmode=0): if query is None: query = xapian.Query("") enquirer = AppEnquire(db._aptcache, db) enquirer.set_query(query, sortmode=sortmode, limit=limit, nonblocking_load=False) return enquirer.matches
def _update_appcount(self): enq = AppEnquire(self.cache, self.db) distro = get_distro() if get_global_filter().supported_only: query = distro.get_supported_query() else: query = xapian.Query('') length = enq.get_estimated_matches_count(query) text = gettext.ngettext("%(amount)s item", "%(amount)s items", length ) % {'amount': length} self.appcount.set_text(text)
def __init__(self, cache, db, distro, icons, datadir, show_ratings=True): Gtk.VBox.__init__(self) BasePane.__init__(self) # other classes we need self.enquirer = AppEnquire(cache, db) self._query_complete_handler = self.enquirer.connect( "query-complete", self.on_query_complete) self.cache = cache self.db = db self.distro = distro self.icons = icons self.datadir = datadir self.show_ratings = show_ratings self.backend = get_install_backend() self.nonapps_visible = NonAppVisibility.MAYBE_VISIBLE # refreshes can happen out-of-bound so we need to be sure # that we only set the new model (when its available) if # the refresh_seq_nr of the ready model matches that of the # request (e.g. people click on ubuntu channel, get impatient, click # on partner channel) self.refresh_seq_nr = 0 # this should be initialized self.apps_search_term = "" # Create the basic frame for the common view self.state = DisplayState() vm = get_viewmanager() self.searchentry = vm.get_global_searchentry() self.back_forward = vm.get_global_backforward() # a notebook below self.notebook = Gtk.Notebook() if not SOFTWARE_CENTER_DEBUG_TABS: self.notebook.set_show_tabs(False) self.notebook.set_show_border(False) # make a spinner view to display while the applist is loading self.spinner_notebook = SpinnerNotebook(self.notebook) self.pack_start(self.spinner_notebook, True, True, 0) # add a bar at the bottom (hidden by default) for contextual actions self.action_bar = ActionBar() self.pack_start(self.action_bar, False, True, 0) # cursor self.busy_cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH) # views to be created in init_view self.app_view = None self.app_details_view = None
def get_documents(self, db): """ return the database docids for the given category """ enq = AppEnquire(db._aptcache, db) app_filter = AppFilter(db, db._aptcache) if "available-only" in self.flags: app_filter.set_available_only(True) if "not-installed-only" in self.flags: app_filter.set_not_installed_only(True) enq.set_query(self.query, limit=self.item_limit, filter=app_filter, sortmode=self.sortmode, nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE, nonblocking_load=False) return enq.get_documents()
def get_test_window(): import softwarecenter.log softwarecenter.log.root.setLevel(level=logging.DEBUG) softwarecenter.log.add_filters_from_string("performance") fmt = logging.Formatter("%(name)s - %(message)s", None) softwarecenter.log.handler.setFormatter(fmt) from softwarecenter.testutils import (get_test_db, get_test_pkg_info, get_test_gtk3_icon_cache) from softwarecenter.ui.gtk3.models.appstore2 import AppListStore db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() # create a filter from softwarecenter.db.appfilter import AppFilter filter = AppFilter(db, cache) filter.set_supported_only(False) filter.set_installed_only(True) # appview from softwarecenter.db.enquire import AppEnquire enquirer = AppEnquire(cache, db) store = AppListStore(db, cache, icons) from softwarecenter.ui.gtk3.views.appview import AppView view = AppView(db, cache, icons, show_ratings=True) view.set_model(store) entry = Gtk.Entry() entry.stamp = 0 entry.connect("changed", on_entry_changed, (view, enquirer)) box = Gtk.VBox() box.pack_start(entry, False, True, 0) box.pack_start(view, True, True, 0) win = Gtk.Window() win.set_data("appview", view) win.set_data("entry", entry) win.connect("destroy", lambda x: Gtk.main_quit()) win.add(box) win.set_size_request(600, 400) win.show_all() return win
def _update_appcount(self): enq = AppEnquire(self.cache, self.db) distro = get_distro() if get_global_filter().supported_only: query = distro.get_supported_query() else: query = xapian.Query('') enq.set_query(query, limit=0, nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE, nonblocking_load=True) length = len(enq.matches) text = gettext.ngettext("%(amount)s item", "%(amount)s items", length) % { 'amount': length, } self.appcount.set_text(text)
def _get_toprated_category_content(self): toprated_cat = get_category_by_name(self.categories, u"Top Rated") # unstranslated name if toprated_cat is None: LOG.warn("No 'toprated' category found!!") return None, [] enq = AppEnquire(self.cache, self.db) app_filter = AppFilter(self.db, self.cache) enq.set_query(toprated_cat.query, limit=TOP_RATED_CAROUSEL_LIMIT, sortmode=toprated_cat.sortmode, filter=app_filter, nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE, nonblocking_load=False) if not hasattr(self, "helper"): self.helper = AppPropertiesHelper(self.db, self.cache, self.icons) return toprated_cat, enq.get_documents()
def test_app_enquire(self): db = get_test_db() cache = get_test_pkg_info() xfilter = AppFilter(cache, db) enquirer = AppEnquire(cache, db) terms = [ "app", "this", "the", "that", "foo", "tool", "game", "graphic", "ubuntu", "debian", "gtk", "this", "bar", "baz" ] # run a bunch of the querries in parallel for nonblocking in [False, True]: for i in range(10): for term in terms: enquirer.set_query(search_query=xapian.Query(term), limit=0, filter=xfilter, nonblocking_load=nonblocking) # give the threads a bit of time time.sleep(5)
def _get_new_category_content(self): whatsnew_cat = get_category_by_name( self.categories, u"What\u2019s New") # unstranslated name if whatsnew_cat is None: LOG.warn("No 'new' category found!!") return None, [] enq = AppEnquire(self.cache, self.db) app_filter = AppFilter(self.db, self.cache) app_filter.set_available_only(True) app_filter.set_not_installed_only(True) enq.set_query(whatsnew_cat.query, limit=8, filter=app_filter, sortmode=SortMethods.BY_CATALOGED_TIME, nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE, nonblocking_load=False) if not hasattr(self, "helper"): self.helper = AppPropertiesHelper(self.db, self.cache, self.icons) return whatsnew_cat, enq.get_documents()
def test_app_view(self): enquirer = AppEnquire(self.cache, self.db) enquirer.set_query(xapian.Query(""), sortmode=SortMethods.BY_CATALOGED_TIME, limit=10, nonblocking_load=False) # get test window win = get_test_window_appview() self.addCleanup(win.destroy) appview = win.get_data("appview") # set matches appview.clear_model() appview.display_matches(enquirer.matches) do_events() # verify that the order is actually the correct one model = appview.tree_view.get_model() docs_in_model = [item[0] for item in model] docs_from_enquirer = [m.document for m in enquirer.matches] self.assertEqual(len(docs_in_model), len(docs_from_enquirer)) for i in range(len(docs_in_model)): self.assertEqual(self.db.get_pkgname(docs_in_model[i]), self.db.get_pkgname(docs_from_enquirer[i]))