]> arthur.barton.de Git - bup.git/blob - cmd/gc-cmd.py
e0782ca3f625701e0ed678e94daad5feb6c0138d
[bup.git] / cmd / gc-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
8 import sys
9
10 from bup import git, options
11 from bup.gc import bup_gc
12 from bup.helpers import die_if_errors, handle_ctrl_c, log
13
14
15 optspec = """
16 bup gc [options...]
17 --
18 v,verbose   increase log output (can be used more than once)
19 threshold=  only rewrite a packfile if it's over this percent garbage [10]
20 #,compress= set compression level to # (0-9, 9 is highest) [1]
21 unsafe      use the command even though it may be DANGEROUS
22 """
23
24 # FIXME: server mode?
25 # FIXME: make sure client handles server-side changes reasonably
26
27 handle_ctrl_c()
28
29 o = options.Options(optspec)
30 (opt, flags, extra) = o.parse(sys.argv[1:])
31
32 if not opt.unsafe:
33     o.fatal('refusing to run dangerous, experimental command without --unsafe')
34
35 if extra:
36     o.fatal('no positional parameters expected')
37
38 if opt.threshold:
39     try:
40         opt.threshold = int(opt.threshold)
41     except ValueError:
42         o.fatal('threshold must be an integer percentage value')
43     if opt.threshold < 0 or opt.threshold > 100:
44         o.fatal('threshold must be an integer percentage value')
45
46 git.check_repo_or_die()
47
48 bup_gc(threshold=opt.threshold,
49        compression=opt.compress,
50        verbosity=opt.verbose)
51
52 die_if_errors()