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

« back to all changes in this revision

Viewing changes to apt_xapian_index_plugin/display_name.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:
 
1
import apt_pkg
 
2
import os
 
3
 
 
4
 
 
5
class DisplayNames:
 
6
 
 
7
    def info(self):
 
8
        """
 
9
        Return general information about the plugin.
 
10
 
 
11
        The information returned is a dict with various keywords:
 
12
 
 
13
         timestamp (required)
 
14
           the last modified timestamp of this data source.  This will be used
 
15
           to see if we need to update the database or not.  A timestamp of 0
 
16
           means that this data source is either missing or always up to date.
 
17
         values (optional)
 
18
           an array of dicts { name: name, desc: description }, one for every
 
19
           numeric value indexed by this data source.
 
20
 
 
21
        Note that this method can be called before init.  The idea is that, if
 
22
        the timestamp shows that this plugin is currently not needed, then the
 
23
        long initialisation can just be skipped.
 
24
        """
 
25
        file = apt_pkg.config.find_file("Dir::Cache::pkgcache")
 
26
        if not os.path.exists(file):
 
27
            return dict(timestamp=0)
 
28
        return dict(
 
29
                timestamp=os.path.getmtime(file),
 
30
                values=[
 
31
                    dict(name="display_name", desc="display name"),
 
32
                    dict(name="pkgname", desc="Pkgname as value"),
 
33
                ])
 
34
 
 
35
    def doc(self):
 
36
        """
 
37
        Return documentation information for this data source.
 
38
 
 
39
        The documentation information is a dictionary with these keys:
 
40
          name: the name for this data source
 
41
          shortDesc: a short description
 
42
          fullDoc: the full description as a chapter in ReST format
 
43
        """
 
44
        return dict(
 
45
            name="DisplayNames",
 
46
            shortDesc="pkgname and package display names indexed as values",
 
47
            fullDoc="""
 
48
            The DisplayNames data source indexes the display name as the
 
49
            ``display_name`` Xapian value.
 
50
            ``pkgname`` Xapian value.
 
51
            """)
 
52
 
 
53
    def init(self, info, progress):
 
54
        """
 
55
        If needed, perform long initialisation tasks here.
 
56
 
 
57
        info is a dictionary with useful information.  Currently it contains
 
58
        the following values:
 
59
 
 
60
          "values": a dict mapping index mnemonics to index numbers
 
61
 
 
62
        The progress indicator can be used to report progress.
 
63
        """
 
64
        # Read the value indexes we will use
 
65
        values = info['values']
 
66
        self.val_display_name = values.get("display_name", -1)
 
67
        self.val_pkgname = values.get("pkgname", -1)
 
68
 
 
69
    def index(self, document, pkg):
 
70
        """
 
71
        Update the document with the information from this data source.
 
72
 
 
73
        document  is the document to update
 
74
        pkg       is the python-apt Package object for this package
 
75
        """
 
76
        ver = pkg.candidate
 
77
        if ver is None:
 
78
            return
 
79
        if self.val_display_name != -1:
 
80
            name = ver.summary
 
81
            document.add_value(self.val_display_name, name)
 
82
        if self.val_pkgname != -1:
 
83
            document.add_value(self.val_pkgname, pkg.name)
 
84
 
 
85
    def indexDeb822(self, document, pkg):
 
86
        """
 
87
        Update the document with the information from this data source.
 
88
 
 
89
        This is alternative to index, and it is used when indexing with package
 
90
        data taken from a custom Packages file.
 
91
 
 
92
        document  is the document to update
 
93
        pkg       is the Deb822 object for this package
 
94
        """
 
95
        return
 
96
 
 
97
 
 
98
def init():
 
99
    """
 
100
    Create and return the plugin object.
 
101
    """
 
102
    return DisplayNames()