Esempio n. 1
0
    def disabled_test_for_purchase_apps_cataloged_time(self):
        from softwarecenter.testutils import get_test_pkg_info
        #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
        os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
        # staging does not have a valid cert
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
        cache = get_test_pkg_info()
        db = xapian.WritableDatabase("./data/test.db",
                                     xapian.DB_CREATE_OR_OVERWRITE)
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
        self.assertTrue(res)
        res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
        self.assertTrue(res)
        db = StoreDatabase("./data/test.db", self.cache)
        db.open(use_axi=True)

        axi_value_time = db._axi_values["catalogedtime"]
        sc_app = Application("Ubuntu Software Center Test", "software-center")
        sc_doc = db.get_xapian_document(sc_app.appname, sc_app.pkgname)
        sc_cataloged_time = sc_doc.get_value(axi_value_time)
        for_purch_app = Application("For Purchase Test App", "hellox")
        for_purch_doc = db.get_xapian_document(for_purch_app.appname,
                                               for_purch_app.pkgname)
        for_purch_cataloged_time = for_purch_doc.get_value(axi_value_time)
        # the for-purchase test package should be cataloged at a
        # later time than axi package Ubuntu Software Center
        self.assertTrue(for_purch_cataloged_time > sc_cataloged_time)

        del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
Esempio n. 2
0
def get_test_window_catview():
    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    # gui
    win = Gtk.Window()
    n = Gtk.Notebook()

    from softwarecenter.paths import APP_INSTALL_PATH
    view = LobbyViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons, distro,
                        apps_filter)
    win.set_data("lobby", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Lobby"))

    # find a cat in the LobbyView that has subcategories
    subcat_cat = None
    for cat in reversed(view.categories):
        if cat.subcategories:
            subcat_cat = cat
            break

    view = SubCategoryViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons,
                              apps_filter)
    view.connect("category-selected", on_category_selected)
    view.set_subcategory(subcat_cat)
    win.set_data("subcat", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Subcats"))

    win.add(n)
    win.set_size_request(800, 600)
    win.show_all()
    win.connect('destroy', Gtk.main_quit)
    return win
Esempio n. 3
0
def get_test_catview():

    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    from softwarecenter.paths import APP_INSTALL_PATH
    cat_view = LobbyViewGtk(datadir, APP_INSTALL_PATH,
                        cache, db, icons, distro, apps_filter)
    return cat_view
def get_test_window_pkgnamesview():

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    pkgs = ["apt", "software-center"]
    view = PackageNamesView("header", cache, pkgs, icons, 32, db)
    view.show()

    win = Gtk.Window()
    win.add(view)
    win.set_size_request(600, 400)
    win.show()
    win.connect('destroy', Gtk.main_quit)
    return win
Esempio n. 5
0
def get_test_catview():
    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    from softwarecenter.paths import APP_INSTALL_PATH
    cat_view = LobbyViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons,
                            distro, apps_filter)
    return cat_view
Esempio n. 6
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
Esempio n. 7
0
 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)
Esempio n. 8
0
 def test_reinstall_purchased_xapian(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open(use_axi=False)
     # now create purchased debs xapian index (in memory because
     # we store the repository passwords in here)
     old_db_len = len(db)
     query = add_from_purchased_but_needs_reinstall_data(
         self.available_to_me, db, self.cache)
     # ensure we have a new item (the available for reinstall one)
     self.assertEqual(len(db), old_db_len+1)
     # query
     enquire = xapian.Enquire(db.xapiandb)
     enquire.set_query(query)
     matches = enquire.get_mset(0, len(db))
     self.assertEqual(len(matches), 1)
     for m in matches:
         doc = db.xapiandb.get_document(m.docid)
         self.assertEqual(doc.get_value(XapianValues.PKGNAME), "photobomb")
         self.assertEqual(
             doc.get_value(XapianValues.ARCHIVE_SIGNING_KEY_ID),
             "1024R/75254D99")
         self.assertEqual(doc.get_value(XapianValues.ARCHIVE_DEB_LINE),
             "deb https://username:random3atoken@"
              "private-ppa.launchpad.net/commercial-ppa-uploaders"
              "/photobomb/ubuntu natty main")
Esempio n. 9
0
 def test_package_states(self):
     db = xapian.WritableDatabase("./data/test.db", 
                                  xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
     self.assertTrue(res)
     db = StoreDatabase("./data/test.db", self.cache)
     db.open(use_axi=False)
     # test PkgStates.INSTALLED
     # FIXME: this will only work if software-center is installed
     app = Application("Ubuntu Software Center Test", "software-center")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.INSTALLED)
     # test PkgStates.UNINSTALLED
     # test PkgStates.UPGRADABLE
     # test PkgStates.REINSTALLABLE
     # test PkgStates.INSTALLING
     # test PkgStates.REMOVING
     # test PkgStates.UPGRADING
     # test PkgStates.NEEDS_SOURCE
     app = Application("Zynjacku Test", "zynjacku-fake")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_SOURCE)
     # test PkgStates.NEEDS_PURCHASE
     app = Application("The expensive gem", "expensive-gem")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_PURCHASE)
     self.assertEqual(appdetails.icon_url, "http://www.google.com/favicon.ico")
     self.assertEqual(appdetails.icon, "favicon")
     # test PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED
     # test PkgStates.UNKNOWN
     app = Application("Scintillant Orange", "scintillant-orange")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NOT_FOUND)
Esempio n. 10
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 test_packagename_is_application(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open()
     # apt has no app
     self.assertEqual(db.get_apps_for_pkgname("apt"), set())
     # but software-center has
     self.assertEqual(len(db.get_apps_for_pkgname("software-center")), 1)
Esempio n. 12
0
 def test_packagename_is_application(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open()
     # apt has no app
     self.assertEqual(db.get_apps_for_pkgname("apt"), set())
     # but software-center has
     self.assertEqual(len(db.get_apps_for_pkgname("software-center")), 1)
 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 test_package_states(self):
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db, self.cache, datadir=os.path.join(DATA_DIR, "desktop"))
     self.assertTrue(res)
     db = StoreDatabase(TEST_DB, self.cache)
     db.open(use_axi=False)
     # test PkgStates.INSTALLED
     # FIXME: this will only work if software-center is installed
     app = Application("Ubuntu Software Center Test", "software-center")
     appdetails = app.get_details(db)
     self.assertTrue(appdetails.pkg_state in (PkgStates.INSTALLED, PkgStates.UPGRADABLE))
     # test PkgStates.UNINSTALLED
     # test PkgStates.UPGRADABLE
     # test PkgStates.REINSTALLABLE
     # test PkgStates.INSTALLING
     # test PkgStates.REMOVING
     # test PkgStates.UPGRADING
     # test PkgStates.NEEDS_SOURCE
     app = Application("Zynjacku Test", "zynjacku-fake")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_SOURCE)
     # test PkgStates.NEEDS_PURCHASE
     app = Application("The expensive gem", "expensive-gem")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_PURCHASE)
     self.assertEqual(appdetails.icon_url, "http://www.google.com/favicon.ico")
     self.assertEqual(appdetails.icon, "expensive-gem-icon-favicon")
     # test PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED
     # test PkgStates.UNKNOWN
     app = Application("Scintillant Orange", "scintillant-orange")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NOT_FOUND)
     expected = ["use::converting", "role::program", "implemented-in::perl"]
     self.assertEqual(appdetails.tags, set(expected))
Esempio n. 15
0
 def test_reinstall_purchased_xapian(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open(use_axi=False)
     # now create purchased debs xapian index (in memory because
     # we store the repository passwords in here)
     old_db_len = len(db)
     query = add_from_purchased_but_needs_reinstall_data(
         self.available_to_me, db, self.cache)
     # ensure we have a new item (the available for reinstall one)
     self.assertEqual(len(db), old_db_len + 1)
     # query
     enquire = xapian.Enquire(db.xapiandb)
     enquire.set_query(query)
     matches = enquire.get_mset(0, len(db))
     self.assertEqual(len(matches), 1)
     for m in matches:
         doc = db.xapiandb.get_document(m.docid)
         self.assertEqual(doc.get_value(XapianValues.PKGNAME), "photobomb")
         self.assertEqual(
             doc.get_value(XapianValues.ARCHIVE_SIGNING_KEY_ID),
             "1024R/75254D99")
         self.assertEqual(
             doc.get_value(XapianValues.ARCHIVE_DEB_LINE),
             "deb https://username:random3atoken@"
             "private-ppa.launchpad.net/commercial-ppa-uploaders"
             "/photobomb/ubuntu precise main")
Esempio n. 16
0
def get_test_window_catview():

    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    # gui
    win = Gtk.Window()
    n = Gtk.Notebook()

    from softwarecenter.paths import APP_INSTALL_PATH
    view = LobbyViewGtk(datadir, APP_INSTALL_PATH,
                        cache, db, icons, distro, apps_filter)
    win.set_data("lobby", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Lobby"))

    # find a cat in the LobbyView that has subcategories
    subcat_cat = None
    for cat in reversed(view.categories):
        if cat.subcategories:
            subcat_cat = cat
            break

    view = SubCategoryViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons,
                              apps_filter)
    view.connect("category-selected", on_category_selected)
    view.set_subcategory(subcat_cat)
    win.set_data("subcat", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Subcats"))

    win.add(n)
    win.set_size_request(800, 800)
    win.show_all()
    win.connect('destroy', Gtk.main_quit)
    return win
Esempio n. 17
0
def get_test_db():
    from softwarecenter.db.database import StoreDatabase
    from softwarecenter.db.pkginfo import get_pkg_info
    import softwarecenter.paths
    cache = get_pkg_info()
    cache.open()
    db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
    db.open()
    return db
def get_test_db():
    from softwarecenter.db.database import StoreDatabase
    from softwarecenter.db.pkginfo import get_pkg_info
    import softwarecenter.paths
    cache = get_pkg_info()
    cache.open()
    db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
    db.open()
    return db
    def _update_package_cache(self):
        """Update the cache with fresh data from PackageKit """

        # we are not ready if the cache is invalid
        if not self._pkgs_cache:
            self._ready = False
        # we never want source packages
        pfilter = 1 << packagekit.FilterEnum.NOT_SOURCE

        pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
        db = StoreDatabase(pathname, self)
        db.open()

        docs = db.get_docs_from_query("")
        wanted_pkgs = list()
        for doc in docs:
            wanted_pkgs.append(db.get_pkgname(doc))

        if len(wanted_pkgs) is 0:
            LOG.warning("no packages to process!")
            return

        # we never want source packages
        pfilter = 1 << packagekit.FilterEnum.NOT_SOURCE

        # Start async update of package-cache, as the data which was
        # loaded before (from on-disk cache) might not be fully up-to-date
        pkDaemonConf = glib.KeyFile()
        ret = pkDaemonConf.load_from_file("/etc/PackageKit/PackageKit.conf", glib.KeyFileFlags.NONE)
        # set maxItems to 100 by default
        maxItems = 100
        if ret:
            try:
                maxItems = pkDaemonConf.get_integer("Daemon", "MaximumItemsToResolve")
            except Exception as e:
                LOG.error("Unable to read PackageKit daemon config: %s", str(e))
                maxItems = 100

        LOG.debug("maximum packages to resolve %i", maxItems)

        helper = self.PkResolveHelper(0)
        #steps = len(wanted_pkgs) + 0.5 // 100
        for i in xrange(0, len(wanted_pkgs), maxItems):
            helper.steps = helper.steps + 1

        for i in xrange(0, len(wanted_pkgs), maxItems):
            res = self.pkclient.resolve_async(pfilter,
                                              wanted_pkgs[i:i+maxItems],
                                              None, # cancellable
                                              lambda prog, t, u: None, # progress callback
                                              None, # progress user data,
                                              self._on_packages_resolve_ready,
                                              helper
            )
Esempio n. 20
0
 def test_most_popular_applications_for_mimetype(self):
     pathname = "../data/xapian"
     if not os.listdir(pathname):
         rebuild_database(pathname)
     db = StoreDatabase(pathname, self.cache)
     db.open()
     # all
     result = db.get_most_popular_applications_for_mimetype("text/html", only_uninstalled=False, num=5)
     self.assertEqual(len(result), 5)
     # only_uninstaleld
     result = db.get_most_popular_applications_for_mimetype("text/html", only_uninstalled=True, num=2)
     self.assertEqual(len(result), 2)
Esempio n. 21
0
 def __init__(self, parent=None):
     super(CategoriesModel, self).__init__()
     self._categories = []
     roles = dict(enumerate(CategoriesModel.COLUMNS))
     self.setRoleNames(roles)
     pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
     # FIXME: move this into app
     cache = get_pkg_info()
     db = StoreDatabase(pathname, cache)
     db.open()
     # /FIXME
     self.catparser = CategoriesParser(db)
     self._categories = self.catparser.parse_applications_menu()
Esempio n. 22
0
 def __init__(self, parent=None):
     super(CategoriesModel, self).__init__()
     self._categories = []
     roles = dict(enumerate(CategoriesModel.COLUMNS))
     self.setRoleNames(roles)
     pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
     # FIXME: move this into app
     cache = get_pkg_info()
     db = StoreDatabase(pathname, cache)
     db.open()
     # /FIXME
     self.catparser = CategoriesParser(db)
     self._categories = self.catparser.parse_applications_menu()
Esempio n. 23
0
 def test_most_popular_applications_for_mimetype(self):
     pathname = os.path.join(REAL_DATA_DIR, "xapian")
     if not os.listdir(pathname):
         rebuild_database(pathname)
     db = StoreDatabase(pathname, self.cache)
     db.open()
     # all
     result = db.get_most_popular_applications_for_mimetype("text/html",
         only_uninstalled=False, num=5)
     self.assertEqual(len(result), 5)
     # only_uninstaleld
     result = db.get_most_popular_applications_for_mimetype("text/html",
         only_uninstalled=True, num=2)
     self.assertEqual(len(result), 2)
 def test_whats_new(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open()
     query = xapian.Query("")
     enquire = xapian.Enquire(db.xapiandb)
     enquire.set_query(query)
     value_time = db._axi_values["catalogedtime"]
     enquire.set_sort_by_value(value_time, reverse=True)
     matches = enquire.get_mset(0, 20)
     last_time = 0
     for m in matches:
         doc = m.document
         doc.get_value(value_time) >= last_time
         last_time = doc.get_value(value_time)
Esempio n. 25
0
 def test_whats_new(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open()
     query = xapian.Query("")
     enquire = xapian.Enquire(db.xapiandb)
     enquire.set_query(query)
     value_time = db._axi_values["catalogedtime"]
     enquire.set_sort_by_value(value_time, reverse=True)
     matches = enquire.get_mset(0, 20)
     last_time = 0
     for m in matches:
         doc = m.document
         doc.get_value(value_time) >= last_time
         last_time = doc.get_value(value_time)
Esempio n. 26
0
 def _get_apps_for_category(self, category):
     query = get_query_for_category(self.db, category)
     if not query:
         LOG.warn("_get_apps_for_category: received invalid category")
         return []
     
     pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
     db = StoreDatabase(pathname, self.cache)
     db.open()
     docs = db.get_docs_from_query(query)
     
     #from the db docs, return a list of pkgnames
     applist = []
     for doc in docs:
         applist.append(db.get_pkgname(doc))
     return applist
    def _get_apps_for_category(self, category):
        query = get_query_for_category(self.db, category)
        if not query:
            LOG.warn("_get_apps_for_category: received invalid category")
            return []

        pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
        db = StoreDatabase(pathname, self.cache)
        db.open()
        docs = db.get_docs_from_query(query)

        #from the db docs, return a list of pkgnames
        applist = []
        for doc in docs:
            applist.append(db.get_pkgname(doc))
        return applist
Esempio n. 28
0
    def test_non_axi_apps_cataloged_time(self):
        db = xapian.WritableDatabase("./data/test.db", 
                                     xapian.DB_CREATE_OR_OVERWRITE)
        res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
        self.assertTrue(res)
        db = StoreDatabase("./data/test.db", self.cache)
        db.open(use_axi=True)

        axi_value_time = db._axi_values["catalogedtime"]
        sc_app = Application("Ubuntu Software Center Test", "software-center")
        sc_doc = db.get_xapian_document(sc_app.appname, sc_app.pkgname)
        sc_cataloged_time = sc_doc.get_value(axi_value_time)
        so_app = Application("Scintillant Orange", "scintillant-orange")
        so_doc = db.get_xapian_document(so_app.appname, so_app.pkgname)
        so_cataloged_time = so_doc.get_value(axi_value_time)
        # the test package Scintillant Orange should be cataloged at a
        # later time than axi package Ubuntu Software Center
        self.assertTrue(so_cataloged_time > sc_cataloged_time)
 def test_reinstall_purchased_xapian(self):
     db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
     db.open(use_axi=False)
     # now create purchased debs xapian index (in memory because
     # we store the repository passwords in here)
     old_db_len = len(db)
     query = add_from_purchased_but_needs_reinstall_data(
         self.available_to_me, db, self.cache)
     # ensure we have a new item (the available for reinstall one)
     self.assertEqual(len(db), old_db_len+1)
     # query
     enquire = xapian.Enquire(db.xapiandb)
     enquire.set_query(query)
     matches = enquire.get_mset(0, len(db))
     self.assertEqual(len(matches), 1)
     for m in matches:
         doc = db.xapiandb.get_document(m.docid)
         self.assertEqual(doc.get_value(XapianValues.PKGNAME), "hellox")
         self.assertEqual(doc.get_value(XapianValues.ARCHIVE_SIGNING_KEY_ID), "1024R/0EB12F05")
         self.assertEqual(doc.get_value(XapianValues.ARCHIVE_DEB_LINE),
                                        "deb https://username:[email protected]/mvo/private-test/ubuntu maverick main #Personal access of username to private-test")
         break # only one match
 def test_package_states(self):
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db,
                                        self.cache,
                                        datadir=os.path.join(
                                            DATA_DIR, "desktop"))
     self.assertTrue(res)
     db = StoreDatabase(TEST_DB, self.cache)
     db.open(use_axi=False)
     # test PkgStates.INSTALLED
     # FIXME: this will only work if software-center is installed
     app = Application("Ubuntu Software Center Test", "software-center")
     appdetails = app.get_details(db)
     self.assertTrue(appdetails.pkg_state in (PkgStates.INSTALLED,
                                              PkgStates.UPGRADABLE))
     # test PkgStates.UNINSTALLED
     # test PkgStates.UPGRADABLE
     # test PkgStates.REINSTALLABLE
     # test PkgStates.INSTALLING
     # test PkgStates.REMOVING
     # test PkgStates.UPGRADING
     # test PkgStates.NEEDS_SOURCE
     app = Application("Zynjacku Test", "zynjacku-fake")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_SOURCE)
     # test PkgStates.NEEDS_PURCHASE
     app = Application("The expensive gem", "expensive-gem")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NEEDS_PURCHASE)
     self.assertEqual(appdetails.icon_url,
                      "http://www.google.com/favicon.ico")
     self.assertEqual(appdetails.icon, "expensive-gem-icon-favicon")
     # test PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED
     # test PkgStates.UNKNOWN
     app = Application("Scintillant Orange", "scintillant-orange")
     appdetails = app.get_details(db)
     self.assertEqual(appdetails.pkg_state, PkgStates.NOT_FOUND)
     expected = ['use::converting', 'role::program', 'implemented-in::perl']
     self.assertEqual(appdetails.tags, set(expected))
Esempio n. 31
0
class TestCatParsing(unittest.TestCase):
    """ tests the "where is it in the menu" code """

    def setUp(self):
        cache = get_pkg_info()
        cache.open()
        xapian_base_path = XAPIAN_BASE_PATH
        pathname = os.path.join(xapian_base_path, "xapian")
        self.db = StoreDatabase(pathname, cache)
        self.db.open()
        self.catview = CategoriesParser(self.db)
        self.catview.db = self.db
        self.cats = self.catview.parse_applications_menu('/usr/share/app-install')

    def test_get_cat_by_name(self):
        cat = get_category_by_name(self.cats, 'Games')
        self.assertEqual(cat.untranslated_name, 'Games')
        cat = get_category_by_name(self.cats, 'Featured')
        self.assertEqual(cat.untranslated_name, 'Featured')

    def test_cat_has_flags(self):
        cat = get_category_by_name(self.cats, 'Featured')
        self.assertEqual(cat.flags[0], 'carousel-only')
 def test_is_pkgname_known(self):
     db = StoreDatabase(cache=self.cache)
     db.open()
     self.assertTrue(db.is_pkgname_known("apt"))
     self.assertFalse(db.is_pkgname_known("i+am-not-a-pkg"))
 def test_application_details(self):
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db, self.cache, datadir=os.path.join(DATA_DIR, "desktop"))
     self.assertTrue(res)
     db = StoreDatabase(TEST_DB, self.cache)
     db.open(use_axi=False, use_agent=False)
     self.assertEqual(len(db), 6)
     # test details
     app = Application("Ubuntu Software Center Test", "software-center")
     details = app.get_details(db)
     self.assertNotEqual(details, None)
     # mvo: disabled, we can reenable this once there is a static
     #      apt rootdir and we do not rely on the test system to
     #      have software-center from the main archive and not from
     #      e.g. a custom repo like the ADT environment
     # self.assertEqual(details.component, "main")
     self.assertEqual(details.pkgname, "software-center")
     # get the first document
     for doc in db:
         if doc.get_data() == "Ubuntu Software Center Test":
             appdetails = AppDetails(db, doc=doc)
             break
     # test get_appname and get_pkgname
     self.assertEqual(db.get_appname(doc), "Ubuntu Software Center Test")
     self.assertEqual(db.get_pkgname(doc), "software-center")
     # test appdetails
     self.assertEqual(appdetails.name, "Ubuntu Software Center Test")
     self.assertEqual(appdetails.pkgname, "software-center")
     # FIXME: add a dekstop file with a real channel to test
     #        and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH
     self.assertEqual(appdetails.channelname, None)
     self.assertEqual(appdetails.channelfile, None)
     self.assertNotEqual(appdetails.pkg, None)
     # from the fake test/data/appdetails/var/lib/dpkg/status
     self.assertEqual(appdetails.pkg.is_installed, True)
     self.assertTrue(appdetails.pkg_state in (PkgStates.INSTALLED, PkgStates.UPGRADABLE))
     # FIXME: test description for unavailable pkg
     self.assertTrue(appdetails.description.startswith("Ubuntu Software Center lets you"))
     # FIXME: test appdetails.website
     self.assertEqual(appdetails.icon, "softwarecenter")
     # crude, crude
     self.assertTrue(len(appdetails.version) > 2)
     # FIXME: screenshots will only work on ubuntu
     self.assertTrue(
         re.match(
             "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+", appdetails.screenshot
         )
     )
     self.assertTrue(
         re.match(
             "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+", appdetails.thumbnail
         )
     )
     # FIXME: add document that has a price
     self.assertEqual(appdetails.price, "Free")
     self.assertEqual(appdetails.raw_price, "")
     # mvo: disabled, we can reenable this once there is a static
     #      apt rootdir and we do not rely on the test system to
     #      have software-center from the main archive and not from
     #      e.g. a custom repo like the ADT environment
     # self.assertEqual(appdetails.license, "Open source")
     # test lazy history loading for installation date
     self.ensure_installation_date_and_lazy_history_loading(appdetails)
     # test apturl replacements
     # $kernel
     app = Application("", "linux-headers-$kernel", "channel=$distro-partner")
     self.assertEqual(app.pkgname, "linux-headers-" + os.uname()[2])
     # $distro
     details = app.get_details(db)
     distro = softwarecenter.distro.get_distro().get_codename()
     self.assertEqual(app.request, "channel=" + distro + "-partner")
class PkgListModel(QAbstractListModel):

    COLUMNS = ('_appname', '_pkgname', '_icon', '_summary', '_installed',
               '_description', '_ratings_total', '_ratings_average',
               '_installremoveprogress')

    def __init__(self, parent=None):
        super(PkgListModel, self).__init__()
        self._docs = []
        roles = dict(enumerate(PkgListModel.COLUMNS))
        self.setRoleNames(roles)
        self._query = ""
        self._category = ""
        pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
        self.cache = get_pkg_info()
        self.db = StoreDatabase(pathname, self.cache)
        self.db.open(use_axi=False)
        self.backend = get_install_backend()
        self.backend.connect("transaction-progress-changed",
                             self._on_backend_transaction_progress_changed)
        self.reviews = get_review_loader(self.cache)
        # FIXME: get this from a parent
        self._catparser = CategoriesParser(self.db)
        self._categories = self._catparser.parse_applications_menu(
            '/usr/share/app-install')

    # QAbstractListModel code
    def rowCount(self, parent=QModelIndex()):
        return len(self._docs)

    def data(self, index, role):
        if not index.isValid():
            return None
        doc = self._docs[index.row()]
        role = self.COLUMNS[role]
        pkgname = unicode(self.db.get_pkgname(doc), "utf8", "ignore")
        appname = unicode(self.db.get_appname(doc), "utf8", "ignore")
        if role == "_pkgname":
            return pkgname
        elif role == "_appname":
            return appname
        elif role == "_summary":
            return unicode(self.db.get_summary(doc))
        elif role == "_installed":
            if not pkgname in self.cache:
                return False
            return self.cache[pkgname].is_installed
        elif role == "_description":
            if not pkgname in self.cache:
                return ""
            return self.cache[pkgname].description
        elif role == "_icon":
            iconname = self.db.get_iconname(doc)
            return self._findIcon(iconname)
        elif role == "_ratings_average":
            stats = self.reviews.get_review_stats(Application(
                appname, pkgname))
            if stats:
                return stats.ratings_average
            return 0
        elif role == "_ratings_total":
            stats = self.reviews.get_review_stats(Application(
                appname, pkgname))
            if stats:
                return stats.ratings_total
            return 0
        elif role == "_installremoveprogress":
            if pkgname in self.backend.pending_transactions:
                return self.backend.pending_transactions[pkgname].progress
            return -1
        return None

    # helper
    def _on_backend_transaction_progress_changed(self, backend, pkgname,
                                                 progress):
        column = self.COLUMNS.index("_installremoveprogress")
        # FIXME: instead of the entire model, just find the row that changed
        top = self.createIndex(0, column)
        bottom = self.createIndex(self.rowCount() - 1, column)
        self.dataChanged.emit(top, bottom)

    def _findIcon(self, iconname):
        path = "/usr/share/icons/Humanity/categories/32/applications-other.svg"
        for ext in ["svg", "png", ".xpm"]:
            p = "/usr/share/app-install/icons/%s" % iconname
            if os.path.exists(p + ext):
                path = "file://%s" % p + ext
                break
        return path

    def clear(self):
        if self._docs == []:
            return
        self.beginRemoveRows(QModelIndex(), 0, self.rowCount() - 1)
        self._docs = []
        self.endRemoveRows()

    def _runQuery(self, querystr):
        self.clear()
        docs = self.db.get_docs_from_query(str(querystr),
                                           start=0,
                                           end=500,
                                           category=self._category)
        self.beginInsertRows(QModelIndex(), 0, len(docs) - 1)
        self._docs = docs
        self.endInsertRows()

    # install/remove interface (for qml)
    @pyqtSlot(str)
    def installPackage(self, pkgname):
        appname = ""
        iconname = ""
        app = Application(appname, pkgname)
        self.backend.install(app, iconname)

    @pyqtSlot(str)
    def removePackage(self, pkgname):
        appname = ""
        iconname = ""
        app = Application(appname, pkgname)
        self.backend.remove(app, iconname)

    # searchQuery property (for qml )
    def getSearchQuery(self):
        return self._query

    def setSearchQuery(self, query):
        self._query = query
        self._runQuery(query)

    searchQueryChanged = QtCore.pyqtSignal()
    searchQuery = QtCore.pyqtProperty(unicode,
                                      getSearchQuery,
                                      setSearchQuery,
                                      notify=searchQueryChanged)

    # allow to refine searches for specific categories
    @pyqtSlot(str)
    def setCategory(self, catname):
        # empty category resets it
        if not catname:
            self._category = None
        else:
            # search for the category
            for cat in self._categories:
                if cat.name == catname:
                    self._category = cat
                    break
            else:
                raise Exception("Can not find category '%s'" % catname)
        # and trigger a query
        self._runQuery(self._query)
 def test_application_details(self):
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db,
                                        self.cache,
                                        datadir=os.path.join(
                                            DATA_DIR, "desktop"))
     self.assertTrue(res)
     db = StoreDatabase(TEST_DB, self.cache)
     db.open(use_axi=False, use_agent=False)
     self.assertEqual(len(db), 6)
     # test details
     app = Application("Ubuntu Software Center Test", "software-center")
     details = app.get_details(db)
     self.assertNotEqual(details, None)
     # mvo: disabled, we can reenable this once there is a static
     #      apt rootdir and we do not rely on the test system to
     #      have software-center from the main archive and not from
     #      e.g. a custom repo like the ADT environment
     #self.assertEqual(details.component, "main")
     self.assertEqual(details.pkgname, "software-center")
     # get the first document
     for doc in db:
         if doc.get_data() == "Ubuntu Software Center Test":
             appdetails = AppDetails(db, doc=doc)
             break
     # test get_appname and get_pkgname
     self.assertEqual(db.get_appname(doc), "Ubuntu Software Center Test")
     self.assertEqual(db.get_pkgname(doc), "software-center")
     # test appdetails
     self.assertEqual(appdetails.name, "Ubuntu Software Center Test")
     self.assertEqual(appdetails.pkgname, "software-center")
     # FIXME: add a dekstop file with a real channel to test
     #        and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH
     self.assertEqual(appdetails.channelname, None)
     self.assertEqual(appdetails.channelfile, None)
     self.assertNotEqual(appdetails.pkg, None)
     # from the fake test/data/appdetails/var/lib/dpkg/status
     self.assertEqual(appdetails.pkg.is_installed, True)
     self.assertTrue(appdetails.pkg_state in (PkgStates.INSTALLED,
                                              PkgStates.UPGRADABLE))
     # FIXME: test description for unavailable pkg
     self.assertTrue(
         appdetails.description.startswith(
             "Ubuntu Software Center lets you"))
     # FIXME: test appdetails.website
     self.assertEqual(appdetails.icon, "softwarecenter")
     # crude, crude
     self.assertTrue(len(appdetails.version) > 2)
     # FIXME: screenshots will only work on ubuntu
     self.assertTrue(
         re.match(
             "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+",
             appdetails.screenshot))
     self.assertTrue(
         re.match(
             "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",
             appdetails.thumbnail))
     # FIXME: add document that has a price
     self.assertEqual(appdetails.price, "Free")
     self.assertEqual(appdetails.raw_price, "")
     # mvo: disabled, we can reenable this once there is a static
     #      apt rootdir and we do not rely on the test system to
     #      have software-center from the main archive and not from
     #      e.g. a custom repo like the ADT environment
     #self.assertEqual(appdetails.license, "Open source")
     # test lazy history loading for installation date
     self.ensure_installation_date_and_lazy_history_loading(appdetails)
     # test apturl replacements
     # $kernel
     app = Application("", "linux-headers-$kernel",
                       "channel=$distro-partner")
     self.assertEqual(app.pkgname, 'linux-headers-' + os.uname()[2])
     # $distro
     details = app.get_details(db)
     distro = softwarecenter.distro.get_distro().get_codename()
     self.assertEqual(app.request, 'channel=' + distro + '-partner')
Esempio n. 36
0
    Gtk.Window.set_default_icon_name("softwarecenter")

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    # xapian
    import xapian
    from softwarecenter.paths import XAPIAN_BASE_PATH
    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = XAPIAN_BASE_PATH
    pathname = os.path.join(xapian_base_path, "xapian")
    try:
        db = StoreDatabase(pathname, cache)
        db.open()
    except xapian.DatabaseOpeningError:
        # Couldn't use that folder as a database
        # This may be because we are in a bzr checkout and that
        #   folder is empty. If the folder is empty, and we can find the
        # script that does population, populate a database in it.
        if os.path.isdir(pathname) and not os.listdir(pathname):
            from softwarecenter.db.update import rebuild_database
            logging.info("building local database")
            rebuild_database(pathname)
            db = StoreDatabase(pathname, cache)
            db.open()
    except xapian.DatabaseCorruptError as e:
        logging.exception("xapian open failed")
        dialogs.error(None, _("Sorry, can not open the software database"),
                      _("Please re-install the 'software-center' "
Esempio n. 37
0
 def test_is_pkgname_known(self):
     db = StoreDatabase(cache=self.cache)
     db.open()
     self.assertTrue(db.is_pkgname_known("apt"))
     self.assertFalse(db.is_pkgname_known("i+am-not-a-pkg"))
Esempio n. 38
0
if __name__ == "__main__":
    def callback(app, reviews):
        print "app callback:"
        print app, reviews
    def stats_callback(stats):
        print "stats callback:"
        print stats

    # cache
    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    db = StoreDatabase(XAPIAN_BASE_PATH+"/xapian", cache)
    db.open()

    # rnrclient loader
    app = Application("ACE", "unace")
    #app = Application("", "2vcard")

    from softwarecenter.backend.reviews.rnr import ReviewLoaderSpawningRNRClient
    loader = ReviewLoaderSpawningRNRClient(cache, db)
    print loader.refresh_review_stats(stats_callback)
    print loader.get_reviews(app, callback)

    print "\n\n"
    print "default loader, press ctrl-c for next loader"
    context = GObject.main_context_default()
    main = GObject.MainLoop(context)
    main.run()
Esempio n. 39
0
def get_test_db():
    cache = get_pkg_info()
    cache.open()
    db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
    db.open()
    return db
Esempio n. 40
0
 def test_application_details(self):
     db = xapian.WritableDatabase("./data/test.db", 
                                  xapian.DB_CREATE_OR_OVERWRITE)
     res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
     self.assertTrue(res)
     db = StoreDatabase("./data/test.db", self.cache)
     db.open(use_axi=False, use_agent=False)
     self.assertEqual(len(db), 5)
     # test details
     app = Application("Ubuntu Software Center Test", "software-center")
     details = app.get_details(db)
     self.assertNotEqual(details, None)
     self.assertEqual(details.component, "main")
     self.assertEqual(details.pkgname, "software-center")
     # get the first document
     for doc in db:
         if doc.get_data() == "Ubuntu Software Center Test":
             appdetails = AppDetails(db, doc=doc)
             break
     # test get_appname and get_pkgname
     self.assertEqual(db.get_appname(doc), "Ubuntu Software Center Test")
     self.assertEqual(db.get_pkgname(doc), "software-center")
     # test appdetails
     self.assertEqual(appdetails.name, "Ubuntu Software Center Test")
     self.assertEqual(appdetails.pkgname, "software-center")
     # FIXME: add a dekstop file with a real channel to test
     #        and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH
     self.assertEqual(appdetails.channelname, None)
     self.assertEqual(appdetails.channelfile, None)
     self.assertEqual(appdetails.component, "main")
     self.assertNotEqual(appdetails.pkg, None)
     # from the fake test/data/appdetails/var/lib/dpkg/status
     self.assertEqual(appdetails.pkg.is_installed, True)
     self.assertEqual(appdetails.pkg_state, PkgStates.INSTALLED)
     # FIXME: test description for unavailable pkg
     self.assertTrue(
         appdetails.description.startswith("Ubuntu Software Center lets you"))
     # FIXME: test appdetails.website
     self.assertEqual(appdetails.icon, "softwarecenter")
     # crude, crude
     self.assertTrue(len(appdetails.version) > 2)
     # FIXME: screenshots will only work on ubuntu
     self.assertTrue(re.match(
             "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+", 
             appdetails.screenshot))
     self.assertTrue(re.match(
             "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",
             appdetails.thumbnail))
     # FIXME: add document that has a price
     self.assertEqual(appdetails.price, '')
     self.assertEqual(appdetails.license, "Open source")
     # test lazy history loading for installation date
     self.ensure_installation_date_and_lazy_history_loading(appdetails)
     # test apturl replacements
     # $kernel
     app = Application("", "linux-headers-$kernel", "channel=$distro-partner")
     self.assertEqual(app.pkgname, 'linux-headers-'+os.uname()[2])
     # $distro
     details = app.get_details(db)
     from softwarecenter.distro import get_distro
     distro = get_distro().get_codename()
     self.assertEqual(app.request, 'channel=' + distro + '-partner')
Esempio n. 41
0
class TestWhereIsit(unittest.TestCase):
    """ tests the "where is it in the menu" code """

    def setUp(self):
        cache = get_pkg_info()
        cache.open()
        xapian_base_path = XAPIAN_BASE_PATH
        pathname = os.path.join(xapian_base_path, "xapian")
        self.db = StoreDatabase(pathname, cache)
        self.db.open()

    # mvo: disabled for now (2011-06-06) because the new gnome-panel
    #      does not have "System" anymore and its not clear to me yet
    #      where those items will appear. Once that is settled it
    #      should be re-enabled
    def disabled_for_now_test_where_is_it_in_system(self):
        app = Application("Hardware Drivers", "jockey-gtk")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file,
                         "/usr/share/app-install/desktop/jockey-gtk.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file)
        self.assertEqual(found[0].get_name(), "Desktop")
        self.assertEqual(found[0].get_icon(), "preferences-other")
        self.assertEqual(found[1].get_name(), "Administration")
        self.assertEqual(found[1].get_icon(), "preferences-system")

    def test_where_is_it_in_applications(self):
        app = Application("Calculator", "gcalctool")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file,
                         "/usr/share/app-install/desktop/gcalctool:gcalctool.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(
            details.desktop_file,
            [os.path.join(DATA_DIR, "fake-applications.menu")])
        self.assertEqual(found[0].get_name(), "Applications")
        self.assertEqual(found[0].get_icon().get_names()[0],
                         "applications-other")
        self.assertEqual(found[1].get_name(), "Accessories")
        self.assertEqual(found[1].get_icon().get_names()[0],
                         "applications-utilities")

    def test_where_is_it_kde4(self):
        app = Application("", "ark")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file,
                         "/usr/share/app-install/desktop/ark:kde4__ark.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(
            details.desktop_file,
            [os.path.join(DATA_DIR, "fake-applications.menu")])
        self.assertEqual(found[0].get_name(), "Applications")
        self.assertEqual(found[0].get_icon().get_names()[0],
                         "applications-other")
        self.assertEqual(found[1].get_name(), "Accessories")
        self.assertEqual(found[1].get_icon().get_names()[0],
                         "applications-utilities")

    def test_where_is_it_real_system(self):
        app = Application("", "gedit")
        details = app.get_details(self.db)
        if details.pkg_state != PkgStates.INSTALLED:
            logging.warn("gedit not installed, skipping real menu test")
            self.skipTest("gedit not installed")
            return
        self.assertEqual(details.desktop_file,
                         "/usr/share/app-install/desktop/gedit:gedit.desktop")
        # search the *real* menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file)
        self.assertNotEqual(found, None)
Esempio n. 42
0
class PkgListModel(QAbstractListModel):

    COLUMNS = ('_appname',
               '_pkgname',
               '_icon',
               '_summary',
               '_installed',
               '_description',
               '_ratings_total',
               '_ratings_average',
               '_installremoveprogress')
 
    def __init__(self, parent=None):
        super(PkgListModel, self).__init__()
        self._docs = []
        roles = dict(enumerate(PkgListModel.COLUMNS))
        self.setRoleNames(roles)
        self._query = ""
        self._category = ""
        pathname = os.path.join(XAPIAN_BASE_PATH, "xapian")
        self.cache = get_pkg_info()
        self.db = StoreDatabase(pathname, self.cache)
        self.db.open(use_axi=False)
        self.backend = get_install_backend()
        self.backend.connect("transaction-progress-changed", 
                             self._on_backend_transaction_progress_changed)
        self.reviews = get_review_loader(self.cache)
        # FIXME: get this from a parent
        self._catparser = CategoriesParser(self.db)
        self._categories = self._catparser.parse_applications_menu(
            '/usr/share/app-install')

    # QAbstractListModel code
    def rowCount(self, parent=QModelIndex()):
        return len(self._docs)

    def data(self, index, role):
        if not index.isValid():
            return None
        doc = self._docs[index.row()]
        role = self.COLUMNS[role]
        pkgname = unicode(self.db.get_pkgname(doc))
        appname =  unicode(self.db.get_appname(doc))
        if role == "_pkgname":
            return pkgname 
        elif role == "_appname":
            return appname
        elif role == "_summary":
            return unicode(self.db.get_summary(doc))
        elif role == "_installed":
            if not pkgname in self.cache:
                return False
            return self.cache[pkgname].is_installed
        elif role == "_description":
            if not pkgname in self.cache:
                return ""
            return self.cache[pkgname].description
        elif role == "_icon":
            iconname = self.db.get_iconname(doc)
            return self._findIcon(iconname)
        elif role == "_ratings_average":
            stats = self.reviews.get_review_stats(Application(appname, pkgname))
            if stats:
                return stats.ratings_average
            return 0
        elif role == "_ratings_total":
            stats = self.reviews.get_review_stats(Application(appname, pkgname))
            if stats:
                return stats.ratings_total
            return 0
        elif role == "_installremoveprogress":
            if pkgname in self.backend.pending_transactions:
                return self.backend.pending_transactions[pkgname].progress
            return -1
        return None

    # helper
    def _on_backend_transaction_progress_changed(self, backend, pkgname, progress):
        column = self.COLUMNS.index("_installremoveprogress")
        # FIXME: instead of the entire model, just find the row that changed
        top = self.createIndex(0, column)
        bottom = self.createIndex(self.rowCount()-1, column)
        self.dataChanged.emit(top, bottom)

    def _findIcon(self, iconname):
        path = "/usr/share/icons/Humanity/categories/32/applications-other.svg"
        for ext in ["svg", "png", ".xpm"]:
            p = "/usr/share/app-install/icons/%s" % iconname
            if os.path.exists(p+ext):
                path = "file://%s" % p+ext
                break
        return path
        
    def clear(self):
        self.beginRemoveRows(QModelIndex(), 0, self.rowCount()-1)
        self._docs = []
        self.endRemoveRows()

    def _runQuery(self, querystr):
        self.clear()
        docs = self.db.get_docs_from_query(
            str(querystr), start=0, end=500, category=self._category)
        self.beginInsertRows(QModelIndex(), len(docs), len(docs))
        self._docs = docs
        self.endInsertRows()

    # install/remove interface (for qml)
    @Slot(str)
    def installPackage(self, pkgname):
        appname = ""
        iconname = ""
        self.backend.install(pkgname, appname, iconname)
    @Slot(str)
    def removePackage(self, pkgname):
        appname = ""
        iconname = ""
        self.backend.remove(pkgname, appname, iconname)

    # searchQuery property (for qml )
    def getSearchQuery(self):
        return self._query
    def setSearchQuery(self, query):
        self._query = query
        self._runQuery(query)
    searchQueryChanged = QtCore.Signal()
    searchQuery = Property(unicode, getSearchQuery, setSearchQuery, notify=searchQueryChanged)

    # allow to refine searches for specific categories
    @Slot(str)
    def setCategory(self, catname):
        # empty category resets it
        if not catname:
            self._category = None
        else:
            # search for the category
            for cat in self._categories:
                if cat.name == catname:
                    self._category = cat
                    break
            else:
                raise Exception("Can not find category '%s'" % catname)
        # and trigger a query
        self._runQuery(self._query)
Esempio n. 43
0
def get_test_db():
    cache = get_pkg_info()
    cache.open()
    db = StoreDatabase(softwarecenter.paths.XAPIAN_PATH, cache)
    db.open()
    return db
class TestWhereIsit(unittest.TestCase):
    """ tests the "where is it in the menu" code """

    def setUp(self):
        cache = get_pkg_info()
        cache.open()
        xapian_base_path = XAPIAN_BASE_PATH
        pathname = os.path.join(xapian_base_path, "xapian")
        self.db = StoreDatabase(pathname, cache)
        self.db.open()

    # mvo: disabled for now (2011-06-06) because the new gnome-panel
    #      does not have "System" anymore and its not clear to me yet
    #      where those items will appear. Once that is settled it
    #      should be re-enabled
    def disabled_for_now_test_where_is_it_in_system(self):
        app = Application("Hardware Drivers", "jockey-gtk")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file, "/usr/share/app-install/desktop/jockey-gtk.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file)
        self.assertEqual(found[0].get_name(), "Desktop")
        self.assertEqual(found[0].get_icon(), "preferences-other")
        self.assertEqual(found[1].get_name(), "Administration")
        self.assertEqual(found[1].get_icon(), "preferences-system")

    def test_where_is_it_in_applications(self):
        app = Application("Calculator", "gcalctool")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file, "/usr/share/app-install/desktop/gcalctool:gcalctool.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file, [os.path.abspath("./data/fake-applications.menu")])
        self.assertEqual(found[0].get_name(), "Applications")
        self.assertEqual(found[0].get_icon().get_names()[0], "applications-other")
        self.assertEqual(found[1].get_name(), "Accessories")
        self.assertEqual(found[1].get_icon().get_names()[0], "applications-utilities")

    def test_where_is_it_kde4(self):
        app = Application("", "ark")
        details = app.get_details(self.db)
        self.assertEqual(details.desktop_file, "/usr/share/app-install/desktop/ark:kde4__ark.desktop")
        # search the settings menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file, [os.path.abspath("./data/fake-applications.menu")])
        self.assertEqual(found[0].get_name(), "Applications")
        self.assertEqual(found[0].get_icon().get_names()[0], "applications-other")
        self.assertEqual(found[1].get_name(), "Accessories")
        self.assertEqual(found[1].get_icon().get_names()[0], "applications-utilities")

    def test_where_is_it_real_system(self):
        app = Application("", "gedit")
        details = app.get_details(self.db)
        if details.pkg_state != PkgStates.INSTALLED:
            logging.warn("gedit not installed, skipping real menu test")
            self.skipTest("gedit not installed")
            return
        self.assertEqual(details.desktop_file, "/usr/share/app-install/desktop/gedit:gedit.desktop")
        # search the *real* menu
        searcher = GMenuSearcher()
        found = searcher.get_main_menu_path(details.desktop_file)
        self.assertNotEqual(found, None)