Debian Codegraph @

update-apt-xapian-index

raw symbols SCIP
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 #
5 # update-apt-xapian-index - Maintain a system-wide Xapian index of Debian
6 # package information
7 #
8 # Copyright (C) 2007--2010 Enrico Zini <[email protected]>
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #
24
25 #
26 # Main program body
27 #
28
29 # Minimal imports so we are always able to print command line help
30 from optparse import OptionParser
31 import sys
32 import warnings
33
34 VERSION="0.49"
35
36 class Parser(OptionParser):
37 def __init__(self, *args, **kwargs):
38 OptionParser.__init__(self, *args, **kwargs)
39
40 def error(self, msg):
41 sys.stderr.write("%s: error: %s\n\n" % (self.get_prog_name(), msg))
42 self.print_help(sys.stderr)
43 sys.exit(2)
44
45 parser = Parser(usage="usage: %prog [options]",
46 version="%prog "+ VERSION,
47 description="Rebuild the Apt Xapian index")
48 parser.add_option("-q", "--quiet", action="store_true", help="quiet mode: only output fatal errors")
49 parser.add_option("-v", "--verbose", action="store_true", help="verbose mode")
50 parser.add_option("-f", "--force", action="store_true", help="force database rebuild even if it's already up to date")
51 parser.add_option("--pkgfile", action="append", help="do not use the APT cache, but the given Package file")
52 parser.add_option("--batch-mode", action="store_true", help="use progress reporting suitable from programmatic parsing.")
53 parser.add_option("-u","--update", action="store_true", help="incremental update, reindexing only those packages whose version has changed since the last run")
54 (opts, args) = parser.parse_args()
55
56
57 # Rest of the imports here
58 import axi
59 import axi.indexer
60
61 #if opts.quiet: print "quiet"
62 #if opts.verbose: print "verbose"
63 #if opts.force: print "force"
64
65 # Instantiate the progress report
66 if opts.batch_mode:
67 quietapt = False
68 progress = axi.indexer.BatchProgress()
69 elif opts.quiet:
70 quietapt = True
71 progress = axi.indexer.SilentProgress()
72 warnings.filterwarnings("ignore","")
73 else:
74 quietapt = False
75 progress = axi.indexer.Progress()
76
77 if opts.verbose:
78 progress.is_verbose = True
79
80 # Create the indexer
81 indexer = axi.indexer.Indexer(progress, quietapt)
82
83 # Lock the session so that we prevent concurrent updates
84 try:
85 locked = indexer.lock()
86 except OSError as e:
87 import errno
88 if e.errno == errno.EACCES:
89 print("You probably need to be root to do this.", file=sys.stderr)
90 sys.exit(1)
91 raise
92 if not locked:
93 indexer.slave()
94 sys.exit(0)
95
96 # Set up the indexer and check that we have something to do
97 if not indexer.setupIndexing(force=opts.force, system=opts.pkgfile is None):
98 sys.exit(0)
99
100 if opts.update:
101 # update only mode
102 indexer.incrementalUpdate()
103 else:
104 indexer.rebuild(opts.pkgfile)
105
106 sys.exit(0)