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