Example #1
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
Example #2
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
Example #3
0
 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()
Example #4
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
Example #5
0
def rebuild_database(pathname, debian_sources=True, appstream_sources=False):
    #cache = apt.Cache(memonly=True)
    cache = get_pkg_info()
    cache.open()
    old_path = pathname+"_old"
    rebuild_path = pathname+"_rb"
    
    if not os.path.exists(rebuild_path):
        try:
            os.makedirs(rebuild_path)
        except:
            LOG.warn("Problem creating rebuild path '%s'." % rebuild_path)
            LOG.warn("Please check you have the relevant permissions.")
            return False
    
    # check permission
    if not os.access(pathname, os.W_OK):
        LOG.warn("Cannot write to '%s'." % pathname)
        LOG.warn("Please check you have the relevant permissions.")
        return False
    
    #check if old unrequired version of db still exists on filesystem
    if os.path.exists(old_path):
        LOG.warn("Existing xapian old db was not previously cleaned: '%s'." % old_path)
        if os.access(old_path, os.W_OK):
            #remove old unrequired db before beginning
            shutil.rmtree(old_path)
        else:
            LOG.warn("Cannot write to '%s'." % old_path)
            LOG.warn("Please check you have the relevant permissions.")
            return False

            
    # write it
    db = xapian.WritableDatabase(rebuild_path, xapian.DB_CREATE_OR_OVERWRITE)

    if debian_sources:
        update(db, cache)
    if appstream_sources:
        update_from_appstream_xml(db, cache)

    # write the database version into the filep
    db.set_metadata("db-schema-version", DB_SCHEMA_VERSION)
    # update the mo file stamp for the langpack checks
    mofile = gettext.find("app-install-data")
    if mofile:
        mo_time = os.path.getctime(mofile)
        db.set_metadata("app-install-mo-time", str(mo_time))
    db.flush()
    
    # use shutil.move() instead of os.rename() as this will automatically
    # figure out if it can use os.rename or needs to do the move "manually"
    try:
        shutil.move(pathname, old_path)
        shutil.move(rebuild_path, pathname)
        shutil.rmtree(old_path)
        return True
    except:
        LOG.warn("Cannot copy refreshed database to correct location: '%s'." % pathname)
        return False
Example #6
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
 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()
Example #8
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
Example #9
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
Example #11
0
 def test_memleak_pkginfo_open(self):
     cache = get_pkg_info()
     cache.open()
     do_events_with_sleep()
     with TraceMemoryUsage("PackageInfo.open()"):
         for i in range(self.ITERATIONS):
             cache.open()
             do_events_with_sleep()
Example #12
0
def get_test_db_from_app_install_data(datadir):
    db = xapian.inmemory_open()
    cache = get_pkg_info()
    cache.open()
    res = update_from_app_install_data(db, cache, datadir)
    if res is False:
        raise AssertionError("Failed to build db from '%s'" % datadir)
    return db
Example #13
0
 def test_memleak_pkginfo_open(self):
     cache = get_pkg_info()
     cache.open()
     do_events_with_sleep()
     with TraceMemoryUsage("PackageInfo.open()"):
         for i in range(self.ITERATIONS):
             cache.open()
             do_events_with_sleep()
Example #14
0
def get_test_db_from_app_install_data(datadir):
    db = xapian.inmemory_open()
    cache = get_pkg_info()
    cache.open()
    res = update_from_app_install_data(db, cache, datadir)
    if res is False:
        raise AssertionError("Failed to build db from '%s'" % datadir)
    return db
def get_installed_package_list():
    """ return a set of all of the currently installed packages """
    from softwarecenter.db.pkginfo import get_pkg_info
    installed_pkgs = set()
    cache = get_pkg_info()
    for pkg in cache:
        if pkg.is_installed:
            installed_pkgs.add(pkg.name)
    return installed_pkgs
Example #16
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 __init__(self, parent=None):
        super(ReviewsListModel, self).__init__()
        self._reviews = []

        roles = dict(enumerate(ReviewsListModel.COLUMNS))
        self.setRoleNames(roles)
        # FIXME: make this async
        self.cache = get_pkg_info()
        self.reviews = get_review_loader(self.cache)
Example #18
0
    def __init__(self, parent=None):
        super(ReviewsListModel, self).__init__()
        self._reviews = []

        roles = dict(enumerate(ReviewsListModel.COLUMNS))
        self.setRoleNames(roles)
        # FIXME: make this async
        self.cache = get_pkg_info()
        self.reviews = get_review_loader(self.cache)
Example #19
0
def get_installed_package_list():
    """ return a set of all of the currently installed packages """
    from softwarecenter.db.pkginfo import get_pkg_info
    installed_pkgs = set()
    cache = get_pkg_info()
    for pkg in cache:
        if pkg.is_installed:
            installed_pkgs.add(pkg.name)
    return installed_pkgs
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
Example #21
0
 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')
Example #22
0
def get_test_window_catview(db=None, selected_category="Internet"):
    ''' 
        Note that selected_category must specify a category that includes
        subcategories, else a ValueError will be raised.
    '''
    def on_category_selected(view, cat):
        print("on_category_selected view: ", view)
        print("on_category_selected cat: ", cat)

    if db is None:
        cache = pkginfo.get_pkg_info()
        cache.open()

        xapian_base_path = "/var/cache/software-center"
        pathname = os.path.join(xapian_base_path, "xapian")
        db = database.StoreDatabase(pathname, cache)
        db.open()
    else:
        cache = db._aptcache

    icons = get_sc_icon_theme()
    distro = softwarecenter.distro.get_distro()
    apps_filter = appfilter.AppFilter(db, cache)

    # gui
    notebook = Gtk.Notebook()

    lobby_view = lobbyview.LobbyView(cache, db, icons, distro, apps_filter)

    scroll = Gtk.ScrolledWindow()
    scroll.add(lobby_view)
    notebook.append_page(scroll, Gtk.Label.new("Lobby"))

    subcat_cat = None
    for cat in lobby_view.categories:
        if cat.name == selected_category:
            if not cat.subcategories:
                raise ValueError('The value specified for selected_category '
                                 '*must* specify a '
                                 'category that contains subcategories!!')
            subcat_cat = cat
            break

    subcat_view = catview.SubCategoryView(cache, db, icons, apps_filter)
    subcat_view.connect("category-selected", on_category_selected)
    subcat_view.set_subcategory(subcat_cat)

    scroll = Gtk.ScrolledWindow()
    scroll.add(subcat_view)
    notebook.append_page(scroll, Gtk.Label.new("Subcats"))

    win = get_test_window(child=notebook, width=800, height=800)
    win.set_data("subcat", subcat_view)
    win.set_data("lobby", lobby_view)
    return win
Example #23
0
    def __init__(self, parent=None):
        super(ReviewsListModel, self).__init__()
        self._reviews = []

        roles = dict(enumerate(ReviewsListModel.COLUMNS))
        self.setRoleNames(roles)
        # FIXME: make this async
        self.cache = get_pkg_info()
        self.reviews = get_review_loader(self.cache)
        self.reviews.connect("refresh-review-stats-finished", self._on_refresh_review_stats_finished)
        self.reviews.connect("get-reviews-finished", self._on_reviews_ready_callback)
Example #24
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()
Example #25
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()
Example #26
0
    def __init__(self, parent=None):
        super(ReviewsListModel, self).__init__()
        self._reviews = []

        roles = dict(enumerate(ReviewsListModel.COLUMNS))
        self.setRoleNames(roles)
        # FIXME: make this async
        self.cache = get_pkg_info()
        self.reviews = get_review_loader(self.cache)
        self.reviews.connect("refresh-review-stats-finished",
                             self._on_refresh_review_stats_finished)
        self.reviews.connect("get-reviews-finished",
                             self._on_reviews_ready_callback)
Example #27
0
 def test_memleak_appdetails(self):
     cache = get_pkg_info()
     cache.open(blocking=True)
     win = get_test_window_appdetails()
     view = win.get_data("view")
     app = Application("", "gedit")
     # get baseline
     view.show_app(app)
     do_events_with_sleep()
     with TraceMemoryUsage("AppdetailsView.show_app()"):
         for i in range(self.ITERATIONS):
             view.show_app(app, force=True)
             # this causes a huge memleak of ~35mb/run
             cache.open()
             do_events_with_sleep()
Example #28
0
 def test_memleak_appdetails(self):
     cache = get_pkg_info()
     cache.open(blocking=True)
     win = get_test_window_appdetails()
     view = win.get_data("view")
     app = Application("", "gedit")
     # get baseline
     view.show_app(app)
     do_events_with_sleep()
     with TraceMemoryUsage("AppdetailsView.show_app()"):
         for i in range(self.ITERATIONS):
             view.show_app(app, force=True)
             # this causes a huge memleak of ~35mb/run
             cache.open()
             do_events_with_sleep()
Example #29
0
 def test_memleak_app_recommendations(self):
     cache = get_pkg_info()
     cache.open(blocking=True)
     win = get_test_window_appdetails()
     view = win.get_data("view")
     app = Application("", "gedit")
     # get baseline
     view.show_app(app)
     do_events_with_sleep()
     with TraceMemoryUsage("AppdetailsView.show_app()"):
         with TraceActiveObjectTypes("view.recommended_for_app.set_pkgname"):
             for i in range(self.ITERATIONS):
                 view.recommended_for_app_panel.set_pkgname("gedit")
                 cache.open()
                 do_events_with_sleep()
Example #30
0
 def test_memleak_app(self):
     options = Mock()
     options.display_navlog = False
     args = []
     # ensure the cache is fully ready before taking the baseline
     cache = get_pkg_info()
     cache.open(blocking=True)
     app = SoftwareCenterAppGtk3(options, args)
     app.window_main.show_all()
     do_events_with_sleep()
     with TraceMemoryUsage("app._on_transaction_finished"):
         for i in range(self.ITERATIONS):
             app._on_transaction_finished(None, None)
             cache.open()
             do_events_with_sleep()
Example #31
0
 def test_memleak_app(self):
     options = Mock()
     options.display_navlog = False
     args = []
     # ensure the cache is fully ready before taking the baseline
     cache = get_pkg_info()
     cache.open(blocking=True)
     app = SoftwareCenterAppGtk3(options, args)
     app.window_main.show_all()
     do_events_with_sleep()
     with TraceMemoryUsage("app._on_transaction_finished"):
         for i in range(self.ITERATIONS):
             app._on_transaction_finished(None, None)
             cache.open()
             do_events_with_sleep()
Example #32
0
 def test_memleak_app_recommendations(self):
     cache = get_pkg_info()
     cache.open(blocking=True)
     win = get_test_window_appdetails()
     view = win.get_data("view")
     app = Application("", "gedit")
     # get baseline
     view.show_app(app)
     do_events_with_sleep()
     with TraceMemoryUsage("AppdetailsView.show_app()"):
         with TraceActiveObjectTypes(
                 "view.recommended_for_app.set_pkgname"):
             for i in range(self.ITERATIONS):
                 view.recommended_for_app_panel.set_pkgname("gedit")
                 cache.open()
                 do_events_with_sleep()
 def __init__(self, pathname=None, cache=None):
     GObject.GObject.__init__(self)
     if pathname is None:
         pathname = softwarecenter.paths.XAPIAN_PATH
     self._db_pathname = pathname
     if cache is None:
         cache = get_pkg_info()
     self._aptcache = cache
     self._additional_databases = []
     # the xapian values as read from /var/lib/apt-xapian-index/values
     self._axi_values = {}
     # we open one db per thread, thread names are reused eventually
     # so no memory leak
     self._db_per_thread = {}
     self._parser_per_thread = {}
     self._axi_stamp_monitor = None
Example #34
0
 def __init__(self, pathname=None, cache=None):
     GObject.GObject.__init__(self)
     if pathname is None:
         pathname = softwarecenter.paths.XAPIAN_PATH
     self._db_pathname = pathname
     if cache is None:
         cache = get_pkg_info()
     self._aptcache = cache
     self._additional_databases = []
     # the xapian values as read from /var/lib/apt-xapian-index/values
     self._axi_values = {}
     self._logger = logging.getLogger("softwarecenter.db")
     # we open one db per thread, thread names are reused eventually
     # so no memory leak
     self._db_per_thread = {} 
     self._parser_per_thread = {} 
Example #35
0
 def test_get_total_size(self):
     # get a cache 
     cache = get_pkg_info()
     cache.open()
     # pick first uninstalled pkg
     for pkg in cache:
         if not pkg.is_installed:
             break
     # prepare args
     addons_to_install = addons_to_remove = []
     archive_suite = "foo"
     with patch.object(cache, "_set_candidate_release") as f_mock:
         cache.get_total_size_on_install(
             pkg.name, addons_to_install, addons_to_remove, archive_suite)
         # ensure it got called with the right arguments
         f_mock.assert_called_with(pkg, archive_suite)
Example #36
0
 def test_get_total_size(self):
     # get a cache
     cache = get_pkg_info()
     cache.open()
     # pick first uninstalled pkg
     for pkg in cache:
         if not pkg.is_installed:
             break
     # prepare args
     addons_to_install = addons_to_remove = []
     archive_suite = "foo"
     with patch.object(cache, "_set_candidate_release") as f_mock:
         cache.get_total_size_on_install(pkg.name, addons_to_install,
                                         addons_to_remove, archive_suite)
         # ensure it got called with the right arguments
         f_mock.assert_called_with(pkg, archive_suite)
Example #37
0
 def _on_install_ready(self, source, result, task):
     LOG.debug("install done %s %s", source, result)
     results = task.generic_finish(result)
     if not results:
         LOG.debug("unable to fetch results")
         return
     # update package cache
     sack = results.get_package_sack()
     array = sack.get_array()
     if len(array) == 0:
         LOG.error("unable to get package results")
         return
     pkg = array[0]
     infoCache = get_pkg_info()
     infoCache.update_installed_status(pkg.get_name(), True)
     LOG.debug("updated package-info cache for %s" % pkg.get_name())
Example #38
0
def get_test_window_pkgnamesview():
    cache = pkginfo.get_pkg_info()
    cache.open()

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

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

    win = get_test_window(child=view)
    return win
Example #39
0
    def test_open_aptcache(self):
        # mvo: for the performance, its critical to have a 
        #      /var/cache/apt/srcpkgcache.bin - otherwise stuff will get slow

        # open s-c aptcache
        with ExecutionTime("s-c softwarecenter.apt.AptCache"):
            self.sccache = get_pkg_info()
        # cache is opened with a timeout_add() in get_pkg_info()
        time.sleep(0.2)
        context = GObject.main_context_default()
        while context.pending():
            context.iteration()
        # compare with plain apt
        with ExecutionTime("plain apt: apt.Cache()"):
            self.cache = apt.Cache()
        with ExecutionTime("plain apt: apt.Cache(memonly=True)"):
            self.cache = apt.Cache(memonly=True)
    def __init__(self):
        GObject.GObject.__init__(self)
        InstallBackend.__init__(self)

        # transaction details for setting as meta
        self.new_pkgname, self.new_appname, self.new_iconname = '', '', ''
        
        # this is public exposed
        self.pending_transactions = {}

        self.client = packagekit.Client()
        self.pkginfo = get_pkg_info()
        self.pkginfo.open()

        self._transactions_watcher = PackagekitTransactionsWatcher()
        self._transactions_watcher.connect('lowlevel-transactions-changed',
                                self._on_lowlevel_transactions_changed)        
Example #41
0
    def __init__(self):
        GObject.GObject.__init__(self)
        InstallBackend.__init__(self)

        # transaction details for setting as meta
        self.new_pkgname, self.new_appname, self.new_iconname = '', '', ''
        
        # this is public exposed
        self.pending_transactions = {}

        self.client = packagekit.Client()
        self.pkginfo = get_pkg_info()
        self.pkginfo.open()

        self._transactions_watcher = PackagekitTransactionsWatcher()
        self._transactions_watcher.connect('lowlevel-transactions-changed',
                                self._on_lowlevel_transactions_changed)        
Example #42
0
    def test_open_aptcache(self):
        # mvo: for the performance, its critical to have a
        #      /var/cache/apt/srcpkgcache.bin - otherwise stuff will get slow

        # open s-c aptcache
        with ExecutionTime("s-c softwarecenter.apt.AptCache"):
            self.sccache = get_pkg_info()
        # cache is opened with a timeout_add() in get_pkg_info()
        time.sleep(0.2)
        context = GObject.main_context_default()
        while context.pending():
            context.iteration()
        # compare with plain apt
        with ExecutionTime("plain apt: apt.Cache()"):
            self.cache = apt.Cache()
        with ExecutionTime("plain apt: apt.Cache(memonly=True)"):
            self.cache = apt.Cache(memonly=True)
Example #43
0
 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")
Example #44
0
 def test_get_total_size_with_mock(self):
     # get a cache 
     cache = get_pkg_info()
     cache.open()
     # pick first uninstalled pkg
     for pkg in cache:
         if not pkg.is_installed:
             break
     # prepare args
     addons_to_install = addons_to_remove = []
     archive_suite = "foo"
     with patch.object(cache.aptd_client, "commit_packages") as f_mock:
         cache.query_total_size_on_install(
             pkg.name, addons_to_install, addons_to_remove, archive_suite)
         # ensure it got called with the right arguments
         args, kwargs = f_mock.call_args
         to_install = args[0]
         self.assertTrue(to_install[0].endswith("/%s" % archive_suite))
Example #45
0
    def _add_tiles_to_flowgrid(self, docs, flowgrid, amount):
        '''Adds application tiles to a FlowableGrid:
           docs = xapian documents (apps)
           flowgrid = the FlowableGrid to add tiles to
           amount = number of tiles to add from start of doc range'''
        amount = min(len(docs), amount)

        cache = get_pkg_info()
        if hasattr(cache, 'prefill_cache'):
            prefill_pkgnames = [ self.db.get_pkgname(doc) for doc in docs[0:amount] ]
            cache.prefill_cache(wanted_pkgs = prefill_pkgnames, only_newest=True)

        for doc in docs[0:amount]:
            tile = FeaturedTile(self.properties_helper, doc)
            tile.connect('clicked', self.on_app_clicked,
                         self.properties_helper.get_application(doc))
            flowgrid.add_child(tile)
        return
Example #46
0
def get_test_catview():
    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % (view, cat))

    cache = pkginfo.get_pkg_info()
    cache.open()

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

    icons = get_sc_icon_theme()
    distro = softwarecenter.distro.get_distro()
    apps_filter = appfilter.AppFilter(db, cache)

    cat_view = lobbyview.LobbyView(cache, db, icons, distro, apps_filter)

    return cat_view
 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')
Example #48
0
    def __init__(self, pathname=None, cache=None):
        GObject.GObject.__init__(self)
        # initialize at creation time to avoid spurious AttributeError
        self._use_agent = False
        self._use_axi = False

        if pathname is None:
            pathname = softwarecenter.paths.XAPIAN_PATH
        self._db_pathname = pathname
        if cache is None:
            cache = get_pkg_info()
        self._aptcache = cache
        self._additional_databases = []
        # the xapian values as read from /var/lib/apt-xapian-index/values
        self._axi_values = {}
        # we open one db per thread, thread names are reused eventually
        # so no memory leak
        self._db_per_thread = {}
        self._parser_per_thread = {}
        self._axi_stamp_monitor = None
def get_test_catview():

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

    cache = pkginfo.get_pkg_info()
    cache.open()

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

    icons = get_sc_icon_theme()
    distro = softwarecenter.distro.get_distro()
    apps_filter = appfilter.AppFilter(db, cache)

    cat_view = lobbyview.LobbyView(cache, db, icons, distro, apps_filter)

    return cat_view
Example #50
0
def get_test_window_appdetails(pkgname=None):
    cache = pkginfo.get_pkg_info()
    cache.open()

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

    icons = get_sc_icon_theme()
    distro = softwarecenter.distro.get_distro()

    # gui
    scroll = Gtk.ScrolledWindow()
    view = appdetailsview.AppDetailsView(db, distro, icons, cache)

    if pkgname is None:
        pkgname = "totem"

    view.show_app(application.Application("", pkgname))
    #view.show_app(application.Application("Pay App Example", "pay-app"))
    #view.show_app(application.Application("3D Chess", "3dchess"))
    #view.show_app(application.Application("Movie Player", "totem"))
    #view.show_app(application.Application("ACE", "unace"))
    #~ view.show_app(application.Application("", "apt"))

    #view.show_app("AMOR")
    #view.show_app("Configuration Editor")
    #view.show_app("Artha")
    #view.show_app("cournol")
    #view.show_app("Qlix")

    scroll.add(view)
    scroll.show()

    win = get_test_window(child=scroll, width=800, height=800)
    win.set_data("view", view)
    return win
def show_top_rated_apps():
    # get the ratings
    cache = get_pkg_info()
    loader = get_review_loader(cache)
    review_stats = loader.REVIEW_STATS_CACHE
    # recalculate using different default power
    results = {}
    for i in [0.5, 0.4, 0.3, 0.2, 0.1, 0.05]:
        for (key, value) in review_stats.iteritems():
            value.dampened_rating = calc_dr(value.rating_spread, power=i)
        top_rated = loader.get_top_rated_apps(quantity=25)
        print "For power: %s" % i
        for (i, key) in enumerate(top_rated):
            item = review_stats[key]
            print "%(rang)2i: %(pkgname)-25s avg=%(avg)1.2f total=%(total)03i dampened=%(dampened)1.5f spread=%(spread)s" % { 
                'rang' : i+1,
                'pkgname' : item.app.pkgname,
                'avg' : item.ratings_average,
                'total' : item.ratings_total,
                'spread' : item.rating_spread,
                'dampened' : item.dampened_rating,
                }
        print 
        results[i] = top_rated[:]
Example #52
0
def show_top_rated_apps():
    # get the ratings
    cache = get_pkg_info()
    loader = get_review_loader(cache)
    review_stats = loader.REVIEW_STATS_CACHE
    # recalculate using different default power
    results = {}
    for i in [0.5, 0.4, 0.3, 0.2, 0.1, 0.05]:
        for (key, value) in review_stats.iteritems():
            value.dampened_rating = calc_dr(value.rating_spread, power=i)
        top_rated = loader.get_top_rated_apps(quantity=25)
        print "For power: %s" % i
        for (i, key) in enumerate(top_rated):
            item = review_stats[key]
            print "%(rang)2i: %(pkgname)-25s avg=%(avg)1.2f total=%(total)03i dampened=%(dampened)1.5f spread=%(spread)s" % {
                'rang': i + 1,
                'pkgname': item.app.pkgname,
                'avg': item.ratings_average,
                'total': item.ratings_total,
                'spread': item.rating_spread,
                'dampened': item.dampened_rating,
            }
        print
        results[i] = top_rated[:]
 def setUpClass(cls):
     cache = get_pkg_info()
     cache.open()
     db = xapian.WritableDatabase(TEST_DB, xapian.DB_CREATE_OR_OVERWRITE)
     update_from_json_string(db, cache, cls.APP_INFO_JSON, origin="local")
     db.close()
 def setUp(self):
     apt.apt_pkg.config.set("Dir::State::status", PKD_DIR)
     self.cache = get_pkg_info()
     self.cache.open()