]> arthur.barton.de Git - bup.git/commitdiff
drecurse: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Fri, 12 Feb 2021 19:55:36 +0000 (13:55 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:39 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/drecurse.py
lib/cmd/bup

index 0fe1e2e30662a24bc487e427f590e2e287b53900..42b292c8041f487bf966e99185ed2d79f25433d5 100755 (executable)
@@ -1,28 +1,9 @@
-#!/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, print_function
-
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
 from os.path import relpath
+import sys
 
-from bup import compat, options, drecurse
+from bup import options, drecurse
 from bup.compat import argv_bytes
 from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors
 from bup.io import byte_stream
@@ -39,36 +20,38 @@ exclude-rx-from= skip --exclude-rx patterns in file (may be repeated)
 q,quiet  don't actually print filenames
 profile  run under the python profiler
 """
-o = options.Options(optspec)
-opt, flags, extra = o.parse(compat.argv[1:])
 
-if len(extra) != 1:
-    o.fatal("exactly one filename expected")
-
-drecurse_top = argv_bytes(extra[0])
-excluded_paths = parse_excludes(flags, o.fatal)
-if not drecurse_top.startswith(b'/'):
-    excluded_paths = [relpath(x) for x in excluded_paths]
-exclude_rxs = parse_rx_excludes(flags, o.fatal)
-it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
-                                excluded_paths=excluded_paths,
-                                exclude_rxs=exclude_rxs)
-if opt.profile:
-    import cProfile
-    def do_it():
-        for i in it:
-            pass
-    cProfile.run('do_it()')
-else:
-    if opt.quiet:
-        for i in it:
-            pass
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
+
+    if len(extra) != 1:
+        o.fatal("exactly one filename expected")
+
+    drecurse_top = argv_bytes(extra[0])
+    excluded_paths = parse_excludes(flags, o.fatal)
+    if not drecurse_top.startswith(b'/'):
+        excluded_paths = [relpath(x) for x in excluded_paths]
+    exclude_rxs = parse_rx_excludes(flags, o.fatal)
+    it = drecurse.recursive_dirlist([drecurse_top], opt.xdev,
+                                    excluded_paths=excluded_paths,
+                                    exclude_rxs=exclude_rxs)
+    if opt.profile:
+        import cProfile
+        def do_it():
+            for i in it:
+                pass
+        cProfile.run('do_it()')
     else:
-        sys.stdout.flush()
-        out = byte_stream(sys.stdout)
-        for (name,st) in it:
-            out.write(name + b'\n')
-
-if saved_errors:
-    log('WARNING: %d errors encountered.\n' % len(saved_errors))
-    sys.exit(1)
+        if opt.quiet:
+            for i in it:
+                pass
+        else:
+            sys.stdout.flush()
+            out = byte_stream(sys.stdout)
+            for (name,st) in it:
+                out.write(name + b'\n')
+
+    if saved_errors:
+        log('WARNING: %d errors encountered.\n' % len(saved_errors))
+        sys.exit(1)
index ab4783c56652f1fe803fa8ce8961f5de0ae65a4c..f3a82c93821c2cd2fc74672e1b812ee86e9890ba 100755 (executable)
@@ -188,6 +188,7 @@ try:
     if subcmd_name not in (b'bloom',
                            b'cat-file',
                            b'daemon',
+                           b'drecurse',
                            b'damage',
                            b'features',
                            b'ftp',