Пример #1
0
    def _add_application_to_unity_launcher(self, transaction_details):
        if not self.add_to_launcher_enabled:
            return
        # mvo: use use softwarecenter.utils explicitly so that we can monkey
        #      patch it in the test
        if not softwarecenter.utils.is_unity_running():
            return

        app = Application(pkgname=transaction_details.pkgname,
                          appname=transaction_details.appname)
        appdetails = app.get_details(self.db)
        # we only add items to the launcher that have a desktop file
        if not appdetails.desktop_file:
            return
        # do not add apps that have no Exec entry in their desktop file
        # (e.g. wine, see LP: #848437 or ubuntu-restricted-extras,
        # see LP: #913756)
        if (os.path.exists(appdetails.desktop_file) and
            not get_exec_line_from_desktop(appdetails.desktop_file)):
            return

        # now gather up the unity launcher info items and send the app to the
        # launcher service
        launcher_info = self._get_unity_launcher_info(app, appdetails,
                transaction_details.trans_id)
        self.unity_launcher.send_application_to_launcher(
                transaction_details.pkgname,
                launcher_info)
    def _add_application_to_unity_launcher(self, transaction_details):
        app = Application(pkgname=transaction_details.pkgname,
                          appname=transaction_details.appname)
        appdetails = app.get_details(self.db)
        # convert the app-install desktop file location to the actual installed
        # desktop file location (or in the case of a purchased item from the
        # agent, generate the correct installed desktop file location)
        installed_desktop_file_path = (
            convert_desktop_file_to_installed_location(appdetails.desktop_file,
                                                       app.pkgname))
        # we only add items to the launcher that have a desktop file
        if not installed_desktop_file_path:
            return
        # do not add apps that have no Exec entry in their desktop file
        # (e.g. wine, see LP: #848437 or ubuntu-restricted-extras,
        # see LP: #913756), also, don't add the item if NoDisplay is
        # specified (see LP: #1006483)
        if (os.path.exists(installed_desktop_file_path) and
            (not get_exec_line_from_desktop(installed_desktop_file_path)
             or is_no_display_desktop_file(installed_desktop_file_path))):
            return

        # now gather up the unity launcher info items and send the app to the
        # launcher service
        launcher_info = self._get_unity_launcher_info(
            app, appdetails, installed_desktop_file_path,
            transaction_details.trans_id)
        self.unity_launcher.send_application_to_launcher(
            transaction_details.pkgname, launcher_info)
    def _add_application_to_unity_launcher(self, transaction_details):
        if not self.add_to_launcher_enabled:
            return
        # mvo: use use softwarecenter.utils explicitly so that we can monkey
        #      patch it in the test
        if not softwarecenter.utils.is_unity_running():
            return

        app = Application(pkgname=transaction_details.pkgname,
                          appname=transaction_details.appname)
        appdetails = app.get_details(self.db)
        # we only add items to the launcher that have a desktop file
        if not appdetails.desktop_file:
            return
        # do not add apps that have no Exec entry in their desktop file
        # (e.g. wine, see LP: #848437 or ubuntu-restricted-extras,
        # see LP: #913756)
        if (os.path.exists(appdetails.desktop_file)
                and not get_exec_line_from_desktop(appdetails.desktop_file)):
            return

        # now gather up the unity launcher info items and send the app to the
        # launcher service
        launcher_info = self._get_unity_launcher_info(
            app, appdetails, transaction_details.trans_id)
        self.unity_launcher.send_application_to_launcher(
            transaction_details.pkgname, launcher_info)
Пример #4
0
 def _register_unity_launcher_transaction_started(self, backend, pkgname, 
                                                  appname, trans_id, 
                                                  trans_type):
     # mvo: use use softwarecenter.utils explictely so that we can monkey
     #      patch it in the test
     if not softwarecenter.utils.is_unity_running():
         return
     # add to launcher only applies in the details view currently
     if not self.is_app_details_view_showing():
         return
     # we only care about getting the launcher information on an install
     if not trans_type == TransactionTypes.INSTALL:
         if pkgname in self.unity_launcher_items:
             self.unity_launcher_items.pop(pkgname)
             self.action_bar.clear()
         return
     # gather details for this transaction and create the launcher_info object
     app = Application(pkgname=pkgname, appname=appname)
     appdetails = app.get_details(self.db)
     (icon_size, icon_x, icon_y) = self._get_onscreen_icon_details_for_launcher_service(app)
     launcher_info = UnityLauncherInfo(app.name,
                                       appdetails.icon,
                                       "",        # we set the icon_file_path value *after* install
                                       icon_x,
                                       icon_y,
                                       icon_size,
                                       appdetails.desktop_file,
                                       "",        # we set the installed_desktop_file_path *after* install
                                       trans_id)
     self.unity_launcher_items[app.pkgname] = launcher_info
     self.show_add_to_launcher_panel(backend, pkgname, appname, app, appdetails, trans_id, trans_type)
Пример #5
0
 def _register_unity_launcher_transaction_started(self, backend, pkgname, 
                                                  appname, trans_id, 
                                                  trans_type):
     # mvo: use use softwarecenter.utils explictely so that we can monkey
     #      patch it in the test
     if not softwarecenter.utils.is_unity_running():
         return
     # add to launcher only applies in the details view currently
     if not self.is_app_details_view_showing():
         return
     # we only care about getting the launcher information on an install
     if not trans_type == TransactionTypes.INSTALL:
         if pkgname in self.unity_launcher_items:
             self.unity_launcher_items.pop(pkgname)
             self.action_bar.clear()
         return
     # gather details for this transaction and create the launcher_info object
     app = Application(pkgname=pkgname, appname=appname)
     appdetails = app.get_details(self.db)
     (icon_size, icon_x, icon_y) = self._get_onscreen_icon_details_for_launcher_service(app)
     launcher_info = UnityLauncherInfo(app.name,
                                       appdetails.icon,
                                       "",        # we set the icon_file_path value *after* install
                                       icon_x,
                                       icon_y,
                                       icon_size,
                                       appdetails.desktop_file,
                                       "",        # we set the installed_desktop_file_path *after* install
                                       trans_id)
     self.unity_launcher_items[app.pkgname] = launcher_info
     self.show_add_to_launcher_panel(backend, pkgname, appname, app, appdetails, trans_id, trans_type)
    def _add_application_to_unity_launcher(self, transaction_details):
        app = Application(pkgname=transaction_details.pkgname,
                          appname=transaction_details.appname)
        appdetails = app.get_details(self.db)
        # convert the app-install desktop file location to the actual installed
        # desktop file location (or in the case of a purchased item from the
        # agent, generate the correct installed desktop file location)
        installed_desktop_file_path = (
            convert_desktop_file_to_installed_location(appdetails.desktop_file,
                                                       app.pkgname))
        # we only add items to the launcher that have a desktop file
        if not installed_desktop_file_path:
            return
        # do not add apps that have no Exec entry in their desktop file
        # (e.g. wine, see LP: #848437 or ubuntu-restricted-extras,
        # see LP: #913756), also, don't add the item if NoDisplay is
        # specified (see LP: #1006483)
        if (os.path.exists(installed_desktop_file_path) and
            (not get_exec_line_from_desktop(installed_desktop_file_path) or
            is_no_display_desktop_file(installed_desktop_file_path))):
            return

        # now gather up the unity launcher info items and send the app to the
        # launcher service
        launcher_info = self._get_unity_launcher_info(app, appdetails,
                installed_desktop_file_path,
                transaction_details.trans_id)
        self.unity_launcher.send_application_to_launcher(
                transaction_details.pkgname,
                launcher_info)
 def _update_action_bar_buttons(self):
     """Update buttons in the action bar to implement the custom package
        lists feature, see
        https://wiki.ubuntu.com/SoftwareCenter#Custom%20package%20lists
     """
     if self._is_custom_list_search(self.state.search_term):
         installable = []
         for doc in self.enquirer.get_documents():
             pkgname = self.db.get_pkgname(doc)
             if (pkgname in self.cache
                     and not self.cache[pkgname].is_installed
                     and not len(self.backend.pending_transactions) > 0):
                 app = Application(pkgname=pkgname)
                 installable.append(app)
         button_text = gettext.ngettext("Install %(amount)s Item",
                                        "Install %(amount)s Items",
                                        len(installable)) % {
                                            'amount': len(installable)
                                        }
         button = self.action_bar.get_button(ActionButtons.INSTALL)
         if button and installable:
             # Install all already offered. Update offer.
             if button.get_label() != button_text:
                 button.set_label(button_text)
         elif installable:
             # Install all not yet offered. Offer.
             self.action_bar.add_button(ActionButtons.INSTALL, button_text,
                                        self._install_current_appstore)
         else:
             # Install offered, but nothing to install. Clear offer.
             self.action_bar.remove_button(ActionButtons.INSTALL)
     else:
         # Ensure button is removed.
         self.action_bar.remove_button(ActionButtons.INSTALL)
 def from_json(cls, other):
     """ convert json reviews into "out" review objects """
     app = Application("", other["package_name"])
     review = cls(app)
     for k, v in other.items():
         setattr(review, k, v)
     return review
    def _on_review_stats_data(self, spawn_helper, piston_review_stats,
                              callback):
        """ process stdout from the helper """
        review_stats = self.REVIEW_STATS_CACHE

        if self._cache_version_old and self._server_has_histogram(
                piston_review_stats):
            self.REVIEW_STATS_CACHE = {}
            self.save_review_stats_cache_file()
            self.refresh_review_stats(callback)
            return

        # convert to the format that s-c uses
        for r in piston_review_stats:
            s = ReviewStats(Application("", r.package_name))
            s.ratings_average = float(r.ratings_average)
            s.ratings_total = float(r.ratings_total)
            if r.histogram:
                s.rating_spread = json.loads(r.histogram)
            else:
                s.rating_spread = [0, 0, 0, 0, 0]
            s.dampened_rating = calc_dr(s.rating_spread)
            review_stats[s.app] = s
        self.REVIEW_STATS_CACHE = review_stats
        callback(review_stats)
        self.emit("refresh-review-stats-finished", review_stats)
        self.save_review_stats_cache_file()
Пример #10
0
        def __init__(self, db, pkgname, appname, trans_id, trans_type):
            self.db = db
            self.app = Application(pkgname=pkgname, appname=appname)
            self.trans_id = trans_id
            self.trans_type = trans_type
            self.__app_details = None
            self.__real_desktop = None

            if trans_type != TransactionTypes.INSTALL:
                self.guess_final_desktop_file()
Пример #11
0
    def getReviews(self, pkgname, page=1):
        # pkgname is a QString, so we need to convert it to a old-fashioned str
        pkgname = unicode(pkgname).encode("utf-8")
        app = Application("", pkgname)
        # support pagination by not cleaning _reviews for subsequent pages
        if page == 1:
            self.clear()

        # load in the eventloop to ensure that animations are not delayed
        GLib.timeout_add(10, self.reviews.get_reviews, app, page)
 def from_piston_mini_client(cls, other):
     """ converts the rnrclieent reviews we get into
         "our" Review object (we need this as we have more
         attributes then the rnrclient review object)
     """
     app = Application("", other.package_name)
     review = cls(app)
     for (attr, value) in other.__dict__.items():
         if not attr.startswith("_"):
             setattr(review, attr, value)
     return review
 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
 def get_review_stats(self, translated_application):
     """return a ReviewStats (number of reviews, rating)
        for a given application. this *must* be super-fast
        as it is called a lot during tree view display
     """
     # check cache
     try:
         application = Application("", translated_application.pkgname)
         if application in self.REVIEW_STATS_CACHE:
             return self.REVIEW_STATS_CACHE[application]
     except ValueError:
         pass
Пример #15
0
    class TransactionDetails(object):
        """ Simple class to keep track of aptdaemon transaction details """
        def __init__(self, db, pkgname, appname, trans_id, trans_type):
            self.db = db
            self.app = Application(pkgname=pkgname, appname=appname)
            self.trans_id = trans_id
            self.trans_type = trans_type
            self.__app_details = None
            self.__real_desktop = None

            if trans_type != TransactionTypes.INSTALL:
                self.guess_final_desktop_file()

        @property
        def app_details(self):
            if not self.__app_details:
                self.__app_details = self.app.get_details(self.db)
            return self.__app_details

        @property
        def desktop_file(self):
            return self.app_details.desktop_file

        @property
        def final_desktop_file(self):
            return self.guess_final_desktop_file()

        def guess_final_desktop_file(self):
            if self.__real_desktop:
                return self.__real_desktop

            # convert the app-install desktop file location to the actual installed
            # desktop file location (or in the case of a purchased item from the
            # agent, generate the correct installed desktop file location)
            desktop_file = (
                convert_desktop_file_to_installed_location(self.desktop_file,
                                                           self.app.pkgname))
            # we only add items to the launcher that have a desktop file
            if not desktop_file:
                return
            # do not add apps that have no Exec entry in their desktop file
            # (e.g. wine, see LP: #848437 or ubuntu-restricted-extras,
            # see LP: #913756), also, don't add the item if NoDisplay is
            # specified (see LP: #1006483)
            if (os.path.exists(desktop_file) and
                    (not get_exec_line_from_desktop(desktop_file) or
                    is_no_display_desktop_file(desktop_file))):
                return

            self.__real_desktop = desktop_file
            return self.__real_desktop
 def update_review_stats(self, translated_application, stats):
     application = Application("", translated_application.pkgname)
     self.REVIEW_STATS_CACHE[application] = stats
            options.iconname = options.iconname or 'folder'
            options.version = options.version or '1.0'
            options.origin = options.origin or 'Ubuntu'
            options.parent_xid = options.parent_xid or '1'

        if not (options.pkgname and options.version):
            parser.error(_("Missing arguments"))

        if options.debug:
            logging.basicConfig(level=logging.DEBUG)

        # personality
        logging.debug("submit_review mode")

        # initialize and run
        theapp = Application(options.appname, options.pkgname)
        review_app = SubmitReviewsApp(datadir=options.datadir,
                                      app=theapp,
                                      parent_xid=options.parent_xid,
                                      iconname=options.iconname,
                                      origin=options.origin,
                                      version=options.version)
        review_app.run()

    # run "report" personality
    if "report_review" in sys.argv[0]:
        # check options
        parser.add_option("", "--review-id")
        parser.add_option("", "--parent-xid")
        parser.add_option("", "--debug", action="store_true", default=False)
        (options, args) = parser.parse_args()
        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()
 def installPackage(self, pkgname):
     appname = ""
     iconname = ""
     app = Application(appname, pkgname)
     self.backend.install(app, iconname)
 def removePackage(self, pkgname):
     appname = ""
     iconname = ""
     app = Application(appname, pkgname)
     self.backend.remove(app, iconname)