diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index deca35fd6a2..0f8135e9081 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -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}) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index db0b7f59644..bf1daa67c42 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -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 ): diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index c2239c4bd7c..2925db0fbe9 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -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' diff --git a/lib/galaxy/web/buildapp.py b/lib/galaxy/web/buildapp.py index 9007007dc86..333f3388980 100644 --- a/lib/galaxy/web/buildapp.py +++ b/lib/galaxy/web/buildapp.py @@ -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 ): diff --git a/lib/galaxy/web/controllers/dataset.py b/lib/galaxy/web/controllers/dataset.py index 8614d410575..f103f7a9b68 100644 --- a/lib/galaxy/web/controllers/dataset.py +++ b/lib/galaxy/web/controllers/dataset.py @@ -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" ) \ No newline at end of file + 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) ) diff --git a/templates/dataset_code.tmpl b/templates/dataset_code.tmpl index ec9fba237fc..0c7a3c76661 100644 --- a/templates/dataset_code.tmpl +++ b/templates/dataset_code.tmpl @@ -111,7 +111,7 @@
-
display data +
display data edit attributes delete