3 # Copyright (C) 2010 Rob Browning
5 # This code is covered under the terms of the GNU Library General
6 # Public License as described in the bup LICENSE file.
11 from bup import metadata
12 from bup import options
14 from bup.helpers import handle_ctrl_c, saved_errors
17 bup pathinfo [OPTION ...] <PATH ...>
19 v,verbose increase log output (can be used more than once)
20 q,quiet don't show progress meter
21 exclude-fields= exclude comma-separated fields
22 include-fields= include comma-separated fields (definitive if first)
26 all_fields = frozenset(['path',
40 active_fields = all_fields
44 o = options.Options('bup pathinfo', optspec)
45 (opt, flags, remainder) = o.parse(sys.argv[1:])
47 treat_include_fields_as_definitive = True
48 for flag, value in flags:
49 if flag == '--verbose' or flag == '-v':
51 elif flag == '--quiet' or flag == '-q':
53 elif flag == '--exclude-fields':
54 exclude_fields = frozenset(value.split(','))
55 for f in exclude_fields:
56 if not f in all_fields:
57 o.fatal(f + ' is not a valid field name')
58 active_fields = active_fields - exclude_fields
59 treat_include_fields_as_definitive = False
60 elif flag == '--include-fields':
61 include_fields = frozenset(value.split(','))
62 for f in include_fields:
63 if not f in all_fields:
64 o.fatal(f + ' is not a valid field name')
65 if treat_include_fields_as_definitive:
66 active_fields = include_fields
67 treat_include_fields_as_definitive = False
69 active_fields = active_fields | include_fields
71 for path in remainder:
72 m = metadata.from_path(path, archive_path = path)
73 if 'path' in active_fields:
75 if 'mode' in active_fields:
76 print 'mode:', oct(m.mode)
77 if 'link-target' in active_fields and stat.S_ISLNK(m.mode):
78 print 'link-target:', m.symlink_target
79 if 'rdev' in active_fields:
81 if 'uid' in active_fields:
83 if 'gid' in active_fields:
85 if 'owner' in active_fields:
86 print 'owner:', m.owner
87 if 'group' in active_fields:
88 print 'group:', m.group
89 if 'atime' in active_fields:
90 print 'atime: ' + '%d.%09d' % m.atime.secs_nsecs()
91 if 'mtime' in active_fields:
92 print 'mtime: ' + '%d.%09d' % m.mtime.secs_nsecs()
93 if 'ctime' in active_fields:
94 print 'ctime: ' + '%d.%09d' % m.ctime.secs_nsecs()
95 if 'linux-attr' in active_fields and m.linux_attr:
96 print 'linux-attr:', hex(m.linux_attr)
97 if 'linux-xattr' in active_fields and m.linux_xattr:
98 for name, value in m.linux_xattr:
99 print 'linux-xattr: %s -> %s' % (name, repr(value))
100 if 'posix1e-acl' in active_fields and m.posix1e_acl:
101 flags = posix1e.TEXT_ABBREVIATE
102 if stat.S_ISDIR(m.mode):
103 acl = m.posix1e_acl[0]
104 default_acl = m.posix1e_acl[2]
105 print acl.to_any_text('posix1e-acl: ', '\n', flags)
106 print acl.to_any_text('posix1e-acl-default: ', '\n', flags)
108 acl = m.posix1e_acl[0]
109 print acl.to_any_text('posix1e-acl: ', '\n', flags)
112 log('WARNING: %d errors encountered.\n' % len(saved_errors))