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