| 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 |
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 |
|
| 58 |
import axi |
| 59 |
import axi.indexer |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 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 |
|
| 81 |
indexer = axi.indexer.Indexer(progress, quietapt) |
| 82 |
|
| 83 |
|
| 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 |
|
| 97 |
if not indexer.setupIndexing(force=opts.force, system=opts.pkgfile is None): |
| 98 |
sys.exit(0) |
| 99 |
|
| 100 |
if opts.update: |
| 101 |
|
| 102 |
indexer.incrementalUpdate() |
| 103 |
else: |
| 104 |
indexer.rebuild(opts.pkgfile) |
| 105 |
|
| 106 |
sys.exit(0) |