File: update-apt-xapian-index

package info (click to toggle)
apt-xapian-index 0.49
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 416 kB
  • sloc: python: 2,872; ruby: 475; sh: 135; makefile: 30
file content (106 lines) | stat: -rwxr-xr-x 3,432 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
# -*- coding: utf-8 -*-

#
# update-apt-xapian-index - Maintain a system-wide Xapian index of Debian
#                           package information
#
# Copyright (C) 2007--2010  Enrico Zini <enrico@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#
# Main program body
#

# Minimal imports so we are always able to print command line help
from optparse import OptionParser
import sys
import warnings

VERSION="0.49"

class Parser(OptionParser):
    def __init__(self, *args, **kwargs):
        OptionParser.__init__(self, *args, **kwargs)

    def error(self, msg):
        sys.stderr.write("%s: error: %s\n\n" % (self.get_prog_name(), msg))
        self.print_help(sys.stderr)
        sys.exit(2)

parser = Parser(usage="usage: %prog [options]",
                version="%prog "+ VERSION,
                description="Rebuild the Apt Xapian index")
parser.add_option("-q", "--quiet", action="store_true", help="quiet mode: only output fatal errors")
parser.add_option("-v", "--verbose", action="store_true", help="verbose mode")
parser.add_option("-f", "--force", action="store_true", help="force database rebuild even if it's already up to date")
parser.add_option("--pkgfile", action="append", help="do not use the APT cache, but the given Package file")
parser.add_option("--batch-mode", action="store_true", help="use progress reporting suitable from programatic parsing.")
parser.add_option("-u","--update", action="store_true", help="incremental update, reindexing only those packages whose version has changed since the last run")
(opts, args) = parser.parse_args()


# Rest of the imports here
import axi
import axi.indexer

#if opts.quiet: print "quiet"
#if opts.verbose: print "verbose"
#if opts.force: print "force"

# Instantiate the progress report
if opts.batch_mode:
    quietapt = False
    progress = axi.indexer.BatchProgress()
elif opts.quiet:
    quietapt = True
    progress = axi.indexer.SilentProgress()
    warnings.filterwarnings("ignore","")
else:
    quietapt = False
    progress = axi.indexer.Progress()

if opts.verbose:
    progress.is_verbose = True

# Create the indexer
indexer = axi.indexer.Indexer(progress, quietapt)

# Lock the session so that we prevent concurrent updates
try:
    locked = indexer.lock()
except OSError, e:
    import errno
    if e.errno == errno.EACCES:
        print >>sys.stderr, "You probably need to be root to do this."
        sys.exit(1)
    raise
if not locked:
    indexer.slave()
    sys.exit(0)

# Set up the indexer and check that we have something to do
if not indexer.setupIndexing(force=opts.force, system=opts.pkgfile is None):
    sys.exit(0)

if opts.update:
    # update only mode
    indexer.incrementalUpdate()
else:
    indexer.rebuild(opts.pkgfile)

sys.exit(0)