~ubuntu-branches/ubuntu/raring/apt-xapian-index/raring-proposed

« back to all changes in this revision

Viewing changes to plugins/sections.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-06-17 10:51:30 UTC
  • mfrom: (15.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110617105130-zrb03qthrg3l51mv
Tags: 0.43ubuntu1
* Merge from debian unstable.  Remaining changes:
  - when upgrading, ensure the index is fully rebuild (in the
    background) to ensure that we get updated information in
    /var/lib/apt-xapian-index/{index.values} and that the index
    fully utilizes the new plugins (LP: #646018)
  - use ionice for the index building
  - do not crash if the DB is already locked (LP: #590998)
  - data/org.debian.AptXapianIndex.conf: fix policy
  - move to dh_python2
  - update-apt-xapian-index-dbus:
    + fix type of "start-time" for policykit (LP: #675533)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import apt
2
 
import apt_pkg
 
1
try:
 
2
    import apt
 
3
    import apt_pkg
 
4
    HAS_APT=True
 
5
except ImportError:
 
6
    HAS_APT=False
3
7
import xapian
4
8
import os, os.path
5
9
 
6
10
class Sections:
7
 
    def info(self):
 
11
    def info(self, **kw):
8
12
        """
9
13
        Return general information about the plugin.
10
14
 
11
15
        The information returned is a dict with various keywords:
12
 
         
 
16
 
13
17
         timestamp (required)
14
18
           the last modified timestamp of this data source.  This will be used
15
19
           to see if we need to update the database or not.  A timestamp of 0
22
26
        the timestamp shows that this plugin is currently not needed, then the
23
27
        long initialisation can just be skipped.
24
28
        """
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(timestamp = os.path.getmtime(file))
 
29
        res = dict(
 
30
                timestamp=0,
 
31
                prefixes=[
 
32
                    dict(idx="XS", qp="sec:", type="bool",
 
33
                         desc="Package section",
 
34
                         ldesc="Debian package section, max one per package"),
 
35
                ],
 
36
        )
 
37
        if kw.get("system", True):
 
38
            if not HAS_APT: return res
 
39
            file = apt_pkg.config.find_file("Dir::Cache::pkgcache")
 
40
            if not os.path.exists(file): return res
 
41
            ts = os.path.getmtime(file)
 
42
        else:
 
43
            file = "(stdin)"
 
44
            ts = 0
 
45
        res["timestamp"] = ts
 
46
        res["sources"] = [dict(path=file, desc="APT index")]
 
47
        return res
29
48
 
30
49
    def init(self, info, progress):
31
50
        """
66
85
        """
67
86
        sec = pkg.section
68
87
        if sec:
69
 
            document.add_term("XS"+sec)
 
88
            document.add_term("XS"+sec.lower())
70
89
 
71
90
    def indexDeb822(self, document, pkg):
72
91
        """
80
99
        """
81
100
        sec = pkg["Section"]
82
101
        if sec:
83
 
            document.add_term("XS"+sec)
 
102
            document.add_term("XS"+sec.lower())
84
103
 
85
104
def init(**kw):
86
105
    """