Last change
on this file since 3 was
3,
checked in by valtob, 15 years ago
|
subversion source 1.6.2 as test
|
-
Property svn:executable set to
*
|
File size:
1.0 KB
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # USAGE: getfile.py [-r REV] repos-path file |
---|
4 | # |
---|
5 | # gets a file from an SVN repository, puts it to sys.stdout |
---|
6 | # |
---|
7 | |
---|
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 | |
---|
16 | from svn import fs, core, repos |
---|
17 | |
---|
18 | CHUNK_SIZE = 16384 |
---|
19 | |
---|
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) |
---|
24 | |
---|
25 | if rev is None: |
---|
26 | rev = fs.youngest_rev(fsob) |
---|
27 | print("Using youngest revision %s" % rev) |
---|
28 | |
---|
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) |
---|
36 | |
---|
37 | def usage(): |
---|
38 | print("USAGE: getfile.py [-r REV] repos-path file") |
---|
39 | sys.exit(1) |
---|
40 | |
---|
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) |
---|
50 | |
---|
51 | if __name__ == '__main__': |
---|
52 | main() |
---|
Note: See
TracBrowser
for help on using the repository browser.