home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / apt-xapian-index / plugins / descriptions.py < prev    next >
Encoding:
Python Source  |  2008-08-20  |  3.3 KB  |  98 lines

  1. import apt
  2. import xapian
  3. import re
  4. import os, os.path
  5.  
  6. class Descriptions:
  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.apt_pkg.Config.FindFile("Dir::Cache::pkgcache")
  26.         return dict(timestamp = os.path.getmtime(file))
  27.  
  28.     def init(self, info, progress):
  29.         """
  30.         If needed, perform long initialisation tasks here.
  31.  
  32.         info is a dictionary with useful information.  Currently it contains
  33.         the following values:
  34.  
  35.           "values": a dict mapping index mnemonics to index numbers
  36.  
  37.         The progress indicator can be used to report progress.
  38.         """
  39.         self.stemmer = xapian.Stem("english")
  40.         self.indexer = xapian.TermGenerator()
  41.         self.indexer.set_stemmer(self.stemmer)
  42.  
  43.     def doc(self):
  44.         """
  45.         Return documentation information for this data source.
  46.  
  47.         The documentation information is a dictionary with these keys:
  48.           name: the name for this data source
  49.           shortDesc: a short description
  50.           fullDoc: the full description as a chapter in ReST format
  51.         """
  52.         return dict(
  53.             name = "Package descriptions",
  54.             shortDesc = "terms extracted from the package descriptions using Xapian's TermGenerator",
  55.             fullDoc = """
  56.             The Descriptions data source simply uses Xapian's TermGenerator to
  57.             tokenise and index the package descriptions.
  58.  
  59.             Currently this creates normal terms as well as stemmed terms
  60.             prefixed with ``Z``.
  61.             """
  62.         )
  63.  
  64.     def index(self, document, pkg):
  65.         """
  66.         Update the document with the information from this data source.
  67.  
  68.         document  is the document to update
  69.         pkg       is the python-apt Package object for this package
  70.         """
  71.         self.indexer.set_document(document)
  72.  
  73.         # Index the record
  74.         self.indexer.index_text_without_positions(pkg.name)
  75.         self.indexer.index_text_without_positions(pkg.rawDescription)
  76.  
  77.     def indexDeb822(self, document, pkg):
  78.         """
  79.         Update the document with the information from this data source.
  80.  
  81.         This is alternative to index, and it is used when indexing with package
  82.         data taken from a custom Packages file.
  83.  
  84.         document  is the document to update
  85.         pkg       is the Deb822 object for this package
  86.         """
  87.         self.indexer.set_document(document)
  88.  
  89.         # Index the record
  90.         self.indexer.index_text_without_positions(pkg["Package"])
  91.         self.indexer.index_text_without_positions(pkg["Description"])
  92.  
  93. def init():
  94.     """
  95.     Create and return the plugin object.
  96.     """
  97.     return Descriptions()
  98.