]> arthur.barton.de Git - bup.git/commitdiff
xstat: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Sat, 6 Feb 2021 19:42:39 +0000 (13:42 -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/xstat.py
lib/cmd/bup

index c20e7a0ebbf5fcebf99d972420fb7c4efd205375..0cf8bdc6176a887d51c63c219d155b917a4153f5 100755 (executable)
@@ -1,19 +1,3 @@
-#!/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
-
 # Copyright (C) 2010 Rob Browning
 #
 # This code is covered under the terms of the GNU Library General
@@ -21,11 +5,7 @@ exec "$bup_python" "$0"
 
 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__)) + '/../..'
-
-import errno, os.path, stat
+import errno, stat, sys
 
 from bup import compat, metadata, options, xstat
 from bup.compat import argv_bytes
@@ -62,71 +42,71 @@ mtime-resolution=  limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
 ctime-resolution=  limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
 """
 
-target_filename = b''
-active_fields = metadata.all_fields
-
-handle_ctrl_c()
-
-o = options.Options(optspec)
-(opt, flags, remainder) = o.parse(compat.argv[1:])
-
-atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
-mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
-ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution)
-
-treat_include_fields_as_definitive = True
-for flag, value in flags:
-    if flag == '--exclude-fields':
-        exclude_fields = frozenset(value.split(','))
-        for f in exclude_fields:
-            if not f in metadata.all_fields:
-                o.fatal(f + ' is not a valid field name')
-        active_fields = active_fields - exclude_fields
-        treat_include_fields_as_definitive = False
-    elif flag == '--include-fields':
-        include_fields = frozenset(value.split(','))
-        for f in include_fields:
-            if not f in metadata.all_fields:
-                o.fatal(f + ' is not a valid field name')
-        if treat_include_fields_as_definitive:
-            active_fields = include_fields
-            treat_include_fields_as_definitive = False
-        else:
-            active_fields = active_fields | include_fields
+def main(argv):
 
-opt.verbose = opt.verbose or 0
-opt.quiet = opt.quiet or 0
-metadata.verbose = opt.verbose - opt.quiet
+    target_filename = b''
+    active_fields = metadata.all_fields
 
-sys.stdout.flush()
-out = byte_stream(sys.stdout)
+    o = options.Options(optspec)
+    (opt, flags, remainder) = o.parse_bytes(argv[1:])
 
-first_path = True
-for path in remainder:
-    path = argv_bytes(path)
-    try:
-        m = metadata.from_path(path, archive_path = path)
-    except (OSError,IOError) as e:
-        if e.errno == errno.ENOENT:
-            add_error(e)
-            continue
-        else:
-            raise
-    if metadata.verbose >= 0:
-        if not first_path:
+    atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
+    mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
+    ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution)
+
+    treat_include_fields_as_definitive = True
+    for flag, value in flags:
+        if flag == '--exclude-fields':
+            exclude_fields = frozenset(value.split(','))
+            for f in exclude_fields:
+                if not f in metadata.all_fields:
+                    o.fatal(f + ' is not a valid field name')
+            active_fields = active_fields - exclude_fields
+            treat_include_fields_as_definitive = False
+        elif flag == '--include-fields':
+            include_fields = frozenset(value.split(','))
+            for f in include_fields:
+                if not f in metadata.all_fields:
+                    o.fatal(f + ' is not a valid field name')
+            if treat_include_fields_as_definitive:
+                active_fields = include_fields
+                treat_include_fields_as_definitive = False
+            else:
+                active_fields = active_fields | include_fields
+
+    opt.verbose = opt.verbose or 0
+    opt.quiet = opt.quiet or 0
+    metadata.verbose = opt.verbose - opt.quiet
+
+    sys.stdout.flush()
+    out = byte_stream(sys.stdout)
+
+    first_path = True
+    for path in remainder:
+        path = argv_bytes(path)
+        try:
+            m = metadata.from_path(path, archive_path = path)
+        except (OSError,IOError) as e:
+            if e.errno == errno.ENOENT:
+                add_error(e)
+                continue
+            else:
+                raise
+        if metadata.verbose >= 0:
+            if not first_path:
+                out.write(b'\n')
+            if atime_resolution != 1:
+                m.atime = (m.atime / atime_resolution) * atime_resolution
+            if mtime_resolution != 1:
+                m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
+            if ctime_resolution != 1:
+                m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
+            out.write(metadata.detailed_bytes(m, active_fields))
             out.write(b'\n')
-        if atime_resolution != 1:
-            m.atime = (m.atime / atime_resolution) * atime_resolution
-        if mtime_resolution != 1:
-            m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
-        if ctime_resolution != 1:
-            m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
-        out.write(metadata.detailed_bytes(m, active_fields))
-        out.write(b'\n')
-        first_path = False
-
-if saved_errors:
-    log('WARNING: %d errors encountered.\n' % len(saved_errors))
-    sys.exit(1)
-else:
-    sys.exit(0)
+            first_path = False
+
+    if saved_errors:
+        log('WARNING: %d errors encountered.\n' % len(saved_errors))
+        sys.exit(1)
+    else:
+        sys.exit(0)
index 43df2aed3cf7c2f18ff91ec63316663f528df3ef..cdb8411fc14ad72e64f753564b027426405d917a 100755 (executable)
@@ -187,7 +187,8 @@ if not subcmd_name:
 try:
     if subcmd_name not in (b'cat-file',
                            b'ls',
-                           b'meta'):
+                           b'meta',
+                           b'xstat'):
         raise ModuleNotFoundError()
     cmd_module = import_module('bup.cmd.'
                                + subcmd_name.decode('ascii').replace('-', '_'))