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