Edgewall Software

source: trunk/svntrac/File.py@ 1

Last change on this file since 1 was 1, checked in by Jonas Borgström, 20 years ago

Initial import

File size: 2.2 KB
Line 
1# svntrac
2#
3# Copyright (C) 2003 Jonas Borgström <jonas@xyche.com>
4#
5# svntrac is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of the
8# License, or (at your option) any later version.
9#
10# svntrac is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18#
19# Author: Jonas Borgström <jonas@xyche.com>
20
21import sys
22import StringIO
23from svn import fs, util, delta
24
25from Module import Module
26import perm
27
28class File (Module):
29 CHUNK_SIZE = 4096
30
31 def __init__(self, config, args, pool):
32 Module.__init__(self, config, args, pool)
33
34 if args.has_key('rev'):
35 self.rev = args['rev']
36 else:
37 self.rev = None
38
39 if args.has_key('path'):
40 self.path = args['path']
41 else:
42 self.path = '/'
43
44 def render (self):
45 perm.assert_permission (perm.FILE_VIEW)
46
47 def get_mime_type (self, root, path):
48 """
49 Try to use the mime-type stored in subversion. text/plain is default.
50 """
51 type = fs.node_prop (root, path, util.SVN_PROP_MIME_TYPE, self.pool)
52 if not type:
53 type = 'text/plain'
54 return type
55
56 def apply_template (self):
57 if not self.rev:
58 rev = fs.youngest_rev(self.fs_ptr, self.pool)
59 else:
60 rev = int(self.rev)
61
62 root = fs.revision_root(self.fs_ptr, rev, self.pool)
63
64 mime_type = self.get_mime_type (root, self.path)
65
66 print 'Content-type: %s\n\r\n\r' % mime_type
67 file = fs.file_contents(root, self.path, self.pool)
68 while 1:
69 data = util.svn_stream_read(file, self.CHUNK_SIZE)
70 if not data:
71 break
72 sys.stdout.write(data)
Note: See TracBrowser for help on using the repository browser.