##// END OF EJS Templates
Added archives support. Version bump
marcink -
r209:1a18994c rhodecode-0.0.0.7.2 default
parent child Browse files
Show More
@@ -2,7 +2,7 b''
2 2 Hg app, a web based mercurial repository managment based on pylons
3 3 """
4 4
5 VERSION = (0, 7, 1, 'beta')
5 VERSION = (0, 7, 2, 'beta')
6 6
7 7 __version__ = '.'.join((str(each) for each in VERSION[:4]))
8 8
@@ -1,14 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g
1 import tempfile
2 from pylons import request, response, session, tmpl_context as c, url, config, \
3 app_globals as g
4 4 from pylons.controllers.util import abort, redirect
5
5 from pylons_app.lib.auth import LoginRequired
6 6 from pylons_app.lib.base import BaseController, render
7 7 from pylons_app.lib.utils import get_repo_slug
8 8 from pylons_app.model.hg_model import HgModel
9 from vcs.exceptions import RepositoryError, ChangesetError
9 10 from vcs.utils import diffs as differ
10 from vcs.exceptions import RepositoryError, ChangesetError
11 from pylons_app.lib.auth import LoginRequired
11 import logging
12 from mercurial import archival
13
12 14
13 15 log = logging.getLogger(__name__)
14 16
@@ -84,7 +86,32 b' class FilesController(BaseController):'
84 86 return render('files/files_annotate.html')
85 87
86 88 def archivefile(self, repo_name, revision, fileformat):
87 return '%s %s %s' % (repo_name, revision, fileformat)
89 archive_specs = {
90 '.tar.bz2': ('application/x-tar', 'tbz2'),
91 '.tar.gz': ('application/x-tar', 'tgz'),
92 '.zip': ('application/zip', 'zip'),
93 }
94 if not archive_specs.has_key(fileformat):
95 return 'Unknown archive type %s' % fileformat
96
97 def read_in_chunks(file_object, chunk_size=1024 * 40):
98 """Lazy function (generator) to read a file piece by piece.
99 Default chunk size: 40k."""
100 while True:
101 data = file_object.read(chunk_size)
102 if not data:
103 break
104 yield data
105
106 archive = tempfile.TemporaryFile()
107 repo = HgModel().get_repo(repo_name).repo
108 fname = '%s-%s%s' % (repo_name, revision, fileformat)
109 archival.archive(repo, archive, revision, archive_specs[fileformat][1],
110 prefix='%s-%s' % (repo_name, revision))
111 response.content_type = archive_specs[fileformat][0]
112 response.content_disposition = 'attachment; filename=%s' % fname
113 archive.seek(0)
114 return read_in_chunks(archive)
88 115
89 116 def diff(self, repo_name, f_path):
90 117 hg_model = HgModel()
General Comments 0
You need to be logged in to leave comments. Login now