[Trac-tickets] [The Trac Project] #1504: Support for downloading
files in zip format (format=zip)
The Trac Project
noreply at edgewall.com
Mon May 2 23:32:26 EDT 2005
#1504: Support for downloading files in zip format (format=zip)
---------------------+------------------------------------------------------
Id: 1504 | Status: new
Component: browser | Modified: Mon May 2 23:32:25 2005
Severity: normal | Milestone: 0.9
Priority: low | Version: devel
Owner: jonas | Reporter: PBruin
---------------------+------------------------------------------------------
I have been having some problems with downloading files from the Browser
as none of the mime types have been specified in the repository I use. To
make it easier to download files I have added a ''Zip Archive'' format
next to the ''Original Format'' at the bottom of the file view in the
Browser. This will download the file in zip format.[[BR]]
I also used the mime_type instead of the node.content_type for the
'format=raw' to prevent those ugly errors when trying to view a file has
no mime_type defined in svn.[[BR]]
Do you think this could be added to the trunk?
{{{
Index: Browser.py
===================================================================
--- Browser.py (revision 1579)
+++ Browser.py (working copy)
@@ -174,7 +174,7 @@
if req.args.get('format') == 'raw':
req.send_response(200)
- req.send_header('Content-Type', node.content_type)
+ req.send_header('Content-Type', mime_type)
req.send_header('Content-Length', node.content_length)
req.send_header('Last-Modified',
util.http_date(node.last_modified))
req.end_headers()
@@ -185,7 +185,27 @@
if not chunk:
break
req.write(chunk)
+ elif req.args.get('format') == 'zip':
+ req.send_header('Content-Type', 'application/zip')
+ req.send_header('Content-Disposition',
+ 'filename=%s.zip' % node.name )
+ req.end_headers()
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
+ from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
+
+ buf = StringIO()
+ zipfile = ZipFile(buf, 'w', ZIP_DEFLATED)
+ zipinfo = ZipInfo()
+ zipinfo.filename = node.name
+ zipinfo.date_time = time.gmtime(node.last_modified)[:6]
+ zipinfo.compress_type = ZIP_DEFLATED
+ zipfile.writestr(zipinfo, node.get_content().read())
+ zipfile.close()
+ req.write(buf.getvalue())
else:
# Generate HTML preview
content =
util.to_utf8(node.get_content().read(DISP_MAX_FILE_SIZE),
@@ -205,6 +225,10 @@
req.hdf['file.raw_href'] = raw_href
add_link(req, 'alternate', raw_href, 'Original Format',
mime_type)
+ add_link(req, 'alternate',
+ self.env.href.browser(node.path, rev=rev and
node.rev, format='zip'),
+ 'Zip Archive', 'application/zip' )
+
req.display('browser.cs')
}}}
--
Ticket URL: <http://projects.edgewall.com/trac/ticket/1504>
The Trac Project <>
More information about the Trac-Tickets
mailing list