[hg] galaxy 2860: peeking large datasets only displays a portion...
details: http://www.bx.psu.edu/hg/galaxy/rev/682cde08c3d5 changeset: 2860:682cde08c3d5 user: Kanwei Li <kanwei@gmail.com> date: Thu Oct 08 21:02:36 2009 -0400 description: peeking large datasets only displays a portion, but allows one to override or save 2 file(s) affected in this change: lib/galaxy/web/controllers/dataset.py templates/dataset/large_file.mako diffs (64 lines): diff -r e02620ad3f41 -r 682cde08c3d5 lib/galaxy/web/controllers/dataset.py --- a/lib/galaxy/web/controllers/dataset.py Thu Oct 08 18:07:02 2009 -0400 +++ b/lib/galaxy/web/controllers/dataset.py Thu Oct 08 21:02:36 2009 -0400 @@ -199,7 +199,7 @@ return 'This link may not be followed from within Galaxy.' @web.expose - def display(self, trans, dataset_id=None, filename=None, **kwd): + def display(self, trans, dataset_id=None, filename=None, show_all=False, **kwd): """Catches the dataset id and displays file contents as directed""" data = trans.app.model.HistoryDatasetAssociation.get( dataset_id ) if not data: @@ -209,23 +209,29 @@ if data.state == trans.model.Dataset.states.UPLOAD: return trans.show_error_message( "Please wait until this dataset finishes uploading before attempting to view it." ) if filename is None or filename.lower() == "index": + file_path = data.file_name mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() ) trans.response.set_content_type(mime) trans.log_event( "Display dataset id: %s" % str( dataset_id ) ) - try: - return open( data.file_name ) - except: - raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % ( filename ) ) + else: file_path = os.path.join( data.extra_files_path, filename ) mime, encoding = mimetypes.guess_type( file_path ) if mime is None: mime = trans.app.datatypes_registry.get_mimetype_by_extension( ".".split( file_path )[-1] ) trans.response.set_content_type( mime ) - try: + + if os.path.exists( file_path ): + max_peek_size = 1000000 # 1 MB + if show_all or os.stat( file_path ).st_size < max_peek_size: return open( file_path ) - except: - raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % ( filename ) ) + else: + trans.response.set_content_type( "text/html" ) + return trans.fill_template( "/dataset/large_file.mako", + truncated_data = open( file_path ).read(max_peek_size), + data = data ) + else: + raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % ( filename ) ) else: return trans.show_error_message( "You are not allowed to access this dataset" ) diff -r e02620ad3f41 -r 682cde08c3d5 templates/dataset/large_file.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/dataset/large_file.mako Thu Oct 08 21:02:36 2009 -0400 @@ -0,0 +1,11 @@ +<%inherit file="/base.mako"/> + +<div class="warningmessagelarge"> + This dataset is large and only the first megabyte is shown below.<br /> + <a href="${h.url_for( controller='dataset', action='display', dataset_id=data.id, show_all=True )}">Show all</a> | + <a href="${h.url_for( controller='root', action='display', id=data.id, tofile='yes', toext=data.ext )}">Save</a> +</div> + +<pre> +${ truncated_data } +</pre>
participants (1)
-
Greg Von Kuster