Changeset - b872bc10f4ec
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 14 years ago 2012-05-15 19:29:02
marcin@python-works.com
cleanup code of get archive for repositories
2 files changed with 10 insertions and 14 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/files.py
Show inline comments
 
@@ -23,12 +23,13 @@
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import os
 
import logging
 
import traceback
 
import tempfile
 

	
 
from pylons import request, response, tmpl_context as c, url
 
from pylons.i18n.translation import _
 
from pylons.controllers.util import redirect
 
from pylons.decorators import jsonify
 

	
 
@@ -356,31 +357,28 @@ class FilesController(BaseRepoController
 
            return _('Unknown revision %s') % revision
 
        except EmptyRepositoryError:
 
            return _('Empty repository')
 
        except (ImproperArchiveTypeError, KeyError):
 
            return _('Unknown archive type')
 

	
 
        archive = tempfile.NamedTemporaryFile(mode='w+r+b')
 
        cs.fill_archive(stream=archive, kind=fileformat, subrepos=subrepos)
 

	
 
        response.content_type = content_type
 
        response.content_disposition = 'attachment; filename=%s-%s%s' \
 
            % (repo_name, revision, ext)
 

	
 
        import tempfile
 
        archive = tempfile.mkstemp()[1]
 
        t = open(archive, 'wb')
 
        cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos)
 
            % (repo_name, revision[:12], ext)
 
        response.content_length = str(os.path.getsize(archive.name))
 

	
 
        def get_chunked_archive(archive):
 
            stream = open(archive, 'rb')
 
        def get_chunked_archive(tmpfile):
 
            while True:
 
                data = stream.read(4096)
 
                data = tmpfile.read(16 * 1024)
 
                if not data:
 
                    os.remove(archive)
 
                    tmpfile.close()
 
                    break
 
                yield data
 

	
 
        return get_chunked_archive(archive)
 
        return get_chunked_archive(tmpfile=archive)
 

	
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def diff(self, repo_name, f_path):
 
        ignore_whitespace = request.GET.get('ignorews') == '1'
 
        line_context = request.GET.get('context', 3)
rhodecode/lib/vcs/backends/hg/changeset.py
Show inline comments
 
@@ -260,14 +260,12 @@ class MercurialChangeset(BaseChangeset):
 
        elif prefix.strip() == '':
 
            raise VCSError("Prefix cannot be empty")
 

	
 
        archival.archive(self.repository._repo, stream, self.raw_id,
 
                         kind, prefix=prefix, subrepos=subrepos)
 

	
 
        #stream.close()
 

	
 
        if stream.closed and hasattr(stream, 'name'):
 
            stream = open(stream.name, 'rb')
 
        elif hasattr(stream, 'mode') and 'r' not in stream.mode:
 
            stream = open(stream.name, 'rb')
 
        else:
 
            stream.seek(0)
0 comments (0 inline, 0 general)