Show More
@@ -39,8 +39,9 b' from rhodecode.lib.base import BaseContr' | |||
|
39 | 39 | from rhodecode.lib.utils import EmptyChangeset |
|
40 | 40 | from rhodecode.model.scm import ScmModel |
|
41 | 41 | |
|
42 | from vcs.backends import ARCHIVE_SPECS | |
|
42 | 43 | from vcs.exceptions import RepositoryError, ChangesetError, \ |
|
43 | ChangesetDoesNotExistError, EmptyRepositoryError | |
|
44 | ChangesetDoesNotExistError, EmptyRepositoryError, InproperArchiveTypeError | |
|
44 | 45 | from vcs.nodes import FileNode |
|
45 | 46 | from vcs.utils import diffs as differ |
|
46 | 47 | |
@@ -149,52 +150,35 b' class FilesController(BaseController):' | |||
|
149 | 150 | return render('files/files_annotate.html') |
|
150 | 151 | |
|
151 | 152 | def archivefile(self, repo_name, fname): |
|
152 | archive_specs = { | |
|
153 | '.tar.bz2': ('application/x-tar', 'tbz2'), | |
|
154 | '.tar.gz': ('application/x-tar', 'tgz'), | |
|
155 | '.zip': ('application/zip', 'zip'), | |
|
156 | } | |
|
157 | 153 | |
|
158 | 154 | fileformat = None |
|
159 | 155 | revision = None |
|
156 | ext = None | |
|
160 | 157 | |
|
161 | for ext in archive_specs.keys(): | |
|
162 | archive_spec = fname.split(ext) | |
|
163 | if len(archive_spec) == 2: | |
|
164 |
fileformat = a |
|
|
158 | for a_type, ext_data in ARCHIVE_SPECS.items(): | |
|
159 | archive_spec = fname.split(ext_data[1]) | |
|
160 | if len(archive_spec) == 2 and archive_spec[1] == '': | |
|
161 | fileformat = a_type or ext_data[1] | |
|
165 | 162 | revision = archive_spec[0] |
|
166 | ||
|
167 | if not archive_specs.has_key(fileformat): | |
|
168 | return _('Unknown archive type') | |
|
169 | ||
|
170 | repo = ScmModel().get_repo(repo_name) | |
|
163 | ext = ext_data[1] | |
|
171 | 164 | |
|
172 | 165 | try: |
|
173 |
repo.get_ |
|
|
166 | repo = ScmModel().get_repo(repo_name) | |
|
167 | cs = repo.get_changeset(revision) | |
|
174 | 168 | except ChangesetDoesNotExistError: |
|
175 | 169 | return _('Unknown revision %s') % revision |
|
176 | 170 | except EmptyRepositoryError: |
|
177 | 171 | return _('Empty repository') |
|
172 | except InproperArchiveTypeError: | |
|
173 | return _('Unknown archive type') | |
|
178 | 174 | |
|
179 | archive = tempfile.TemporaryFile() | |
|
180 | localrepo = repo.repo | |
|
181 | fname = '%s-%s%s' % (repo_name, revision, fileformat) | |
|
182 | archival.archive(localrepo, archive, revision, archive_specs[fileformat][1], | |
|
183 | prefix='%s-%s' % (repo_name, revision)) | |
|
184 | response.content_type = archive_specs[fileformat][0] | |
|
185 | response.content_disposition = 'attachment; filename=%s' % fname | |
|
186 | archive.seek(0) | |
|
175 | fname = '%s-%s%s' % (repo_name, revision, ext) | |
|
187 | 176 | |
|
188 | def read_in_chunks(file_object, chunk_size=1024 * 40): | |
|
189 | """Lazy function (generator) to read a file piece by piece. | |
|
190 | Default chunk size: 40k.""" | |
|
191 | while True: | |
|
192 | data = file_object.read(chunk_size) | |
|
193 | if not data: | |
|
194 | break | |
|
195 | yield data | |
|
177 | response.content_type = ARCHIVE_SPECS[fileformat][0] | |
|
178 | response.content_disposition = 'attachment; filename=%s' % fname | |
|
196 | 179 | |
|
197 |
return |
|
|
180 | return cs.get_chunked_archive(kind=fileformat) | |
|
181 | ||
|
198 | 182 | |
|
199 | 183 | def diff(self, repo_name, f_path): |
|
200 | 184 | hg_model = ScmModel() |
General Comments 0
You need to be logged in to leave comments.
Login now