Fix compiler warning due to missing function prototype.
[svn.git] / tools / examples / dumpprops.py
blob4df575f11b39439af1263500918f51348c3d991b
1 #!/usr/bin/env python
3 # USAGE: dumprops.py [-r REV] repos-path [file]
5 # dump out the properties on a given path (recursively if given a dir)
8 import sys
9 import os
10 import getopt
11 try:
12 my_getopt = getopt.gnu_getopt
13 except AttributeError:
14 my_getopt = getopt.getopt
15 import pprint
17 from svn import fs, core, repos
20 def dumpprops(path, filename='', rev=None):
21 path = core.svn_path_canonicalize(path)
22 repos_ptr = repos.open(path)
23 fsob = repos.fs(repos_ptr)
25 if rev is None:
26 rev = fs.youngest_rev(fsob)
28 root = fs.revision_root(fsob, rev)
29 print_props(root, filename)
30 if fs.is_dir(root, filename):
31 walk_tree(root, filename)
33 def print_props(root, path):
34 raw_props = fs.node_proplist(root, path)
35 # need to massage some buffers into strings for printing
36 props = { }
37 for key, value in raw_props.items():
38 props[key] = str(value)
40 print '---', path
41 pprint.pprint(props)
43 def walk_tree(root, path):
44 for name in fs.dir_entries(root, path).keys():
45 full = path + '/' + name
46 print_props(root, full)
47 if fs.is_dir(root, full):
48 walk_tree(root, full)
50 def usage():
51 print "USAGE: dumpprops.py [-r REV] repos-path [file]"
52 sys.exit(1)
54 def main():
55 opts, args = my_getopt(sys.argv[1:], 'r:')
56 rev = None
57 for name, value in opts:
58 if name == '-r':
59 rev = int(value)
60 if len(args) == 2:
61 dumpprops(args[0], args[1], rev)
62 elif len(args) == 1:
63 dumpprops(args[0], "", rev)
64 else:
65 usage()
67 if __name__ == '__main__':
68 main()