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