Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / examples / getfile.py
blob64e4f48a937ceb10de0ca7433f6352947963125d
1 #!/usr/bin/env python
3 # USAGE: getfile.py [-r REV] repos-path file
5 # gets a file from an SVN repository, puts it to sys.stdout
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
16 from svn import fs, core, repos
18 CHUNK_SIZE = 16384
20 def getfile(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)
27 print "Using youngest revision ", rev
29 root = fs.revision_root(fsob, rev)
30 file = fs.file_contents(root, filename)
31 while 1:
32 data = core.svn_stream_read(file, CHUNK_SIZE)
33 if not data:
34 break
35 sys.stdout.write(data)
37 def usage():
38 print "USAGE: getfile.py [-r REV] repos-path file"
39 sys.exit(1)
41 def main():
42 opts, args = my_getopt(sys.argv[1:], 'r:')
43 if len(args) != 2:
44 usage()
45 rev = None
46 for name, value in opts:
47 if name == '-r':
48 rev = int(value)
49 getfile(args[0], args[1], rev)
51 if __name__ == '__main__':
52 main()