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.
12 from bup import metadata
13 from bup import options
15 from bup.helpers import handle_ctrl_c, saved_errors, add_error, log
18 def fstimestr(fstime):
19 (s, ns) = fstime.secs_nsecs()
23 return '%d.%09d' % (s, ns)
27 bup pathinfo [OPTION ...] <PATH ...>
29 v,verbose increase log output (can be used more than once)
30 q,quiet don't show progress meter
31 exclude-fields= exclude comma-separated fields
32 include-fields= include comma-separated fields (definitive if first)
36 all_fields = frozenset(['path',
50 active_fields = all_fields
54 o = options.Options(optspec)
55 (opt, flags, remainder) = o.parse(sys.argv[1:])
57 treat_include_fields_as_definitive = True
58 for flag, value in flags:
59 if flag == '--verbose' or flag == '-v':
61 elif flag == '--quiet' or flag == '-q':
63 elif flag == '--exclude-fields':
64 exclude_fields = frozenset(value.split(','))
65 for f in exclude_fields:
66 if not f in all_fields:
67 o.fatal(f + ' is not a valid field name')
68 active_fields = active_fields - exclude_fields
69 treat_include_fields_as_definitive = False
70 elif flag == '--include-fields':
71 include_fields = frozenset(value.split(','))
72 for f in include_fields:
73 if not f in all_fields:
74 o.fatal(f + ' is not a valid field name')
75 if treat_include_fields_as_definitive:
76 active_fields = include_fields
77 treat_include_fields_as_definitive = False
79 active_fields = active_fields | include_fields
81 for path in remainder:
83 m = metadata.from_path(path, archive_path = path)
85 if e.errno == errno.ENOENT:
90 if 'path' in active_fields:
92 if 'mode' in active_fields:
93 print 'mode:', oct(m.mode)
94 if 'link-target' in active_fields and stat.S_ISLNK(m.mode):
95 print 'link-target:', m.symlink_target
96 if 'rdev' in active_fields:
98 if 'uid' in active_fields:
100 if 'gid' in active_fields:
102 if 'owner' in active_fields:
103 print 'owner:', m.owner
104 if 'group' in active_fields:
105 print 'group:', m.group
106 if 'atime' in active_fields:
107 print 'atime: ' + fstimestr(m.atime)
108 if 'mtime' in active_fields:
109 print 'mtime: ' + fstimestr(m.mtime)
110 if 'ctime' in active_fields:
111 print 'ctime: ' + fstimestr(m.ctime)
112 if 'linux-attr' in active_fields and m.linux_attr:
113 print 'linux-attr:', hex(m.linux_attr)
114 if 'linux-xattr' in active_fields and m.linux_xattr:
115 for name, value in m.linux_xattr:
116 print 'linux-xattr: %s -> %s' % (name, repr(value))
117 if 'posix1e-acl' in active_fields and m.posix1e_acl:
118 flags = posix1e.TEXT_ABBREVIATE
119 if stat.S_ISDIR(m.mode):
120 acl = m.posix1e_acl[0]
121 default_acl = m.posix1e_acl[2]
122 print acl.to_any_text('posix1e-acl: ', '\n', flags)
123 print acl.to_any_text('posix1e-acl-default: ', '\n', flags)
125 acl = m.posix1e_acl[0]
126 print acl.to_any_text('posix1e-acl: ', '\n', flags)
129 log('WARNING: %d errors encountered.\n' % len(saved_errors))