mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add ability to have a directory of files associated with an individual dataset. Relative links in html work.
Put all desired files in the directory specified in a tool XML as $output.files_path. Example: <command interpreter="python">script.py $input $output $output.files_path</command> becomes: python ./tools/filters/script.py ./database/files/dataset_1.dat ./database/files/dataset_2.dat ./database/tmp/dataset_2_files Any file put in ./database/tmp/dataset_2_files will be accessable to html files using a relative link. Directories are moved to a more permanent location only if they contain files.
This commit is contained in:
@@ -286,6 +286,8 @@ class JobWrapper( object ):
|
||||
out_data = dict( [ ( da.name, da.dataset ) for da in job.output_datasets ] )
|
||||
param_dict = dict( [ ( p.name, p.value ) for p in job.parameters ] )
|
||||
param_dict = self.tool.params_from_strings( param_dict, self.app )
|
||||
# Check for and move associated_files
|
||||
self.tool.collect_associated_files(out_data)
|
||||
# Create generated output children and primary datasets and add to param_dict
|
||||
collected_datasets = {'children':self.tool.collect_child_datasets(out_data),'primary':self.tool.collect_primary_datasets(out_data)}
|
||||
param_dict.update({'__collected_datasets__':collected_datasets})
|
||||
|
||||
@@ -278,6 +278,8 @@ class Dataset( object ):
|
||||
self.purged = True
|
||||
try: os.unlink(self.file_name)
|
||||
except: pass
|
||||
try: os.unlink(os.path.join(self.file_path, "dataset_%d_files" % (self.id)))
|
||||
except: pass
|
||||
def get_converter_types(self):
|
||||
return self.datatype.get_converter_types( self, datatypes_registry)
|
||||
def add_validation_error( self, validation_error ):
|
||||
|
||||
@@ -778,6 +778,8 @@ class Tool:
|
||||
param_dict[ key ] = DatasetFilenameWrapper( child )
|
||||
for name, data in output_datasets.items():
|
||||
param_dict[name] = DatasetFilenameWrapper( data )
|
||||
# Provide access to a path to store additional files
|
||||
param_dict[name].files_path = os.path.join(self.app.config.new_file_path, "dataset_%s_files" % (data.id) )
|
||||
for child_association in data.children:
|
||||
child = child_association.child
|
||||
key = "_CHILD___%s___%s" % ( name, child.designation )
|
||||
@@ -860,8 +862,18 @@ class Tool:
|
||||
return code( *args, **kwargs )
|
||||
except Exception, e:
|
||||
e.args = ( "Error in '%s' hook '%s', original message: %s" % ( self.name, hook_name, e.args[0] ) )
|
||||
raise
|
||||
|
||||
raise
|
||||
|
||||
def collect_associated_files( self, output):
|
||||
for name, outdata in output.items():
|
||||
temp_file_path = os.path.join(self.app.config.new_file_path, "dataset_%s_files" % (outdata.id) )
|
||||
try:
|
||||
if len(os.listdir(temp_file_path)) > 0:
|
||||
store_file_path = os.path.join(self.app.config.file_path, "dataset_%s_files" % (outdata.id) )
|
||||
shutil.move(temp_file_path, store_file_path)
|
||||
except:
|
||||
continue
|
||||
|
||||
def collect_child_datasets( self, output):
|
||||
children = {}
|
||||
#Loop through output file names, looking for generated children in form of 'child_parentId_designation_visibility_extension'
|
||||
|
||||
@@ -47,6 +47,7 @@ def app_factory( global_conf, **kwargs ):
|
||||
webapp.add_route( '/async/:tool_id/:data_id/:data_secret', controller='async', action='index', tool_id=None, data_id=None, data_secret=None )
|
||||
webapp.add_route( '/:controller/:action', action='index' )
|
||||
webapp.add_route( '/:action', controller='root', action='index' )
|
||||
webapp.add_route( '/datasets/:dataset_id/:action/:filename', controller='dataset', action='index', dataset_id=None, filename=None)
|
||||
webapp.finalize_config()
|
||||
# Wrap the webapp in some useful middleware
|
||||
if kwargs.get( 'middleware', True ):
|
||||
|
||||
@@ -10,6 +10,10 @@ from cgi import escape, FieldStorage
|
||||
import smtplib
|
||||
from email.MIMEText import MIMEText
|
||||
|
||||
import pkg_resources;
|
||||
pkg_resources.require( "Paste" )
|
||||
import paste.httpexceptions
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
error_report_template = """
|
||||
@@ -82,4 +86,34 @@ class DatasetInterface( BaseController ):
|
||||
s.close()
|
||||
return trans.show_ok_message( "Your error report has been sent" )
|
||||
except:
|
||||
return trans.show_error_message( "An error occurred sending the report by email" )
|
||||
return trans.show_error_message( "An error occurred sending the report by email" )
|
||||
|
||||
@web.expose
|
||||
def default(self, trans, dataset_id=None, **kwd):
|
||||
return 'This link may not be followed from within Galaxy.'
|
||||
|
||||
@web.expose
|
||||
def display(self, trans, dataset_id=None, filename=None, **kwd):
|
||||
"""Catches the dataset id and displays file contents as directed"""
|
||||
if filename is None or filename.lower() == "index":
|
||||
try:
|
||||
data = trans.app.model.Dataset.get( dataset_id )
|
||||
if data:
|
||||
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:
|
||||
return "This item contains no content"
|
||||
except:
|
||||
pass
|
||||
return "Invalid dataset specified"
|
||||
else:
|
||||
#display files from directory here
|
||||
try:
|
||||
file_path = os.path.join(trans.app.config.file_path, "dataset_%s_files" % (dataset_id))
|
||||
file_path = os.path.join(file_path, filename)
|
||||
return open(file_path)
|
||||
except:
|
||||
raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % (filename) )
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<div style="float: right;"><a href="$h.url_for( 'display', id=data.id )" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
|
||||
<div style="float: right;"><a href="/datasets/$data.id/display/index" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
|
||||
<a href="edit?id=$data.id" target="galaxy_main"><img src="$h.url_for('/static/images/pencil_icon.png')" rollover="$h.url_for('/static/images/pencil_icon_dark.png')" width='16' height='16' alt='edit attributes' title='edit attributes' class='editButton' border='0'></a>
|
||||
<a href="delete?id=$data.id" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="$h.url_for('/static/images/delete_icon.png')" rollover="$h.url_for('/static/images/delete_icon_dark.png')" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
|
||||
<!--
|
||||
|
||||
@@ -179,7 +179,7 @@ div#footer {
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<div style="float: right;"><a href="$h.url_for( 'display', id=data.id )" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
|
||||
<div style="float: right;"><a href="/datasets/$data.id/display/index" target="_top"><img src="$h.url_for('/static/images/eye_icon.png')" rollover="$h.url_for('/static/images/eye_icon_dark.png')" width='16' height='16' alt='display data' title='display data' class='displayButton' border='0'></a>
|
||||
<a href="edit?id=$data.id" target="galaxy_main"><img src="$h.url_for('/static/images/pencil_icon.png')" rollover="$h.url_for('/static/images/pencil_icon_dark.png')" width='16' height='16' alt='edit attributes' title='edit attributes' class='editButton' border='0'></a>
|
||||
<a href="delete?id=$data.id" class="historyItemDelete" id="historyItemDelter-${data.id}"><img src="$h.url_for('/static/images/delete_icon.png')" rollover="$h.url_for('/static/images/delete_icon_dark.png')" width='16' height='16' alt='delete' class='deleteButton' border='0'></a>
|
||||
<!--
|
||||
|
||||
Reference in New Issue
Block a user