~nik90/ubuntu/precise/software-center/add_keywords

« back to all changes in this revision

Viewing changes to softwarecenter/db/categories.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Brendan Donegan, Gary Lasker
  • Date: 2012-02-03 18:34:43 UTC
  • Revision ID: package-import@ubuntu.com-20120203183443-1r39x52ozrb1revz
Tags: 5.1.8
[ Michael Vogt ]
* softwarecenter/db/update.py:
  - trivial fix to skip unreadable app-install-data files
* lp:~mvo/software-center/device-profiles:
  - implement the hardware-requirements display in
    the detailsview
* lp:~mvo/software-center/arb-partner-channels:
  - add support for extras.ubuntu.com and archive.canonical.com
    channel detection and adding via software-center-agent
* data/software-center.menu.in:
  - do not show "X-Publishing" in education because the
    software-center-agent will send "X-Publishing;Education" for
    compatibility with the old clients
* lp:~mvo/software-center/fix-cachedir-for-public-api:
  - add missing cachedir argument
* lp:~mvo/software-center/region-support:
  - add support for a region tag and display a warning to
    the user if an application is not suitable for their
    region

[ Brendan Donegan ]
* lp:~brendan-donegan/software-center/test_utils_get_nice_date_string:
  - add a test function in test_utils.py which covers all of
    get_nice_date_string

[ Gary Lasker ]
* lp:~gary-lasker/software-center/launcher-integration-lp761851:
  - update to the Unity launcher integration implementation to
    support the revamped functionality on the Unity side (LP: #761851) 
* lp:~gary-lasker/software-center/recommends-ui-lobby:
  - initial recommends UI implementation, limited to non-personalized
    recommends currently
* lp:~gary-lasker/software-center/appdetailsview-button-focus-fix:
  - make sure the action button in the applications details view
    always gets the initial focus (LP: #925613)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# this program; if not, write to the Free Software Foundation, Inc.,
17
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
 
19
from gi.repository import GObject
19
20
import gettext
20
21
import glob
21
22
import locale
27
28
from xml.sax.saxutils import escape as xml_escape
28
29
from xml.sax.saxutils import unescape as xml_unescape
29
30
 
30
 
from softwarecenter.enums import SortMethods
 
31
from softwarecenter.enums import (
 
32
    SortMethods, NonAppVisibility)
 
33
from softwarecenter.backend.recommends import RecommenderAgent
 
34
from softwarecenter.db.appfilter import AppFilter
 
35
from softwarecenter.db.enquire import AppEnquire
 
36
from softwarecenter.db.utils import get_query_for_pkgnames
 
37
from softwarecenter.paths import APP_INSTALL_PATH
 
38
 
 
39
from gettext import gettext as _
31
40
 
32
41
# not possible not use local logger
33
42
LOG = logging.getLogger(__name__)
55
64
                sorted_cats.append(cat)
56
65
                break
57
66
    return sorted_cats
58
 
 
59
 
 
60
 
class Category(object):
 
67
        
 
68
def get_query_for_category(db, untranslated_category_name):
 
69
    cat_parser = CategoriesParser(db)
 
70
    categories = cat_parser.parse_applications_menu(APP_INSTALL_PATH)
 
71
    for c in categories:
 
72
        if untranslated_category_name == c.untranslated_name:
 
73
            query = c.query
 
74
            return query
 
75
    return False
 
76
 
 
77
 
 
78
class Category(GObject.GObject):
61
79
    """represents a menu category"""
62
80
    def __init__(self, untranslated_name, name, iconname, query,
63
81
                 only_unallocated=True, dont_display=False, flags=[], 
64
82
                 subcategories=[], sortmode=SortMethods.BY_ALPHABET,
65
83
                 item_limit=0):
 
84
        GObject.GObject.__init__(self)
66
85
        if type(name) == str:
67
86
            self.name = unicode(name, 'utf8').encode('utf8')
68
87
        else:
83
102
    def is_forced_sort_mode(self):
84
103
        return (self.sortmode != SortMethods.BY_ALPHABET)
85
104
 
 
105
    def get_documents(self, db):
 
106
        """ return the database docids for the given category """
 
107
        enq = AppEnquire(db._aptcache, db)
 
108
        app_filter = AppFilter(db, db._aptcache)
 
109
        if "available-only" in self.flags:
 
110
            app_filter.set_available_only(True)
 
111
        if "not-installed-only" in self.flags:
 
112
            app_filter.set_not_installed_only(True)
 
113
        enq.set_query(self.query,
 
114
                      limit=self.item_limit,
 
115
                      filter=app_filter,
 
116
                      sortmode=self.sortmode,
 
117
                      nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
 
118
                      nonblocking_load=False)
 
119
        return enq.get_documents()
 
120
 
86
121
    def __str__(self):
87
122
        return "<Category: name='%s', sortmode='%s', "\
88
123
               "item_limit='%s'>" % (
89
124
                   self.name, self.sortmode, self.item_limit)
90
125
 
 
126
 
 
127
class RecommendedForYouCategory(Category):
 
128
 
 
129
    __gsignals__ = {
 
130
        "needs-refresh" : (GObject.SIGNAL_RUN_LAST,
 
131
                           GObject.TYPE_NONE, 
 
132
                           (),
 
133
                          ),
 
134
        "recommender-agent-error" : (GObject.SIGNAL_RUN_LAST,
 
135
                                     GObject.TYPE_NONE, 
 
136
                                     (GObject.TYPE_STRING,),
 
137
                                    ),
 
138
        }
 
139
 
 
140
    def __init__(self):
 
141
        super(RecommendedForYouCategory, self).__init__(
 
142
            u"Recommended for You", _("Recommended for You"), None, 
 
143
            xapian.Query(),flags=['available-only', 'not-installed-only'], 
 
144
            item_limit=60)
 
145
        self.recommender_agent = RecommenderAgent()
 
146
        self.recommender_agent.connect(
 
147
            "recommend-top", self._recommend_top_result)
 
148
        self.recommender_agent.connect(
 
149
            "error", self._recommender_agent_error)
 
150
        self.recommender_agent.query_recommend_top()
 
151
 
 
152
    def _recommend_top_result(self, recommender_agent, result_list):
 
153
        pkgs = []
 
154
        for item in result_list['recommendations']:
 
155
            pkgs.append(item['package_name'])
 
156
        self.query = get_query_for_pkgnames(pkgs)
 
157
        self.emit("needs-refresh")
 
158
 
 
159
    def _recommender_agent_error(self, recommender_agent, msg):
 
160
        LOG.warn("Error while accessing the recommender service: %s" 
 
161
                                                            % msg)
 
162
        self.emit("recommender-agent-error", msg)
 
163
 
91
164
class CategoriesParser(object):
92
165
    """ 
93
166
    Parser that is able to read the categories from a menu file
328
401
            #print cat_unalloc.name, cat_unalloc.query
329
402
        return
330
403
 
 
404
 
331
405
# static category mapping for the tiles
332
406
 
333
407
category_cat = {
345
419
'Video': 'Sound & Video',
346
420
'Settings': 'Themes & Tweaks',
347
421
'Accessibility': 'Universal Access',
348
 
'Development': 'Developer Tools',}
 
422
'Development': 'Developer Tools',
 
423
'X-Publishing': 'Books & Magazines',
 
424
}
349
425
 
350
426
category_subcat = {
351
427
'BoardGame': 'Games;Board Games',