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

« back to all changes in this revision

Viewing changes to apt-xapian-index-plugin/origin.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
 
# Add origin tags to the index
2
 
 
3
 
import apt
4
 
import os
5
 
 
6
 
 
7
 
class OriginPlugin:
8
 
 
9
 
    def info(self):
10
 
        """
11
 
        Return general information about the plugin.
12
 
 
13
 
        The information returned is a dict with various keywords:
14
 
 
15
 
         timestamp (required)
16
 
           the last modified timestamp of this data source.  This will be used
17
 
           to see if we need to update the database or not.  A timestamp of 0
18
 
           means that this data source is either missing or always up to date.
19
 
         values (optional)
20
 
           an array of dicts { name: name, desc: description }, one for every
21
 
           numeric value indexed by this data source.
22
 
 
23
 
        Note that this method can be called before init.  The idea is that, if
24
 
        the timestamp shows that this plugin is currently not needed, then the
25
 
        long initialisation can just be skipped.
26
 
        """
27
 
        file = apt.apt_pkg.config.find_file("Dir::Cache::pkgcache")
28
 
        if not os.path.exists(file):
29
 
            return dict(timestamp=0)
30
 
        return dict(timestamp=os.path.getmtime(file))
31
 
 
32
 
    def init(self, info, progress):
33
 
        """
34
 
        If needed, perform long initialisation tasks here.
35
 
 
36
 
        info is a dictionary with useful information.  Currently it contains
37
 
        the following values:
38
 
 
39
 
          "values": a dict mapping index mnemonics to index numbers
40
 
 
41
 
        The progress indicator can be used to report progress.
42
 
        """
43
 
        pass
44
 
 
45
 
    def doc(self):
46
 
        """
47
 
        Return documentation information for this data source.
48
 
 
49
 
        The documentation information is a dictionary with these keys:
50
 
          name: the name for this data source
51
 
          shortDesc: a short description
52
 
          fullDoc: the full description as a chapter in ReST format
53
 
        """
54
 
        return dict(
55
 
            name="Origin",
56
 
            shortDesc="Origin information",
57
 
            fullDoc="""
58
 
            The Origin data source indexes origin information
59
 
            It uses the prefix XO
60
 
            """)
61
 
 
62
 
    def index(self, document, pkg):
63
 
        """
64
 
        Update the document with the information from this data source.
65
 
 
66
 
        document  is the document to update
67
 
        pkg       is the python-apt Package object for this package
68
 
        """
69
 
        ver = pkg.candidate
70
 
        if ver is None:
71
 
            return
72
 
        if not ver.downloadable:
73
 
            document.add_term("XOL" + "notdownloadable")
74
 
        for origin in ver.origins:
75
 
            document.add_term("XOA" + origin.archive)
76
 
            document.add_term("XOC" + origin.component)
77
 
            document.add_term("XOL" + origin.label)
78
 
            document.add_term("XOO" + origin.origin)
79
 
            document.add_term("XOS" + origin.site)
80
 
 
81
 
        # FIXME: this doesn't really belong in this file, but we can put it in
82
 
        #        here until we get a display_name/display_summary plugin which
83
 
        #        is being prepared in the experimental-fastlist branch.
84
 
        if '-' in pkg.name:
85
 
            # we need this to work around xapian oddness
86
 
            document.add_term(pkg.name.replace('-', '_'))
87
 
 
88
 
    def indexDeb822(self, document, pkg):
89
 
        """
90
 
        Update the document with the information from this data source.
91
 
 
92
 
        This is alternative to index, and it is used when indexing with package
93
 
        data taken from a custom Packages file.
94
 
 
95
 
        document  is the document to update
96
 
        pkg       is the Deb822 object for this package
97
 
        """
98
 
        # NOTHING here, does not make sense for non-downloadable data
99
 
        return
100
 
 
101
 
 
102
 
def init():
103
 
    """
104
 
    Create and return the plugin object.
105
 
    """
106
 
    return OriginPlugin()