]> arthur.barton.de Git - bup.git/blob - lib/cmd/gc-cmd.py
Remove $(dirname "$0") from sys.path
[bup.git] / lib / cmd / gc-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
5 arg_i=1
6 for arg in "$@"; do
7     export "BUP_ARGV_${arg_i}"="$arg"
8     shift
9     arg_i=$((arg_i + 1))
10 done
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
14 """
15 # end of bup preamble
16
17 from __future__ import absolute_import
18
19 # Intentionally replace the dirname "$0" that python prepends
20 import os, sys
21 sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/..'
22
23 from bup import compat, git, options
24 from bup.gc import bup_gc
25 from bup.helpers import die_if_errors, handle_ctrl_c, log
26
27
28 optspec = """
29 bup gc [options...]
30 --
31 v,verbose   increase log output (can be used more than once)
32 threshold=  only rewrite a packfile if it's over this percent garbage [10]
33 #,compress= set compression level to # (0-9, 9 is highest) [1]
34 unsafe      use the command even though it may be DANGEROUS
35 """
36
37 # FIXME: server mode?
38 # FIXME: make sure client handles server-side changes reasonably
39
40 handle_ctrl_c()
41
42 o = options.Options(optspec)
43 opt, flags, extra = o.parse(compat.argv[1:])
44
45 if not opt.unsafe:
46     o.fatal('refusing to run dangerous, experimental command without --unsafe')
47
48 if extra:
49     o.fatal('no positional parameters expected')
50
51 if opt.threshold:
52     try:
53         opt.threshold = int(opt.threshold)
54     except ValueError:
55         o.fatal('threshold must be an integer percentage value')
56     if opt.threshold < 0 or opt.threshold > 100:
57         o.fatal('threshold must be an integer percentage value')
58
59 git.check_repo_or_die()
60
61 bup_gc(threshold=opt.threshold,
62        compression=opt.compress,
63        verbosity=opt.verbose)
64
65 die_if_errors()