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

« back to all changes in this revision

Viewing changes to plugins/cataloged_time.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_pkg
 
1
try:
 
2
    import apt_pkg
 
3
    HAS_APT=True
 
4
except ImportError:
 
5
    HAS_APT=False
2
6
import cPickle
3
7
import os
4
8
import os.path
28
32
        the timestamp shows that this plugin is currently not needed, then the
29
33
        long initialisation can just be skipped.
30
34
        """
 
35
        res = dict(timestamp=0,
 
36
                   values=[
 
37
                       dict(name="catalogedtime", desc="Cataloged timestamp"),
 
38
                       ],
 
39
                   sources=[
 
40
                       dict(
 
41
                           path=os.path.join(self.PERSISTANCE_DIR, self.CATALOGED_NAME),
 
42
                           desc="first-seen information for every package"
 
43
                       )
 
44
                   ])
 
45
        if not HAS_APT: return res
 
46
        if not hasattr(apt_pkg, "config"): return res
31
47
        fname = apt_pkg.config.find_file("Dir::Cache::pkgcache")
32
 
        if not os.path.exists(fname):
33
 
            return dict(timestamp = 0)
34
 
        return dict(timestamp = os.path.getmtime(fname),
35
 
                    values = [
36
 
                        dict(name = "catalogedtime", desc = "Cataloged timestamp"),
37
 
                        ]
38
 
                    )
 
48
        if not os.path.exists(fname): return res
 
49
        res["timestamp"] = os.path.getmtime(fname)
 
50
        return res
39
51
 
40
52
    def init(self, info, progress):
41
53
        """
121
133
    """
122
134
    Create and return the plugin object.
123
135
    """
124
 
    apt_pkg.init_config()
 
136
    if not HAS_APT: return None
125
137
    return CatalogedTime()