-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-idx-cmd.py
executable file
·63 lines (53 loc) · 1.46 KB
/
list-idx-cmd.py
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
#!/bin/sh
"""": # -*-python-*-
bup_python="$(dirname "$0")/bup-python" || exit $?
exec "$bup_python" "$0" ${1+"$@"}
"""
# end of bup preamble
import sys, os
from bup import git, options
from bup.helpers import add_error, handle_ctrl_c, log, qprogress, saved_errors
optspec = """
bup list-idx [--find=<prefix>] <idxfilenames...>
--
find= display only objects that start with <prefix>
"""
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])
handle_ctrl_c()
opt.find = opt.find or ''
if not extra:
o.fatal('you must provide at least one filename')
if len(opt.find) > 40:
o.fatal('--find parameter must be <= 40 chars long')
else:
if len(opt.find) % 2:
s = opt.find + '0'
else:
s = opt.find
try:
bin = s.decode('hex')
except TypeError:
o.fatal('--find parameter is not a valid hex string')
find = opt.find.lower()
count = 0
for name in extra:
try:
ix = git.open_idx(name)
except git.GitError as e:
add_error('%s: %s' % (name, e))
continue
if len(opt.find) == 40:
if ix.exists(bin):
print name, find
else:
# slow, exhaustive search
for _i in ix:
i = str(_i).encode('hex')
if i.startswith(find):
print name, i
qprogress('Searching: %d\r' % count)
count += 1
if saved_errors:
log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))
sys.exit(1)