3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 # Copyright (C) 2010 Rob Browning
10 # This code is covered under the terms of the GNU Library General
11 # Public License as described in the bup LICENSE file.
13 from __future__ import absolute_import, print_function
14 import sys, stat, errno
16 from bup import metadata, options, xstat
17 from bup.compat import argv_bytes
18 from bup.helpers import add_error, handle_ctrl_c, parse_timestamp, saved_errors, \
20 from bup.io import byte_stream
23 def parse_timestamp_arg(field, value):
24 res = str(value) # Undo autoconversion.
26 res = parse_timestamp(res)
27 except ValueError as ex:
29 o.fatal('unable to parse %s resolution "%s" (%s)'
32 o.fatal('unable to parse %s resolution "%s"' % (field, value))
34 if res != 1 and res % 10:
35 o.fatal('%s resolution "%s" must be a power of 10' % (field, value))
40 bup xstat pathinfo [OPTION ...] <PATH ...>
42 v,verbose increase log output (can be used more than once)
43 q,quiet don't show progress meter
44 exclude-fields= exclude comma-separated fields
45 include-fields= include comma-separated fields (definitive if first)
46 atime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
47 mtime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
48 ctime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
52 active_fields = metadata.all_fields
56 o = options.Options(optspec)
57 (opt, flags, remainder) = o.parse(sys.argv[1:])
59 atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
60 mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
61 ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution)
63 treat_include_fields_as_definitive = True
64 for flag, value in flags:
65 if flag == '--exclude-fields':
66 exclude_fields = frozenset(value.split(','))
67 for f in exclude_fields:
68 if not f in metadata.all_fields:
69 o.fatal(f + ' is not a valid field name')
70 active_fields = active_fields - exclude_fields
71 treat_include_fields_as_definitive = False
72 elif flag == '--include-fields':
73 include_fields = frozenset(value.split(','))
74 for f in include_fields:
75 if not f in metadata.all_fields:
76 o.fatal(f + ' is not a valid field name')
77 if treat_include_fields_as_definitive:
78 active_fields = include_fields
79 treat_include_fields_as_definitive = False
81 active_fields = active_fields | include_fields
83 opt.verbose = opt.verbose or 0
84 opt.quiet = opt.quiet or 0
85 metadata.verbose = opt.verbose - opt.quiet
88 out = byte_stream(sys.stdout)
91 for path in remainder:
92 path = argv_bytes(path)
94 m = metadata.from_path(path, archive_path = path)
95 except (OSError,IOError) as e:
96 if e.errno == errno.ENOENT:
101 if metadata.verbose >= 0:
104 if atime_resolution != 1:
105 m.atime = (m.atime / atime_resolution) * atime_resolution
106 if mtime_resolution != 1:
107 m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
108 if ctime_resolution != 1:
109 m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
110 out.write(metadata.detailed_bytes(m, active_fields))
115 log('WARNING: %d errors encountered.\n' % len(saved_errors))