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