]> arthur.barton.de Git - bup.git/blob - cmd/list-idx-cmd.py
Configure python, use it, and embed during install
[bup.git] / cmd / list-idx-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7 import sys, os
8 from bup import git, options
9 from bup.helpers import *
10
11 optspec = """
12 bup list-idx [--find=<prefix>] <idxfilenames...>
13 --
14 find=   display only objects that start with <prefix>
15 """
16 o = options.Options(optspec)
17 (opt, flags, extra) = o.parse(sys.argv[1:])
18
19 handle_ctrl_c()
20 opt.find = opt.find or ''
21
22 if not extra:
23     o.fatal('you must provide at least one filename')
24
25 if len(opt.find) > 40:
26     o.fatal('--find parameter must be <= 40 chars long')
27 else:
28     if len(opt.find) % 2:
29         s = opt.find + '0'
30     else:
31         s = opt.find
32     try:
33         bin = s.decode('hex')
34     except TypeError:
35         o.fatal('--find parameter is not a valid hex string')
36
37 find = opt.find.lower()
38
39 count = 0
40 for name in extra:
41     try:
42         ix = git.open_idx(name)
43     except git.GitError, e:
44         add_error('%s: %s' % (name, e))
45         continue
46     if len(opt.find) == 40:
47         if ix.exists(bin):
48             print name, find
49     else:
50         # slow, exhaustive search
51         for _i in ix:
52             i = str(_i).encode('hex')
53             if i.startswith(find):
54                 print name, i
55             qprogress('Searching: %d\r' % count)
56             count += 1
57
58 if saved_errors:
59     log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))
60     sys.exit(1)