~ubuntu-branches/ubuntu/quantal/apt-xapian-index/quantal

« back to all changes in this revision

Viewing changes to plugins/apttags.py

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Zini
  • Date: 2008-02-19 11:19:08 UTC
  • Revision ID: james.westby@ubuntu.com-20080219111908-mq6rug29v32hlqp0
Tags: 0.6
Added --pkgfile option to index arbitrary Package files instead of the APT
cache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Add debtags tags to the index
2
2
 
3
 
import re, os, os.path
 
3
import re, os, os.path, apt
4
4
 
5
5
DEBTAGSDB = "/var/lib/debtags/package-tags"
6
6
 
81
81
            """
82
82
        )
83
83
 
84
 
    def index(self, document, pkg):
85
 
        """
86
 
        Update the document with the information from this data source.
87
 
 
88
 
        document  is the document to update
89
 
        pkg       is the python-apt Package object for this package
90
 
        """
91
 
        tagstring = pkg.candidateRecord['Tag']
 
84
    def _parse_and_index(self, tagstring, document):
 
85
        """
 
86
        Parse tagstring into tags, and index the tags
 
87
        """
92
88
        def expandTags(mo):
93
89
            root = mo.group(1)
94
90
            ends = self.re_split.split(mo.group(2))
95
91
            return ", ".join([root + x for x in ends])
96
 
        tagstring = self.re_expand.sub(expandtags, tagstring)
 
92
        tagstring = self.re_expand.sub(expandTags, tagstring)
97
93
        for tag in self.re_split.split(tagstring):
98
94
            document.add_term("XT"+tag)
 
95
        
 
96
 
 
97
    def index(self, document, pkg):
 
98
        """
 
99
        Update the document with the information from this data source.
 
100
 
 
101
        document  is the document to update
 
102
        pkg       is the python-apt Package object for this package
 
103
        """
 
104
        rec = pkg.candidateRecord
 
105
        if rec == None: return
 
106
        try:
 
107
            self._parse_and_index(rec['Tag'], document)
 
108
        except KeyError:
 
109
            return
 
110
 
 
111
    def indexDeb822(self, document, pkg):
 
112
        """
 
113
        Update the document with the information from this data source.
 
114
 
 
115
        This is alternative to index, and it is used when indexing with package
 
116
        data taken from a custom Packages file.
 
117
 
 
118
        document  is the document to update
 
119
        pkg       is the Deb822 object for this package
 
120
        """
 
121
        try:
 
122
            self._parse_and_index(pkg['Tag'], document)
 
123
        except KeyError:
 
124
            return
 
125
 
99
126
 
100
127
def init():
101
128
    """