~gary-lasker/software-center/fix-lp913756-for-5.0

« back to all changes in this revision

Viewing changes to apt-xapian-index-plugin/origin.py

prototype side view

Show diffs side-by-side

added added

removed removed

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