3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
17 # Copyright (C) 2010 Rob Browning
19 # This code is covered under the terms of the GNU Library General
20 # Public License as described in the bup LICENSE file.
22 from __future__ import absolute_import, print_function
24 # Intentionally replace the dirname "$0" that python prepends
26 sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
28 import errno, os.path, stat
30 from bup import compat, metadata, options, xstat
31 from bup.compat import argv_bytes
32 from bup.helpers import add_error, handle_ctrl_c, parse_timestamp, saved_errors, \
34 from bup.io import byte_stream
37 def parse_timestamp_arg(field, value):
38 res = str(value) # Undo autoconversion.
40 res = parse_timestamp(res)
41 except ValueError as ex:
43 o.fatal('unable to parse %s resolution "%s" (%s)'
46 o.fatal('unable to parse %s resolution "%s"' % (field, value))
48 if res != 1 and res % 10:
49 o.fatal('%s resolution "%s" must be a power of 10' % (field, value))
54 bup xstat pathinfo [OPTION ...] <PATH ...>
56 v,verbose increase log output (can be used more than once)
57 q,quiet don't show progress meter
58 exclude-fields= exclude comma-separated fields
59 include-fields= include comma-separated fields (definitive if first)
60 atime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
61 mtime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
62 ctime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
66 active_fields = metadata.all_fields
70 o = options.Options(optspec)
71 (opt, flags, remainder) = o.parse(compat.argv[1:])
73 atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
74 mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
75 ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution)
77 treat_include_fields_as_definitive = True
78 for flag, value in flags:
79 if flag == '--exclude-fields':
80 exclude_fields = frozenset(value.split(','))
81 for f in exclude_fields:
82 if not f in metadata.all_fields:
83 o.fatal(f + ' is not a valid field name')
84 active_fields = active_fields - exclude_fields
85 treat_include_fields_as_definitive = False
86 elif flag == '--include-fields':
87 include_fields = frozenset(value.split(','))
88 for f in include_fields:
89 if not f in metadata.all_fields:
90 o.fatal(f + ' is not a valid field name')
91 if treat_include_fields_as_definitive:
92 active_fields = include_fields
93 treat_include_fields_as_definitive = False
95 active_fields = active_fields | include_fields
97 opt.verbose = opt.verbose or 0
98 opt.quiet = opt.quiet or 0
99 metadata.verbose = opt.verbose - opt.quiet
102 out = byte_stream(sys.stdout)
105 for path in remainder:
106 path = argv_bytes(path)
108 m = metadata.from_path(path, archive_path = path)
109 except (OSError,IOError) as e:
110 if e.errno == errno.ENOENT:
115 if metadata.verbose >= 0:
118 if atime_resolution != 1:
119 m.atime = (m.atime / atime_resolution) * atime_resolution
120 if mtime_resolution != 1:
121 m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
122 if ctime_resolution != 1:
123 m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
124 out.write(metadata.detailed_bytes(m, active_fields))
129 log('WARNING: %d errors encountered.\n' % len(saved_errors))