Пример #1
0
 def show_add_to_launcher_panel(self, backend, pkgname, appname, app, appdetails, trans_id, trans_type):
     """
     if Unity is currently running, display a panel to allow the user
     the choose whether to add a newly-installed application to the
     launcher
     """
     # TODO: handle local deb install case
     # TODO: implement the list view case (once it is specified)
     # only show the panel if unity is running and this is a package install
     #
     # we only show the prompt for apps with a desktop file
     if not appdetails.desktop_file:
         return
     # do not add apps without a exec line (like wine, see #848437)
     if (os.path.exists(appdetails.desktop_file) and
         is_no_display_desktop_file(appdetails.desktop_file)):
             return
     self.action_bar.add_button(ActionButtons.CANCEL_ADD_TO_LAUNCHER,
                                 _("Not Now"), 
                                 self.on_cancel_add_to_launcher, 
                                 pkgname)
     self.action_bar.add_button(ActionButtons.ADD_TO_LAUNCHER,
                                _("Add to Launcher"),
                                self.on_add_to_launcher,
                                pkgname,
                                app,
                                appdetails,
                                trans_id)
     self.action_bar.set_label(utf8(_("Add %s to the launcher?")) % utf8(app.name))
Пример #2
0
 def show_add_to_launcher_panel(self, backend, pkgname, appname, app, appdetails, trans_id, trans_type):
     """
     if Unity is currently running, display a panel to allow the user
     the choose whether to add a newly-installed application to the
     launcher
     """
     # TODO: handle local deb install case
     # TODO: implement the list view case (once it is specified)
     # only show the panel if unity is running and this is a package install
     #
     # we only show the prompt for apps with a desktop file
     if not appdetails.desktop_file:
         return
     # do not add apps without a exec line (like wine, see #848437)
     if (os.path.exists(appdetails.desktop_file) and
         is_no_display_desktop_file(appdetails.desktop_file)):
             return
     self.action_bar.add_button(ActionButtons.CANCEL_ADD_TO_LAUNCHER,
                                 _("Not Now"), 
                                 self.on_cancel_add_to_launcher, 
                                 pkgname)
     self.action_bar.add_button(ActionButtons.ADD_TO_LAUNCHER,
                                _("Add to Launcher"),
                                self.on_add_to_launcher,
                                pkgname,
                                app,
                                appdetails,
                                trans_id)
     self.action_bar.set_label(utf8(_("Add %s to the launcher?")) % utf8(app.name))
Пример #3
0
 def __init__(self, subcategory=None):
     self.subcategory = subcategory
     if subcategory:
         # this is the set of recommendations for a given subcategory
         cat_title = u"Recommended For You in %s" % (
                                              subcategory.untranslated_name)
         tr_title = utf8(_("Recommended For You in %s")) % utf8(
                                                           subcategory.name)
     else:
         # this is the full set of recommendations for e.g. the lobby view
         cat_title = u"Recommended For You"
         tr_title = _("Recommended For You")
     super(RecommendedForYouCategory, self).__init__(
             cat_title,
             tr_title,
             None,
             xapian.Query(),
             flags=['available-only', 'not-installed-only'],
             item_limit=60)
     self.recommender_agent = RecommenderAgent()
     self.recommender_agent.connect(
         "recommend-me", self._recommend_me_result)
     self.recommender_agent.connect(
         "error", self._recommender_agent_error)
     self.recommender_agent.query_recommend_me()
 def __init__(self, subcategory=None):
     self.subcategory = subcategory
     if subcategory:
         # this is the set of recommendations for a given subcategory
         cat_title = u"Recommended For You in %s" % (
                                              subcategory.untranslated_name)
         tr_title = utf8(_("Recommended For You in %s")) % utf8(
                                                           subcategory.name)
     else:
         # this is the full set of recommendations for e.g. the lobby view
         cat_title = u"Recommended For You"
         tr_title = _("Recommended For You")
     super(RecommendedForYouCategory, self).__init__(
             cat_title,
             tr_title,
             None,
             xapian.Query(),
             flags=['available-only', 'not-installed-only'],
             item_limit=60)
     self.recommender_agent = RecommenderAgent()
     self.recommender_agent.connect(
         "recommend-me", self._recommend_me_result)
     self.recommender_agent.connect(
         "error", self._recommender_agent_error)
     self.recommender_agent.query_recommend_me()
Пример #5
0
 def _apply_exceptions(self):
     super(SCAPurchasedApplicationParser, self)._apply_exceptions()
     # WARNING: item.name needs to be different than
     #          the item.name in the DB otherwise the DB
     #          gets confused about (appname, pkgname) duplication
     self.sca_application.name = utf8(_("%s (already purchased)")) % utf8(self.sca_application.name)
     self.sca_application.channel = PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME
Пример #6
0
    def __init__(self, db, doc=None, application=None):
        """ Create a new AppDetails object. It can be created from
            a xapian.Document or from a db.application.Application object
        """
        GObject.GObject.__init__(self)
        if not doc and not application:
            raise ValueError("Need either document or application")
        self._db = db
        self._db.connect("reopen", self._on_db_reopen)
        self._cache = self._db._aptcache
        self._distro = softwarecenter.distro.get_distro()
        self._history = None
        # import here (instead of global) to avoid dbus dependency
        # in update-software-center (that imports application, but
        # never uses AppDetails) LP: #620011
        from softwarecenter.backend.installbackend import get_install_backend
        self._backend = get_install_backend()
        # FIXME: why two error states ?
        self._error = None
        self._error_not_found = None
        self._screenshot_list = []

        # load application
        self._app = application
        if doc:
            self._app = Application(self._db.get_appname(doc),
                                    self._db.get_pkgname(doc), "")

        # substitute for apturl
        if self._app.request:
            self._app.request = self._app.request.replace(
                "$distro", self._distro.get_codename())

        # load pkg cache
        self._pkg = None
        if (self._app.pkgname in self._cache
                and self._cache[self._app.pkgname].candidate):
            self._pkg = self._cache[self._app.pkgname]

        # load xapian document
        self._doc = doc
        if not self._doc:
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except IndexError:
                # if there is no document and no apturl request,
                # set error state
                debfile_matches = re.findall(r'/', self._app.request)
                channel_matches = re.findall(r'channel=[a-z,-]*',
                                             self._app.request)
                section_matches = re.findall(r'section=[a-z]*',
                                             self._app.request)
                if (not self._pkg and not debfile_matches
                        and not channel_matches and not section_matches):
                    self._error = _("Not found")
                    self._error_not_found = utf8(
                        _(u"There isn\u2019t a "
                          u"software package called \u201c%s\u201D in your "
                          u"current software sources.")) % utf8(self.pkgname)
Пример #7
0
    def __init__(self, db, doc=None, application=None):
        """ Create a new AppDetails object. It can be created from
            a xapian.Document or from a db.application.Application object
        """
        GObject.GObject.__init__(self)
        if not doc and not application:
            raise ValueError("Need either document or application")
        self._db = db
        self._db.connect("reopen", self._on_db_reopen)
        self._cache = self._db._aptcache
        self._distro = softwarecenter.distro.get_distro()
        self._history = None
        # import here (instead of global) to avoid dbus dependency
        # in update-software-center (that imports application, but
        # never uses AppDetails) LP: #620011
        from softwarecenter.backend.installbackend import get_install_backend

        self._backend = get_install_backend()
        # FIXME: why two error states ?
        self._error = None
        self._error_not_found = None
        self._screenshot_list = []

        # load application
        self._app = application
        if doc:
            self._app = Application(self._db.get_appname(doc), self._db.get_pkgname(doc), "")

        # substitute for apturl
        if self._app.request:
            self._app.request = self._app.request.replace("$distro", self._distro.get_codename())

        # load pkg cache
        self._pkg = None
        if self._app.pkgname in self._cache and self._cache[self._app.pkgname].candidate:
            self._pkg = self._cache[self._app.pkgname]

        # load xapian document
        self._doc = doc
        if not self._doc:
            try:
                self._doc = self._db.get_xapian_document(self._app.appname, self._app.pkgname)
            except IndexError:
                # if there is no document and no apturl request,
                # set error state
                debfile_matches = re.findall(r"/", self._app.request)
                channel_matches = re.findall(r"channel=[a-z,-]*", self._app.request)
                section_matches = re.findall(r"section=[a-z]*", self._app.request)
                if not self._pkg and not debfile_matches and not channel_matches and not section_matches:
                    self._error = _("Not found")
                    self._error_not_found = utf8(
                        _(
                            u"There isn\u2019t a "
                            u"software package called \u201c%s\u201D in your "
                            u"current software sources."
                        )
                    ) % utf8(self.pkgname)
 def _apply_exceptions(self):
     super(SCAPurchasedApplicationParser, self)._apply_exceptions()
     # WARNING: item.name needs to be different than
     #          the item.name in the DB otherwise the DB
     #          gets confused about (appname, pkgname) duplication
     self.sca_application.name = utf8(_("%s (already purchased)")) % utf8(
         self.sca_application.name)
     self.sca_application.channel = (
         PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME)
Пример #9
0
    def pkg_state(self):
        # puchase state
        if self.pkgname in self._backend.pending_purchases:
            return PkgStates.INSTALLING_PURCHASED

        # via the pending transactions dict
        if self.pkgname in self._backend.pending_transactions:
            # FIXME: we don't handle upgrades yet
            # if there is no self._pkg yet, that means this is a INSTALL
            # from a previously not-enabled source (like a purchase)
            if self._pkg and self._pkg.installed:
                return PkgStates.REMOVING
            else:
                return PkgStates.INSTALLING

        # if we have _pkg that means its either:
        # - available for download (via sources.list)
        # - locally installed
        # - intalled and available for download
        if self._pkg:
            # Don't handle upgrades yet
            #if self._pkg.installed and self._pkg._isUpgradable:
            #    return PkgStates.UPGRADABLE
            if self._pkg.is_installed:
                return PkgStates.INSTALLED
            else:
                return PkgStates.UNINSTALLED
        # if we don't have a _pkg, then its either:
        #  - its in a unavailable repo
        #  - the repository information is outdated
        #  - the repository information is missing (/var/lib/apt/lists empty)
        #  - its a failure in our meta-data (e.g. typo in the pkgname in
        #    the metadata)
        if not self._pkg:
            if self.channelname:
                if self._unavailable_channel():
                    return PkgStates.NEEDS_SOURCE
                else:
                    self._error =  _("Not found")
                    self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
                    return PkgStates.NOT_FOUND
            else:
                if self.price:
                    return PkgStates.NEEDS_PURCHASE
                if (self.purchase_date and
                    self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):
                    return PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED
                if self.component:
                    components = self.component.split('&')
                    for component in components:
                        if component and self._unavailable_component(component_to_check=component):
                            return PkgStates.NEEDS_SOURCE
                self._error =  _("Not found")
                self._error_not_found = utf8(_(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources.")) % utf8(self.pkgname)
                return PkgStates.NOT_FOUND
        return PkgStates.UNKNOWN
Пример #10
0
 def __init__(self, catview, subcategory):
     RecommendationsPanel.__init__(self, catview)
     self.subcategory = subcategory
     if self.subcategory:
         self.set_header_label(GObject.markup_escape_text(utf8(
             _("Recommended For You in %s")) % utf8(self.subcategory.name)))
     self.recommended_for_you_content = None
     if self.recommender_agent.is_opted_in():
         self._update_recommended_for_you_content()
     else:
         self._hide_recommended_for_you_panel()
Пример #11
0
 def _apply_exceptions(self):
     super(SCAPurchasedApplicationParser, self)._apply_exceptions()
     # WARNING: item.name needs to be different than
     #          the item.name in the DB otherwise the DB
     #          gets confused about (appname, pkgname) duplication
     self.sca_application.name = utf8(_("%s (already purchased)")) % utf8(
         self.sca_application.name)
     for attr_name in ('license_key', 'license_key_path'):
         attr = getattr(self.sca_subscription, attr_name, self.NOT_DEFINED)
         if attr is self.NOT_DEFINED:
             setattr(self.sca_subscription, attr_name, None)
Пример #12
0
 def _apply_exceptions(self):
     super(SCAPurchasedApplicationParser, self)._apply_exceptions()
     # WARNING: item.name needs to be different than
     #          the item.name in the DB otherwise the DB
     #          gets confused about (appname, pkgname) duplication
     self.sca_application.name = utf8(_("%s (already purchased)")) % utf8(
         self.sca_application.name)
     for attr_name in ('license_key', 'license_key_path'):
         attr = getattr(self.sca_subscription, attr_name, self.NOT_DEFINED)
         if attr is self.NOT_DEFINED:
             setattr(self.sca_subscription, attr_name, None)
Пример #13
0
 def error(self):
     if self._error_not_found:
         return self._error_not_found
     elif self._error:
         return self._error
     # this may have changed since we inited the appdetails
     elif self.pkg_state == PkgStates.NOT_FOUND:
         self._error = _("Not found")
         self._error_not_found = utf8(
             _(u"There isn\u2019t a software package called \u201c%s\u201D in your current software sources."
               )) % utf8(self.pkgname)
         return self._error_not_found
Пример #14
0
 def error(self):
     if self._error_not_found:
         return self._error_not_found
     elif self._error:
         return self._error
     # this may have changed since we inited the appdetails
     elif self.pkg_state == PkgStates.NOT_FOUND:
         self._error = _("Not found")
         self._error_not_found = utf8(
             _(u"There isn\u2019t a software "
               u"package called \u201c%s\u201D in your current software "
               u"sources.")) % utf8(self.pkgname)
         return self._error_not_found
 def __init__(self, db, properties_helper, subcategory):
     RecommendationsPanel.__init__(self)
     self.db = db
     self.properties_helper = properties_helper
     self.subcategory = subcategory
     if self.subcategory:
         self.set_header_label(GLib.markup_escape_text(utf8(
             _("Recommended For You in %s")) % utf8(self.subcategory.name)))
     self.recommended_for_you_content = None
     if self.recommender_agent.is_opted_in():
         self._update_recommended_for_you_content()
     else:
         self.hide()
Пример #16
0
 def __init__(self, db, properties_helper, subcategory):
     RecommendationsPanel.__init__(self)
     self.db = db
     self.properties_helper = properties_helper
     self.subcategory = subcategory
     if self.subcategory:
         self.set_header_label(GLib.markup_escape_text(utf8(
             _("Recommended For You in %s")) % utf8(self.subcategory.name)))
     self.recommended_for_you_content = None
     if self.recommender_agent.is_opted_in():
         self._update_recommended_for_you_content()
     else:
         self.hide()
 def __init__(self, catview, subcategory):
     RecommendationsPanel.__init__(self, catview)
     self.subcategory = subcategory
     if self.subcategory:
         self.set_header_label(
             GObject.markup_escape_text(
                 utf8(_("Recommended For You in %s")) %
                 utf8(self.subcategory.name)))
     self.recommended_for_you_content = None
     if self.recommender_agent.is_opted_in():
         self._update_recommended_for_you_content()
     else:
         self._hide_recommended_for_you_panel()
Пример #18
0
 def warning(self):
     # FIXME: use more concise warnings
     if self._deb:
         deb_state = self._deb.compare_to_version_in_cache(use_installed=False)
         if deb_state == DebPackage.VERSION_NONE:
             return utf8(_("Only install this file if you trust the origin."))
         elif (not self._cache[self.pkgname].installed and
               self._cache[self.pkgname].candidate and
               self._cache[self.pkgname].candidate.downloadable): 
             if deb_state == DebPackage.VERSION_OUTDATED:
                 return utf8(_("Please install \"%s\" via your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name)
             elif deb_state == DebPackage.VERSION_SAME:
                 return utf8(_("Please install \"%s\" via your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name)
             elif deb_state == DebPackage.VERSION_NEWER:
                 return utf8(_("An older version of \"%s\" is available in your normal software channels. Only install this file if you trust the origin.")) % utf8(self.name)
Пример #19
0
    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise ValueError("doc must be None for deb files")

        try:
            # for some reason Cache() is much faster than "self._cache._cache"
            # on startup
            with ExecutionTime("create DebPackage"):
                self._deb = DebPackage(self._app.request, Cache())
        except:
            self._deb = None
            self._pkg = None
            if not os.path.exists(self._app.request):
                self._error = _("Not found")
                self._error_not_found = utf8(_(u"The file \u201c%s\u201d does not exist.")) % utf8(self._app.request)
            else:
                mimetype = guess_type(self._app.request)
                if mimetype[0] != "application/x-debian-package":
                    self._error =  _("Not found")
                    self._error_not_found = utf8(_(u"The file \u201c%s\u201d is not a software package.")) % utf8(self._app.request)
                else:
                    # deb files which are corrupt
                    self._error =  _("Internal Error")
                    self._error_not_found = utf8(_(u"The file \u201c%s\u201d could not be opened.")) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache and 
                self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string
Пример #20
0
 def _get_params(self):
     p = {}
     if self.help_text:
         p["help_text"] = utf8(self.help_text)
     if self._window_id:
         p["window_id"] = self._window_id
     return p
Пример #21
0
 def _get_params(self):
     p = {}
     if self.help_text:
         p['help_text'] = utf8(self.help_text)
     if self._window_id:
         p['window_id'] = self._window_id
     return p
Пример #22
0
    def get_removal_warning_text(self, cache, pkg, appname, depends):
        primary = _("To remove %s, these items must be removed "
                    "as well:") % utf8(appname)
        button_text = _("Remove All")

        # alter it if an important meta-package is affected
        for m in self.IMPORTANT_METAPACKAGES:
            if m in depends:
                primary = _("%s is a core item in Ubuntu. "
                            "Removing it may cause future upgrades "
                            "to be incomplete. Are you sure you want to "
                            "continue?") % appname
                button_text = _("Remove Anyway")
                depends = []
                break

        # alter it if a meta-package is affected
        for m in depends:
            if cache[m].section == "metapackages":
                primary = _("If you uninstall %s, future updates will not "
                            "include new items in <b>%s</b> set. "
                            "Are you sure you want to continue?") % (
                                appname, cache[m].installed.summary)
                button_text = _("Remove Anyway")
                depends = []
                break

        return (primary, button_text)
Пример #23
0
 def spawn_write_new_review_ui(self, translated_app, version, iconname,
                               origin, parent_xid, datadir):
     """ this spawns the UI for writing a new review and
         adds it automatically to the reviews DB """
     app = translated_app.get_untranslated_app(self.db)
     cmd = [
         os.path.join(datadir, RNRApps.SUBMIT_REVIEW),
         "--pkgname",
         app.pkgname,
         "--iconname",
         iconname,
         "--parent-xid",
         "%s" % parent_xid,
         "--version",
         version,
         "--origin",
         origin,
         "--datadir",
         datadir,
     ]
     if app.appname:
         # needs to be (utf8 encoded) str, otherwise call fails
         cmd += ["--appname", utf8(app.appname)]
     spawn_helper = SpawnHelper(format="json")
     spawn_helper.connect("data-available", self._on_submit_review_data,
                          app)
     spawn_helper.connect("exited", self._on_exited_callback, app)
     spawn_helper.connect("error", self._on_error_callback, app)
     spawn_helper.run(cmd)
Пример #24
0
 def _get_params(self):
     p = {}
     if self.help_text:
         p['help_text'] = utf8(self.help_text)
     if self._window_id:
         p['window_id'] = self._window_id
     return p
    def get_removal_warning_text(self, cache, pkg, appname, depends):
        primary = _("To remove %s, these items must be removed "
                    "as well:") % utf8(appname)
        button_text = _("Remove All")

        # alter it if a meta-package is affected
        for m in depends:
            if cache[m].section == "metapackages":
                primary = _("If you uninstall %s, future updates will not "
                            "include new items in <b>%s</b> set. "
                            "Are you sure you want to continue?") % (
                                appname, cache[m].installed.summary)
                button_text = _("Remove Anyway")
                depends = []
                break

        # alter it if an important meta-package is affected
        for m in self.IMPORTANT_METAPACKAGES:
            if m in depends:
                primary = _("%s is a core application in elementary OS. "
                            "Uninstalling it may cause future upgrades "
                            "to be incomplete. Are you sure you want to "
                            "continue?") % appname
                button_text = _("Remove Anyway")
                depends = None
                break
        return (primary, button_text)
Пример #26
0
 def __str__(self):
     s = utf8('%s %s "%s" %s %s') % \
                               (self.category,
                                self.subcategory,
                                self.search_term,
                                self.application,
                                self.channel)
     return s
Пример #27
0
 def __str__(self):
     s = utf8('%s %s "%s" %s %s') % \
                               (self.category,
                                self.subcategory,
                                self.search_term,
                                self.application,
                                self.channel)
     return s
Пример #28
0
 def test_hardware_requirements_label_utf8(self, mock_get_hw):
     magic_marker = u" \u1234 GPS"
     mock_get_hw.return_value = utf8(magic_marker)
     label = HardwareRequirementsLabel()
     label.set_hardware_requirement('hardware::gps', 'yes')
     self.assertEqual(
         label.get_label(), u"%s%s" %
         (HardwareRequirementsLabel.SUPPORTED_SYM["yes"], magic_marker))
 def warning(self):
     # FIXME: use more concise warnings
     if self._deb:
         deb_state = self._deb.compare_to_version_in_cache(
             use_installed=False)
         if deb_state == DebPackage.VERSION_NONE:
             return utf8(
                 _("Only install this file if you trust the origin."))
         elif (not self._cache[self.pkgname].installed
               and self._cache[self.pkgname].candidate
               and self._cache[self.pkgname].candidate.downloadable):
             if deb_state == DebPackage.VERSION_OUTDATED:
                 return utf8(
                     _("Please install \"%s\" via your normal "
                       "software channels. Only install this file if you "
                       "trust the origin.")) % utf8(self.name)
             elif deb_state == DebPackage.VERSION_SAME:
                 return utf8(
                     _("Please install \"%s\" via your normal "
                       "software channels. Only install this file if you "
                       "trust the origin.")) % utf8(self.name)
             elif deb_state == DebPackage.VERSION_NEWER:
                 return utf8(
                     _("An older version of \"%s\" is available in "
                       "your normal software channels. Only install this "
                       "file if you trust the origin.")) % utf8(self.name)
Пример #30
0
 def test_get_hw_missing_long_description(self):
     s = get_hw_missing_long_description(
         { "hardware::input:keyboard": "yes",
           OPENGL_DRIVER_BLACKLIST_TAG + "intel": "no",
         })
     self.assertEqual(s,
                      utf8(u'This software does not work with the '
                           u'\u201cintel\u201D graphics driver this '
                           u'computer is using.'))
Пример #31
0
 def test_get_hw_missing_long_description(self):
     s = get_hw_missing_long_description(
         { "hardware::input:keyboard": "yes",
           OPENGL_DRIVER_BLACKLIST_TAG + "intel": "no",
         })
     self.assertEqual(s, 
                      utf8(u'This software does not work with the '
                           u'\u201cintel\u201D graphics driver this '
                           u'computer is using.'))
Пример #32
0
 def test_hardware_requirements_label_utf8(self, mock_get_hw):
     magic_marker = u" \u1234 GPS"
     mock_get_hw.return_value = utf8(magic_marker)
     label = HardwareRequirementsLabel()
     label.set_hardware_requirement('hardware::gps', 'yes')
     self.assertEqual(
         label.get_label(),
         u"%s%s" % (HardwareRequirementsLabel.SUPPORTED_SYM["yes"],
                    magic_marker))
Пример #33
0
def add_from_purchased_but_needs_reinstall_data(
        purchased_but_may_need_reinstall_list, db, cache):
    """Add application that have been purchased but may require a reinstall
    
    This adds a inmemory database to the main db with the special
    PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME channel prefix

    :return: a xapian query to get all the apps that need reinstall
    """
    # magic
    db_purchased = xapian.inmemory_open()
    # go over the items we have
    for item in purchased_but_may_need_reinstall_list:
        # FIXME: what to do with duplicated entries? we will end
        #        up with two xapian.Document, one for the for-pay
        #        and one for the availalbe one from s-c-agent
        #try:
        #    db.get_xapian_document(item.name,
        #                           item.package_name)
        #except IndexError:
        #    # item is not in the xapian db
        #    pass
        #else:
        #    # ignore items we already have in the db, ignore
        #    continue
        # index the item
        try:
            # we fake a channel here
            item.channel = PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME
            # and empty category to make the parser happy
            item.categories = ""
            # WARNING: item.name needs to be different than
            #          the item.name in the DB otherwise the DB
            #          gets confused about (appname, pkgname) duplication
            item.name = utf8(_("%s (already purchased)")) % utf8(item.name)
            parser = SoftwareCenterAgentParser(item)
            index_app_info_from_parser(parser, db_purchased, cache)
        except Exception as e:
            LOG.exception("error processing: %s " % e)
    # add new in memory db to the main db
    db.add_database(db_purchased)
    # return a query
    query = xapian.Query("AH" + PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME)
    return query
Пример #34
0
def add_from_purchased_but_needs_reinstall_data(purchased_but_may_need_reinstall_list, db, cache):
    """Add application that have been purchased but may require a reinstall
    
    This adds a inmemory database to the main db with the special
    PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME channel prefix

    :return: a xapian query to get all the apps that need reinstall
    """
    # magic
    db_purchased = xapian.inmemory_open()
    # go over the items we have
    for item in purchased_but_may_need_reinstall_list:
        # FIXME: what to do with duplicated entries? we will end
        #        up with two xapian.Document, one for the for-pay
        #        and one for the availalbe one from s-c-agent
        #try:
        #    db.get_xapian_document(item.name,
        #                           item.package_name)
        #except IndexError:
        #    # item is not in the xapian db
        #    pass
        #else:
        #    # ignore items we already have in the db, ignore
        #    continue
        # index the item
        try:
            # we fake a channel here
            item.channel = PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME
            # and empty category to make the parser happy
            item.categories = ""
            # WARNING: item.name needs to be different than
            #          the item.name in the DB otherwise the DB
            #          gets confused about (appname, pkgname) duplication
            item.name = utf8(_("%s (already purchased)")) % utf8(item.name)
            parser = SoftwareCenterAgentParser(item)
            index_app_info_from_parser(parser, db_purchased, cache)
        except Exception as e:
            LOG.exception("error processing: %s " % e)
    # add new in memory db to the main db
    db.add_database(db_purchased)
    # return a query
    query = xapian.Query("AH"+PURCHASED_NEEDS_REINSTALL_MAGIC_CHANNEL_NAME)
    return query
Пример #35
0
    def get_title_text(self, term, category, state):
        from softwarecenter.utils import utf8

        def build_category_path():
            if not category:
                return ''
            if not state.subcategory:
                return category.name
            plain_text = _("%(category_name)s → %(subcategory_name)s")
            usable_text = unicode(plain_text, 'utf8').encode('utf8')
            return usable_text % {'category_name': category.name,
                                  'subcategory_name': state.subcategory.name}

        if not category:
            sub = utf8(_(u"No items match “%s”")) % term
        else:
            sub = utf8(_(u"No items in %s match “%s”"))
            sub = sub % (build_category_path(), term)

        return self.HEADER_MARKUP % GLib.markup_escape_text(sub)
Пример #36
0
    def get_install_warning_text(self, cache, pkg, appname, depends):
        primary = (utf8(_("To install %s, these items must be removed:")) %
                   utf8(appname))
        button_text = _("Install Anyway")

        # alter it if a meta-package is affected
        for m in depends:
            if cache[m].section == "metapackages":
                primary = utf8(
                    _("If you install %s, future updates will not "
                      "include new items in <b>%s</b> set. "
                      "Are you sure you want to continue?")) % (
                          utf8(appname), cache[m].installed.summary)
                button_text = _("Install Anyway")
                depends = []
                break

        # alter it if an important meta-package is affected
        for m in self.IMPORTANT_METAPACKAGES:
            if m in depends:
                primary = utf8(
                    _("Installing %s may cause core applications "
                      "to be removed. Are you sure you want to "
                      "continue?")) % utf8(appname)
                button_text = _("Install Anyway")
                depends = None
                break
        return (primary, button_text)
Пример #37
0
    def get_install_warning_text(self, cache, pkg, appname, depends):
        primary = utf8(_("To install %s, these items must be removed:")) % utf8(appname)
        button_text = _("Install Anyway")

        # alter it if a meta-package is affected
        for m in depends:
            if cache[m].section == "metapackages":
                primary = utf8(
                    _(
                        "If you install %s, future updates will not "
                        "include new items in <b>%s</b> set. "
                        "Are you sure you want to continue?"
                    )
                ) % (utf8(appname), cache[m].installed.summary)
                button_text = _("Install Anyway")
                depends = []
                break

        # alter it if an important meta-package is affected
        for m in self.IMPORTANT_METAPACKAGES:
            if m in depends:
                primary = utf8(
                    _(
                        "Installing %s may cause core applications "
                        "to be removed. Are you sure you want to "
                        "continue?"
                    )
                ) % utf8(appname)
                button_text = _("Install Anyway")
                depends = None
                break
        return (primary, button_text)
Пример #38
0
    def get_title_text(self, term, category, state):
        from softwarecenter.utils import utf8

        def build_category_path():
            if not category:
                return ''
            if not state.subcategory:
                return category.name
            plain_text = _("%(category_name)s → %(subcategory_name)s")
            usable_text = unicode(plain_text, 'utf8').encode('utf8')
            return usable_text % {
                'category_name': category.name,
                'subcategory_name': state.subcategory.name
            }

        if not category:
            sub = utf8(_(u"No items match “%s”")) % term
        else:
            sub = utf8(_(u"No items in %s match “%s”"))
            sub = sub % (build_category_path(), term)

        return self.HEADER_MARKUP % GObject.markup_escape_text(sub)
Пример #39
0
    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise DebFileOpenError("AppDetailsDebFile: doc must be None.")

        self._error = None
        self._deb = None

        # check errors before creating the DebPackage
        if not os.path.exists(self._app.request):
            self._error = _("Not found")
            self._error_not_found = utf8(
                _(u"The file \u201c%s\u201d "
                  "does not exist.")) % utf8(self._app.request)
        elif not is_deb_file(self._app.request):
            self._error = _("Not found")
            self._error_not_found = utf8(
                _(u"The file \u201c%s\u201d "
                  "is not a software package.")) % utf8(self._app.request)

        if self._error is not None:
            return

        try:
            with ExecutionTime("create DebPackage"):
                # Cache() used to be faster here than self._cache._cache
                # but that is no longer the case with the latest apt
                self._deb = DebPackage(self._app.request, self._cache._cache)
        except:
            # deb files which are corrupt
            self._error = _("Internal Error")
            self._error_not_found = utf8(
                _(u"The file \u201c%s\u201d "
                  "could not be opened.")) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache
                    and self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string.strip()
Пример #40
0
    def configure_geometry(self, layout):
        self._layout_reset(layout)
        max_size = (0, 0)

        for k, variant in self.markup_variants.items():
            safe_markup = GLib.markup_escape_text(utf8(variant))
            layout.set_markup(safe_markup, -1)
            size = layout.get_size()
            max_size = max(max_size, size)

        w, h = max_size
        w /= Pango.SCALE
        h /= Pango.SCALE

        self.set_size(w + 2 * self.xpad, h + 2 * self.ypad)
Пример #41
0
    def configure_geometry(self, layout):
        self._layout_reset(layout)
        max_size = (0, 0)

        for k, variant in self.markup_variants.items():
            safe_markup = GObject.markup_escape_text(utf8(variant))
            layout.set_markup(safe_markup, -1)
            size = layout.get_size()
            max_size = max(max_size, size)

        w, h = max_size
        w /= Pango.SCALE
        h /= Pango.SCALE

        self.set_size(w + 2 * self.xpad, h + 2 * self.ypad)
Пример #42
0
    def _whom_when_markup(self, person, displayname, cur_t):
        nice_date = get_nice_date_string(cur_t)
        #dt = datetime.datetime.utcnow() - cur_t

        # prefer displayname if available
        correct_name = displayname or person

        if person == self.logged_in_person:
            m = '%s (%s), %s' % (
                GLib.markup_escape_text(utf8(correct_name)),
                # TRANSLATORS: displayed in a review after the persons name,
                # e.g. "Jane Smith (that's you), 2011-02-11"
                utf8(_(u"that\u2019s you")),
                GLib.markup_escape_text(utf8(nice_date)))
        else:
            try:
                m = '%s, %s' % (GLib.markup_escape_text(
                    correct_name.encode("utf-8")),
                                GLib.markup_escape_text(nice_date))
            except Exception:
                LOG.exception("_who_when_markup failed")
                m = "Error parsing name"

        return m
Пример #43
0
    def _whom_when_markup(self, person, displayname, cur_t):
        nice_date = get_nice_date_string(cur_t)
        #dt = datetime.datetime.utcnow() - cur_t

        # prefer displayname if available
        correct_name = displayname or person

        if person == self.logged_in_person:
            m = '%s (%s), %s' % (
                GLib.markup_escape_text(utf8(correct_name)),
                # TRANSLATORS: displayed in a review after the persons name,
                # e.g. "Jane Smith (that's you), 2011-02-11"
                utf8(_(u"that\u2019s you")),
                GLib.markup_escape_text(utf8(nice_date)))
        else:
            try:
                m = '%s, %s' % (
                    GLib.markup_escape_text(correct_name.encode("utf-8")),
                    GLib.markup_escape_text(nice_date))
            except Exception:
                LOG.exception("_who_when_markup failed")
                m = "Error parsing name"

        return m
Пример #44
0
    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise DebFileOpenError("AppDetailsDebFile: doc must be None.")

        self._error = None
        self._deb = None

        # check errors before creating the DebPackage
        if not os.path.exists(self._app.request):
            self._error = _("Not found")
            self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                "does not exist.")) % utf8(self._app.request)
        elif not is_deb_file(self._app.request):
            self._error = _("Not found")
            self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                "is not a software package.")) % utf8(self._app.request)

        if self._error is not None:
            return

        try:
            with ExecutionTime("create DebPackage"):
                # Cache() used to be faster here than self._cache._cache
                # but that is no longer the case with the latest apt
                self._deb = DebPackage(self._app.request, self._cache._cache)
        except:
            # deb files which are corrupt
            self._error = _("Internal Error")
            self._error_not_found = utf8(_(u"The file \u201c%s\u201d "
                "could not be opened.")) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache and
                    self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string.strip()
Пример #45
0
    def __init__(self, db, doc=None, application=None):
        super(AppDetailsDebFile, self).__init__(db, doc, application)
        if doc:
            raise ValueError("doc must be None for deb files")

        try:
            # for some reason Cache() is much faster than "self._cache._cache"
            # on startup
            with ExecutionTime("create DebPackage"):
                self._deb = DebPackage(self._app.request, Cache())
        except:
            self._deb = None
            self._pkg = None
            if not os.path.exists(self._app.request):
                self._error = _("Not found")
                self._error_not_found = utf8(
                    _(u"The file \u201c%s\u201d does not exist.")) % utf8(
                        self._app.request)
            else:
                mimetype = guess_type(self._app.request)
                if mimetype[0] != "application/x-debian-package":
                    self._error = _("Not found")
                    self._error_not_found = utf8(
                        _(u"The file \u201c%s\u201d is not a software package."
                          )) % utf8(self._app.request)
                else:
                    # deb files which are corrupt
                    self._error = _("Internal Error")
                    self._error_not_found = utf8(
                        _(u"The file \u201c%s\u201d could not be opened.")
                    ) % utf8(self._app.request)
            return

        if self.pkgname and self.pkgname != self._app.pkgname:
            # this happens when the deb file has a quirky file name
            self._app.pkgname = self.pkgname

            # load pkg cache
            self._pkg = None
            if (self._app.pkgname in self._cache
                    and self._cache[self._app.pkgname].candidate):
                self._pkg = self._cache[self._app.pkgname]
            # load xapian document
            self._doc = None
            try:
                self._doc = self._db.get_xapian_document(
                    self._app.appname, self._app.pkgname)
            except:
                pass

        # check deb and set failure state on error
        with ExecutionTime("AppDetailsDebFile._deb.check()"):
            if not self._deb.check():
                self._error = self._deb._failure_string
Пример #46
0
 def __init__(self, appname="", pkgname="", request="", popcon=0):
     if not (appname or pkgname):
         raise ValueError("Need either appname or pkgname or request")
     # defaults
     self.pkgname = pkgname.replace("$kernel", os.uname()[2])
     if appname:
         self.appname = utf8(appname)
     else:
         self.appname = ''
     # the request can take additional "request" data like apturl
     # strings or the path of a local deb package
     self.request = request
     self._popcon = popcon
     # a "?" in the name means its a apturl request
     if "?" in pkgname:
         # the bit before the "?" is the pkgname, everything else the req
         (self.pkgname, sep, self.request) = pkgname.partition("?")
Пример #47
0
 def __init__(self, appname="", pkgname="", request="", popcon=0):
     if not (appname or pkgname):
         raise ValueError("Need either appname or pkgname or request")
     # defaults
     self.pkgname = pkgname.replace("$kernel", os.uname()[2])
     if appname:
         self.appname = utf8(appname)
     else:
         self.appname = ''
     # the request can take additional "request" data like apturl
     # strings or the path of a local deb package
     self.request = request
     self._popcon = popcon
     # a "?" in the name means its a apturl request
     if "?" in pkgname:
         # the bit before the "?" is the pkgname, everything else the req
         (self.pkgname, sep, self.request) = pkgname.partition("?")
Пример #48
0
def get_hw_missing_long_description(tags):
    s = ""
    # build string
    for tag, supported in tags.iteritems():
        if supported == "no":
            descr = TAG_MISSING_DESCRIPTION.get(tag)
            if descr:
                s += "%s\n" % descr
            else:
                # deal with generic tags
                prefix, sep, postfix = tag.rpartition(":")
                descr = TAG_MISSING_DESCRIPTION.get(prefix + sep)
                descr = descr % postfix
                if descr:
                    s += "%s\n" % descr
    # ensure that the last \n is gone
    if s:
        s = s[:-1]
    return utf8(_(s))
Пример #49
0
def get_hw_missing_long_description(tags):
    s = ""
    # build string
    for tag, supported in tags.iteritems():
        if supported == "no":
            descr = TAG_MISSING_DESCRIPTION.get(tag)
            if descr:
                s += "%s\n" % descr
            else:
                # deal with generic tags
                prefix, sep, postfix = tag.rpartition(":")
                descr = TAG_MISSING_DESCRIPTION.get(prefix + sep)
                descr = descr % postfix
                if descr:
                    s += "%s\n" % descr
    # ensure that the last \n is gone
    if s:
        s = s[:-1]
    return utf8(_(s))
Пример #50
0
 def spawn_write_new_review_ui(self, translated_app, version, iconname, 
                               origin, parent_xid, datadir, callback):
     """ this spawns the UI for writing a new review and
         adds it automatically to the reviews DB """
     app = translated_app.get_untranslated_app(self.db)
     cmd = [os.path.join(datadir, RNRApps.SUBMIT_REVIEW), 
            "--pkgname", app.pkgname,
            "--iconname", iconname,
            "--parent-xid", "%s" % parent_xid,
            "--version", version,
            "--origin", origin,
            "--datadir", datadir,
            ]
     if app.appname:
         # needs to be (utf8 encoded) str, otherwise call fails
         cmd += ["--appname", utf8(app.appname)]
     spawn_helper = SpawnHelper(format="json")
     spawn_helper.connect(
         "data-available", self._on_submit_review_data, app, callback)
     spawn_helper.run(cmd)
Пример #51
0
 def __init__(self, appname="", pkgname="", request="", popcon=0):
     if not (appname or pkgname):
         raise ValueError("Need either appname or pkgname or request")
     # defaults
     self.pkgname = pkgname.replace("$kernel", os.uname()[2])
     if appname:
         self.appname = utf8(appname)
     else:
         self.appname = ''
     # the request can take additional "request" data like apturl
     # strings or the path of a local deb package
     self.request = request
     # a archive_suite can be used to force a specific version that
     # would not be installed automatically (like ubuntu-backports)
     self.archive_suite = ""
     # popcon
     self._popcon = popcon
     # a "?" in the name means its a apturl request
     if "?" in pkgname:
         # the bit before the "?" is the pkgname, everything else the req
         (self.pkgname, sep, self.request) = pkgname.partition("?")
Пример #52
0
    def pkg_state(self):
        # puchase state
        if self.pkgname in self._backend.pending_purchases:
            return PkgStates.INSTALLING_PURCHASED

        # via the pending transactions dict
        if self.pkgname in self._backend.pending_transactions:
            # FIXME: we don't handle upgrades yet
            # if there is no self._pkg yet, that means this is a INSTALL
            # from a previously not-enabled source (like a purchase)
            if self._pkg and self._pkg.installed:
                return PkgStates.REMOVING
            else:
                return PkgStates.INSTALLING

        # if we have _pkg that means its either:
        # - available for download (via sources.list)
        # - locally installed
        # - intalled and available for download
        # - installed but the user wants to switch versions between
        #   not-automatic channels (like experimental/backports)
        if self._pkg:
            if self._pkg.installed and self._app.archive_suite:
                archive_suites = [origin.archive
                                  for origin in self._pkg.installed.origins]
                if not self._app.archive_suite in archive_suites:
                    return PkgStates.FORCE_VERSION
            # Don't handle upgrades yet, see bug LP #976525 we need more UI
            # for this
            #if self._pkg.installed and self._pkg.is_upgradable:
            #    return PkgStates.UPGRADABLE
            if self._pkg.is_installed:
                return PkgStates.INSTALLED
            else:
                return PkgStates.UNINSTALLED
        # if we don't have a _pkg, then its either:
        #  - its in a unavailable repo
        #  - the repository information is outdated
        #  - the repository information is missing (/var/lib/apt/lists empty)
        #  - its a failure in our meta-data (e.g. typo in the pkgname in
        #    the metadata)
        if not self._pkg:
            if self.channelname:
                if self._unavailable_channel():
                    return PkgStates.NEEDS_SOURCE
                else:
                    self._error = _("Not found")
                    self._error_not_found = utf8(
                        _(u"There isn\u2019t a "
                          u"software package called \u201c%s\u201D in your "
                          u"current software sources.")) % utf8(self.pkgname)
                    return PkgStates.NOT_FOUND
            else:
                if self.price:
                    return PkgStates.NEEDS_PURCHASE
                if (self.purchase_date and
                    self._doc.get_value(XapianValues.ARCHIVE_DEB_LINE)):
                    supported_distros = self.supported_distros

                    # Until bug 917109 is fixed on the server we won't have
                    # any supported_distros for a for-purchase app, so we
                    # follow the current behaviour in this case.
                    if not supported_distros:
                        return PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED

                    current_distro = self._distro.get_codename()
                    current_arch = self._distro.get_architecture()
                    if current_distro in supported_distros and (
                        current_arch in supported_distros[current_distro] or
                        'any' in supported_distros[current_distro]):
                        return PkgStates.PURCHASED_BUT_REPO_MUST_BE_ENABLED
                    else:
                        return PkgStates.PURCHASED_BUT_NOT_AVAILABLE_FOR_SERIES

                if self.component:
                    components = self.component.split('&')
                    for component in components:
                        if component and self._unavailable_component(
                            component_to_check=component):
                            return PkgStates.NEEDS_SOURCE
                self._error = _("Not found")
                self._error_not_found = utf8(
                    _(u"There isn\u2019t a software "
                      u"package called \u201c%s\u201D in your current "
                      u"software sources.")) % utf8(self.pkgname)
                return PkgStates.NOT_FOUND
        return PkgStates.UNKNOWN
Пример #53
0
 def __str__(self):
     return utf8("%s,%s") % (utf8(self.appname), utf8(self.pkgname))
Пример #54
0
 def __hash__(self):
     return utf8("%s:%s" % (
             utf8(self.appname), utf8(self.pkgname))).__hash__()
 def __str__(self):
     facet = self.pane.pane_name.replace(' ', '')[:6]
     result = utf8("%s:%s %s") % (facet, self.page, self.view_state)
     return result
 def summary(self):
     if self._deb:
         description = self._deb._sections["Description"]
         # ensure its utf8(), see #738771
         return utf8(description.split('\n')[0])