]> arthur.barton.de Git - bup.git/commitdiff
bloom: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Sun, 7 Feb 2021 22:36:53 +0000 (16:36 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:38 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/bloom.py
lib/cmd/bup

index 751643abb2e3f512ebff989d0f280e4c5da4fc0c..3bff576b9fbe4bad9cbe71c115afc0d2e4c51df3 100755 (executable)
@@ -1,26 +1,7 @@
-#!/bin/sh
-"""": # -*-python-*-
-# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
-export "BUP_ARGV_0"="$0"
-arg_i=1
-for arg in "$@"; do
-    export "BUP_ARGV_${arg_i}"="$arg"
-    shift
-    arg_i=$((arg_i + 1))
-done
-# Here to end of preamble replaced during install
-bup_python="$(dirname "$0")/../../../config/bin/python" || exit $?
-exec "$bup_python" "$0"
-"""
-# end of bup preamble
 
 from __future__ import absolute_import
 
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
-import glob, tempfile
+import os, glob, tempfile
 
 from bup import compat, options, git, bloom
 from bup.compat import argv_bytes, hexstr
@@ -75,11 +56,11 @@ def check_bloom(path, bloomfilename, idx):
 
 
 _first = None
-def do_bloom(path, outfilename, k):
+def do_bloom(path, outfilename, k, force):
     global _first
     assert k in (None, 4, 5)
     b = None
-    if os.path.exists(outfilename) and not opt.force:
+    if os.path.exists(outfilename) and not force:
         b = bloom.ShaBloom(outfilename)
         if not b.valid():
             debug1("bloom: Existing invalid bloom found, regenerating.\n")
@@ -157,36 +138,35 @@ def do_bloom(path, outfilename, k):
         os.rename(tfname, outfilename)
 
 
-handle_ctrl_c()
-
-o = options.Options(optspec)
-opt, flags, extra = o.parse(compat.argv[1:])
-
-if extra:
-    o.fatal('no positional parameters expected')
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
 
-if not opt.check and opt.k and opt.k not in (4,5):
-    o.fatal('only k values of 4 and 5 are supported')
+    if extra:
+        o.fatal('no positional parameters expected')
 
-if opt.check:
-    opt.check = argv_bytes(opt.check)
+    if not opt.check and opt.k and opt.k not in (4,5):
+        o.fatal('only k values of 4 and 5 are supported')
 
-git.check_repo_or_die()
-
-output = argv_bytes(opt.output) if opt.output else None
-paths = opt.dir and [argv_bytes(opt.dir)] or git.all_packdirs()
-for path in paths:
-    debug1('bloom: scanning %s\n' % path_msg(path))
-    outfilename = output or os.path.join(path, b'bup.bloom')
     if opt.check:
-        check_bloom(path, outfilename, opt.check)
-    elif opt.ruin:
-        ruin_bloom(outfilename)
-    else:
-        do_bloom(path, outfilename, opt.k)
-
-if saved_errors:
-    log('WARNING: %d errors encountered during bloom.\n' % len(saved_errors))
-    sys.exit(1)
-elif opt.check:
-    log('All tests passed.\n')
+        opt.check = argv_bytes(opt.check)
+
+    git.check_repo_or_die()
+
+    output = argv_bytes(opt.output) if opt.output else None
+    paths = opt.dir and [argv_bytes(opt.dir)] or git.all_packdirs()
+    for path in paths:
+        debug1('bloom: scanning %s\n' % path_msg(path))
+        outfilename = output or os.path.join(path, b'bup.bloom')
+        if opt.check:
+            check_bloom(path, outfilename, opt.check)
+        elif opt.ruin:
+            ruin_bloom(outfilename)
+        else:
+            do_bloom(path, outfilename, opt.k, opt.force)
+
+    if saved_errors:
+        log('WARNING: %d errors encountered during bloom.\n' % len(saved_errors))
+        sys.exit(1)
+    elif opt.check:
+        log('All tests passed.\n')
index 02e54a3b940735f73ff0834ae3ef543abcf76eef..cfee03ec010cd735ab9a623b33827005342f08fc 100755 (executable)
@@ -185,7 +185,8 @@ if not subcmd_name:
     usage()
 
 try:
-    if subcmd_name not in (b'cat-file',
+    if subcmd_name not in (b'bloom',
+                           b'cat-file',
                            b'ls',
                            b'meta',
                            b'version',