~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to softwarecenter/db/database.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import threading
25
25
import xapian
26
26
from softwarecenter.db.application import Application
27
 
from softwarecenter.db.utils import get_query_for_pkgnames
28
27
from softwarecenter.db.pkginfo import get_pkg_info
29
28
import softwarecenter.paths
30
29
 
31
30
from gi.repository import GObject, Gio
32
31
 
33
 
#from softwarecenter.utils import *
 
32
from softwarecenter.utils import ExecutionTime
34
33
from softwarecenter.enums import (
35
34
    AVAILABLE_FOR_PURCHASE_MAGIC_CHANNEL_NAME,
36
35
    PkgStates,
43
42
LOG = logging.getLogger(__name__)
44
43
 
45
44
 
 
45
def get_reinstall_previous_purchases_query():
 
46
    """Return a query to get applications purchased
 
47
 
 
48
    :return: a xapian query to get all the apps that are purchaed
 
49
    """
 
50
    # this query will give us all documents that have a purchase date != ""
 
51
    query = xapian.Query(xapian.Query.OP_VALUE_GE,
 
52
                         XapianValues.PURCHASED_DATE,
 
53
                         "1")
 
54
    return query
 
55
 
 
56
 
46
57
def parse_axi_values_file(filename="/var/lib/apt-xapian-index/values"):
47
58
    """ parse the apt-xapian-index "values" file and provide the
48
59
    information in the self._axi_values dict
204
215
        xapian_parser.add_boolean_prefix("section", "XS")
205
216
        xapian_parser.add_boolean_prefix("origin", "XOC")
206
217
        xapian_parser.add_prefix("pkg_wildcard", "XP")
 
218
        xapian_parser.add_prefix("pkg_wildcard", "XPM")
207
219
        xapian_parser.add_prefix("pkg_wildcard", "AP")
 
220
        xapian_parser.add_prefix("pkg_wildcard", "APM")
208
221
        xapian_parser.set_default_op(xapian.Query.OP_AND)
209
222
        return xapian_parser
210
223
 
222
235
        # with the UI)
223
236
        self.nr_databases = 0
224
237
        self._use_axi = use_axi
 
238
        self._axi_values = {}
225
239
        self._use_agent = use_agent
226
240
        if use_axi:
227
241
            if self._axi_stamp_monitor:
287
301
        assert popcon_max > 0
288
302
        return popcon_max
289
303
 
 
304
    def get_query_for_pkgnames(self, pkgnames):
 
305
        """ return a xapian query that matches exactly the list of pkgnames """
 
306
        enquire = xapian.Enquire(self.xapiandb)
 
307
        query = xapian.Query()
 
308
        for pkgname in pkgnames:
 
309
            # even on the raspbery pi this query super quick (~0.003s)
 
310
            with ExecutionTime("de-dup query_for_pkgnames"):
 
311
                tmp_query = xapian.Query("AP" + pkgname)
 
312
                enquire.set_query(tmp_query)
 
313
                result = enquire.get_mset(0, 1)
 
314
            # see bug #1043159, we need to ensure that we de-duplicate
 
315
            # when there is a pkg and a app (e.g. from the s-c-agent) in the db
 
316
            if len(result) == 1:
 
317
                query = xapian.Query(xapian.Query.OP_OR,
 
318
                                     query,
 
319
                                     xapian.Query("AP" + pkgname))
 
320
            else:
 
321
                query = xapian.Query(xapian.Query.OP_OR,
 
322
                                     query,
 
323
                                     xapian.Query("XP" + pkgname))
 
324
        return query
 
325
 
290
326
    def get_query_list_from_search_entry(self, search_term,
291
327
        category_query=None):
292
328
        """ get xapian.Query from a search term string and a limit the
328
364
        search_term = search_term.strip()
329
365
        # get a pkg query
330
366
        if "," in search_term:
331
 
            pkg_query = get_query_for_pkgnames(search_term.split(","))
 
367
            pkg_query = self.get_query_for_pkgnames(search_term.split(","))
332
368
        else:
333
369
            pkg_query = xapian.Query()
334
370
            for term in search_term.split():
456
492
        iconname = doc.get_value(XapianValues.ICON)
457
493
        return iconname
458
494
 
 
495
    def get_desktopfile(self, doc):
 
496
        """ Return the desktopfile from the xapian document """
 
497
        desktopf = doc.get_value(XapianValues.DESKTOP_FILE)
 
498
        return desktopf
 
499
 
459
500
    def pkg_in_category(self, pkgname, cat_query):
460
501
        """ Return True if the given pkg is in the given category """
461
502
        pkg_query1 = xapian.Query("AP" + pkgname)