details:
http://www.bx.psu.edu/hg/galaxy/rev/53ddb4b728f7
changeset: 3512:53ddb4b728f7
user: fubar: ross Lazarus at gmail period com
date: Wed Mar 10 19:48:28 2010 -0500
description:
Reverted missing python version check for zipfile setup
Changed download archive names for both libraries and for history items
so they're related to the content - uses data.name rather than one fixed string for
all
diffstat:
lib/galaxy/web/controllers/dataset.py | 25 ++++++++++++++++---------
lib/galaxy/web/controllers/library_common.py | 13 ++++++++-----
2 files changed, 24 insertions(+), 14 deletions(-)
diffs (153 lines):
diff -r 2af472aa0844 -r 53ddb4b728f7 lib/galaxy/web/controllers/dataset.py
--- a/lib/galaxy/web/controllers/dataset.py Wed Mar 10 17:10:43 2010 -0500
+++ b/lib/galaxy/web/controllers/dataset.py Wed Mar 10 19:48:28 2010 -0500
@@ -1,4 +1,4 @@
-import logging, os, string, shutil, re, socket, mimetypes, smtplib, urllib, tempfile,
zipfile, glob
+import logging, os, string, shutil, re, socket, mimetypes, smtplib, urllib, tempfile,
zipfile, glob, sys
from galaxy.web.base.controller import *
from galaxy.web.framework.helpers import time_ago, iff, grids
@@ -11,6 +11,11 @@
pkg_resources.require( "Paste" )
import paste.httpexceptions
+if sys.version_info[:2] < ( 2, 6 ):
+ zipfile.BadZipFile = zipfile.error
+if sys.version_info[:2] < ( 2, 5 ):
+ zipfile.LargeZipFile = zipfile.error
+
tmpd = tempfile.mkdtemp()
comptypes=[]
ziptype = '32'
@@ -204,6 +209,9 @@
def archive_composite_dataset( self, trans, data=None, **kwd ):
# save a composite object into a compressed archive for downloading
params = util.Params( kwd )
+ valid_chars =
'.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ outfname = data.name[0:150]
+ outfname = ''.join(c in valid_chars and c or '_' for c in
outfname)
if (params.do_action == None):
params.do_action = 'zip' # default
msg = util.restore_text( params.get( 'msg', '' ) )
@@ -230,7 +238,7 @@
except (OSError, zipfile.BadZipFile):
error = True
log.exception( "Unable to create archive for download" )
- msg = "Unable to create archive for %s for download, please report
this error" % data.name
+ msg = "Unable to create archive for %s for download, please report
this error" % outfname
messagetype = 'error'
if not error:
current_user_roles = trans.get_current_user_roles()
@@ -239,7 +247,7 @@
fname = os.path.split(path)[-1]
basename = data.metadata.base_name
efp = data.extra_files_path
- htmlname = os.path.splitext(data.name)[0]
+ htmlname = os.path.splitext(outfname)[0]
if not htmlname.endswith(ext):
htmlname = '%s_%s' % (htmlname,ext)
archname = '%s.html' % htmlname # fake the real nature of the
html file
@@ -276,14 +284,14 @@
messagetype = 'error'
if not error:
trans.response.set_content_type(
"application/x-zip-compressed" )
- trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=GalaxyCompositeObject.zip"
+ trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=%s.zip" % outfname
return tmpfh
else:
trans.response.set_content_type( "application/x-tar" )
outext = 'tgz'
if params.do_action == 'tbz':
outext = 'tbz'
- trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=GalaxyLibraryFiles.%s" % outext
+ trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=%s.%s" % (outfname,outext)
archive.wsgi_status = trans.response.wsgi_status()
archive.wsgi_headeritems = trans.response.wsgi_headeritems()
return archive.stream
@@ -294,7 +302,8 @@
@web.expose
def display(self, trans, dataset_id=None, preview=False, filename=None, to_ext=None,
**kwd):
"""Catches the dataset id and displays file contents as
directed"""
-
+ composite_extensions = trans.app.datatypes_registry.get_composite_extensions( )
+ composite_extensions.append('html') # for archiving composite datatypes
# DEPRECATION: We still support unencoded ids for backward compatibility
try:
dataset_id = int( dataset_id )
@@ -329,8 +338,6 @@
trans.log_event( "Display dataset id: %s" % str( dataset_id ) )
if to_ext: # Saving the file
- composite_extensions =
trans.app.datatypes_registry.get_composite_extensions( )
- composite_extensions.append('html')
if data.ext in composite_extensions:
return self.archive_composite_dataset( trans, data, **kwd )
else:
@@ -340,7 +347,7 @@
valid_chars =
'.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
fname = data.name
fname = ''.join(c in valid_chars and c or '_' for c
in fname)[0:150]
- trans.response.headers["Content-Disposition"] =
"attachment; filename=GalaxyHistoryItem-%s-[%s]%s" % (data.hid, fname, to_ext)
+ trans.response.headers["Content-Disposition"] =
"attachment; filename=Galaxy%s-[%s]%s" % (data.hid, fname, to_ext)
return open( data.file_name )
if os.path.exists( data.file_name ):
max_peek_size = 1000000 # 1 MB
diff -r 2af472aa0844 -r 53ddb4b728f7 lib/galaxy/web/controllers/library_common.py
--- a/lib/galaxy/web/controllers/library_common.py Wed Mar 10 17:10:43 2010 -0500
+++ b/lib/galaxy/web/controllers/library_common.py Wed Mar 10 19:48:28 2010 -0500
@@ -1312,6 +1312,7 @@
else:
error = False
try:
+ outext = 'zip'
if action == 'zip':
# Can't use mkstemp - the file must not exist first
tmpd = tempfile.mkdtemp()
@@ -1323,8 +1324,10 @@
archive.add = lambda x, y: archive.write( x,
y.encode('CP437') )
elif action == 'tgz':
archive = util.streamball.StreamBall( 'w|gz' )
+ outext = 'gz'
elif action == 'tbz':
archive = util.streamball.StreamBall( 'w|bz2' )
+ outext = 'bz2'
except (OSError, zipfile.BadZipFile):
error = True
log.exception( "Unable to create archive for download" )
@@ -1357,11 +1360,11 @@
seen.append( path )
if is_composite: # need to add all the components from the
extra_files_path to the zip
zpath = os.path.split(path)[-1] # comes as base_name/fname
- zpathext = os.path.splitext(zpath)[-1]
+ outfname,zpathext = os.path.splitext(zpath)
if zpathext == '':
zpath = '%s.html' % zpath # fake the real nature
of the html file
try:
- archive.add(ldda.dataset.file_name,zpath)
+ archive.add(ldda.dataset.file_name,zpath) # add the
primary of a composite set
except IOError:
error = True
log.exception( "Unable to add composite parent %s to
temporary library download archive" % ldda.dataset.file_name)
@@ -1375,7 +1378,7 @@
archive.add( fpath,fname )
except IOError:
error = True
- log.exception( "Unable to add %s to temporary
library download archive" % fname)
+ log.exception( "Unable to add %s to temporary
library download archive %s" % (fname,outfname))
msg = "Unable to create archive for download,
please report this error"
messagetype = 'error'
continue
@@ -1402,11 +1405,11 @@
messagetype = 'error'
if not error:
trans.response.set_content_type(
"application/x-zip-compressed" )
- trans.response.headers[ "Content-Disposition" ]
= "attachment; filename=GalaxyLibraryFiles.%s" % action
+ trans.response.headers[ "Content-Disposition" ]
= "attachment; filename=%s.%s" % (outfname,outext)
return tmpfh
else:
trans.response.set_content_type(
"application/x-tar" )
- trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=GalaxyLibraryFiles.%s" % action
+ trans.response.headers[ "Content-Disposition" ] =
"attachment; filename=%s.%s" % (outfname,outext)
archive.wsgi_status = trans.response.wsgi_status()
archive.wsgi_headeritems = trans.response.wsgi_headeritems()
return archive.stream