commit/galaxy-central: greg: Enhance the process for displaying a workflow in a tool shed repository so that workflows in change sets other than the repository tip can be viewed.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/9301e65263cf/ changeset: 9301e65263cf user: greg date: 2011-11-29 17:15:10 summary: Enhance the process for displaying a workflow in a tool shed repository so that workflows in change sets other than the repository tip can be viewed. affected #: 3 files diff -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 -r 9301e65263cf292d2f047b075aaf067444f60c73 lib/galaxy/webapps/community/controllers/common.py --- a/lib/galaxy/webapps/community/controllers/common.py +++ b/lib/galaxy/webapps/community/controllers/common.py @@ -765,6 +765,48 @@ ToolClass = Tool return ToolClass( config_file, root, trans.app ) return None +def load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config ): + repository = get_repository( trans, repository_id ) + repo = hg.repository( get_configured_ui(), repository.repo_path ) + tool = None + message = '' + if changeset_revision == repository.tip: + try: + tool = load_tool( trans, os.path.abspath( tool_config ) ) + except Exception, e: + tool = None + message = "Error loading tool: %s. Clicking <b>Reset metadata</b> may correct this error." % str( e ) + else: + # Get the tool config file name from the hgweb url, something like: + # /repos/test/convert_chars1/file/e58dcf0026c7/convert_characters.xml + old_tool_config_file_name = tool_config.split( '/' )[ -1 ] + ctx = get_changectx_for_changeset( trans, repo, changeset_revision ) + fctx = None + for filename in ctx: + filename_head, filename_tail = os.path.split( filename ) + if filename_tail == old_tool_config_file_name: + fctx = ctx[ filename ] + break + if fctx: + # Write the contents of the old tool config to a temporary file. + fh = tempfile.NamedTemporaryFile( 'w' ) + tmp_filename = fh.name + fh.close() + fh = open( tmp_filename, 'w' ) + fh.write( fctx.data() ) + fh.close() + try: + tool = load_tool( trans, tmp_filename ) + except Exception, e: + tool = None + message = "Error loading tool: %s. Clicking <b>Reset metadata</b> may correct this error." % str( e ) + try: + os.unlink( tmp_filename ) + except: + pass + else: + tool = None + return tool, message def build_changeset_revision_select_field( trans, repository, selected_value=None, add_id_to_name=True ): """ Build a SelectField whose options are the changeset_revision diff -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 -r 9301e65263cf292d2f047b075aaf067444f60c73 lib/galaxy/webapps/community/controllers/repository.py --- a/lib/galaxy/webapps/community/controllers/repository.py +++ b/lib/galaxy/webapps/community/controllers/repository.py @@ -1905,46 +1905,7 @@ status = params.get( 'status', 'done' ) webapp = params.get( 'webapp', 'community' ) repository = get_repository( trans, repository_id ) - repo = hg.repository( get_configured_ui(), repository.repo_path ) - valid = True - if changeset_revision == repository.tip: - try: - tool = load_tool( trans, os.path.abspath( tool_config ) ) - except Exception, e: - tool = None - valid = False - message = "Error loading tool: %s. Clicking <b>Reset metadata</b> may correct this error." % str( e ) - else: - # Get the tool config file name from the hgweb url, something like: - # /repos/test/convert_chars1/file/e58dcf0026c7/convert_characters.xml - old_tool_config_file_name = tool_config.split( '/' )[ -1 ] - ctx = get_changectx_for_changeset( trans, repo, changeset_revision ) - fctx = None - for filename in ctx: - filename_head, filename_tail = os.path.split( filename ) - if filename_tail == old_tool_config_file_name: - fctx = ctx[ filename ] - break - if fctx: - # Write the contents of the old tool config to a temporary file. - fh = tempfile.NamedTemporaryFile( 'w' ) - tmp_filename = fh.name - fh.close() - fh = open( tmp_filename, 'w' ) - fh.write( fctx.data() ) - fh.close() - try: - tool = load_tool( trans, tmp_filename ) - except Exception, e: - tool = None - valid = False - message = "Error loading tool: %s. Clicking <b>Reset metadata</b> may correct this error." % str( e ) - try: - os.unlink( tmp_filename ) - except: - pass - else: - tool = None + tool, message = load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config ) tool_state = self.__new_state( trans ) is_malicious = change_set_is_malicious( trans, repository_id, repository.tip ) try: diff -r 5db0da0007fcc59bb23f0e0ae2edb1e961702f14 -r 9301e65263cf292d2f047b075aaf067444f60c73 lib/galaxy/webapps/community/controllers/workflow.py --- a/lib/galaxy/webapps/community/controllers/workflow.py +++ b/lib/galaxy/webapps/community/controllers/workflow.py @@ -22,13 +22,13 @@ module.state = dict( name="Input Dataset" ) return module @classmethod - def from_dict( Class, trans, d, tools_metadata=None, secure=True ): + def from_dict( Class, trans, repository_id, changeset_revision, step_dict, tools_metadata=None, secure=True ): module = Class( trans ) - state = from_json_string( d[ "tool_state" ] ) + state = from_json_string( step_dict[ "tool_state" ] ) module.state = dict( name=state.get( "name", "Input Dataset" ) ) return module @classmethod - def from_workflow_step( Class, trans, tools_metadata, step ): + def from_workflow_step( Class, trans, repository_id, changeset_revision, tools_metadata, step ): module = Class( trans ) module.state = dict( name="Input Dataset" ) if step.tool_inputs and "name" in step.tool_inputs: @@ -39,35 +39,38 @@ type = "tool" - def __init__( self, trans, tools_metadata, tool_id ): + def __init__( self, trans, repository_id, changeset_revision, tools_metadata, tool_id ): self.trans = trans self.tools_metadata = tools_metadata self.tool_id = tool_id self.tool = None + self.errors = None for tool_dict in tools_metadata: if self.tool_id in [ tool_dict[ 'id' ], tool_dict[ 'guid' ] ]: - self.tool = load_tool( trans, os.path.abspath( tool_dict[ 'tool_config' ] ) ) + self.tool, message = load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_dict[ 'tool_config' ] ) + if message and self.tool is None: + self.errors = 'unavailable' + break self.post_job_actions = {} self.workflow_outputs = [] self.state = None - self.errors = None @classmethod - def new( Class, trans, tools_metadata, tool_id=None ): - module = Class( trans, tools_metadata, tool_id ) + def new( Class, trans, repository_id, changeset_revision, tools_metadata, tool_id=None ): + module = Class( trans, repository_id, changeset_revision, tools_metadata, tool_id ) module.state = module.tool.new_state( trans, all_pages=True ) return module @classmethod - def from_dict( Class, trans, d, tools_metadata, secure=True ): - tool_id = d[ 'tool_id' ] - module = Class( trans, tools_metadata, tool_id ) + def from_dict( Class, trans, repository_id, changeset_revision, step_dict, tools_metadata, secure=True ): + tool_id = step_dict[ 'tool_id' ] + module = Class( trans, repository_id, changeset_revision, tools_metadata, tool_id ) module.state = DefaultToolState() if module.tool is not None: - module.state.decode( d[ "tool_state" ], module.tool, module.trans.app, secure=secure ) - module.errors = d.get( "tool_errors", None ) + module.state.decode( step_dict[ "tool_state" ], module.tool, module.trans.app, secure=secure ) + module.errors = step_dict.get( "tool_errors", None ) return module @classmethod - def from_workflow_step( Class, trans, tools_metadata, step ): - module = Class( trans, tools_metadata, step.tool_id ) + def from_workflow_step( Class, trans, repository_id, changeset_revision, tools_metadata, step ): + module = Class( trans, repository_id, changeset_revision, tools_metadata, step.tool_id ) module.state = DefaultToolState() if module.tool: module.state.inputs = module.tool.params_from_strings( step.tool_inputs, trans.app, ignore_errors=True ) @@ -115,18 +118,18 @@ def __init__( self, module_types ): self.module_types = module_types def new( self, trans, type, tools_metadata=None, tool_id=None ): - """Return module for type and (optional) tool_id intialized with new / default state.""" + """Return module for type and (optional) tool_id initialized with new / default state.""" assert type in self.module_types return self.module_types[type].new( trans, tool_id ) - def from_dict( self, trans, d, **kwargs ): - """Return module initialized from the data in dictionary `d`.""" - type = d[ 'type' ] + def from_dict( self, trans, repository_id, changeset_revision, step_dict, **kwd ): + """Return module initialized from the data in dictionary `step_dict`.""" + type = step_dict[ 'type' ] assert type in self.module_types - return self.module_types[ type ].from_dict( trans, d, **kwargs ) - def from_workflow_step( self, trans, tools_metadata, step ): + return self.module_types[ type ].from_dict( trans, repository_id, changeset_revision, step_dict, **kwd ) + def from_workflow_step( self, trans, repository_id, changeset_revision, tools_metadata, step ): """Return module initialized from the WorkflowStep object `step`.""" type = step.type - return self.module_types[ type ].from_workflow_step( trans, tools_metadata, step ) + return self.module_types[ type ].from_workflow_step( trans, repository_id, changeset_revision, tools_metadata, step ) module_factory = RepoWorkflowModuleFactory( dict( data_input=RepoInputDataModule, tool=RepoToolModule ) ) @@ -153,6 +156,8 @@ @web.expose def generate_workflow_image( self, trans, repository_metadata_id, workflow_name, webapp='community' ): repository_metadata = get_repository_metadata_by_id( trans, repository_metadata_id ) + repository_id = trans.security.encode_id( repository_metadata.repository_id ) + changeset_revision = repository_metadata.changeset_revision metadata = repository_metadata.metadata workflow_name = decode( workflow_name ) for workflow_dict in metadata[ 'workflows' ]: @@ -162,7 +167,7 @@ tools_metadata = metadata[ 'tools' ] else: tools_metadata = [] - workflow, missing_tool_tups = self.__workflow_from_dict( trans, workflow_dict, tools_metadata ) + workflow, missing_tool_tups = self.__workflow_from_dict( trans, workflow_dict, tools_metadata, repository_id, changeset_revision ) data = [] canvas = svgfig.canvas( style="stroke:black; fill:none; stroke-width:1px; stroke-linejoin:round; text-anchor:left" ) text = svgfig.SVG( "g" ) @@ -179,7 +184,7 @@ max_width, max_x, max_y = 0, 0, 0 for step in workflow.steps: step.upgrade_messages = {} - module = module_factory.from_workflow_step( trans, tools_metadata, step ) + module = module_factory.from_workflow_step( trans, repository_id, changeset_revision, tools_metadata, step ) tool_errors = module.type == 'tool' and not module.tool module_data_inputs = self.__get_data_inputs( step, module ) module_data_outputs = self.__get_data_outputs( step, module, workflow.steps ) @@ -308,11 +313,11 @@ data_outputs.append( data_outputs_dict ) return data_outputs return module.get_data_outputs() - def __workflow_from_dict( self, trans, data, tools_metadata ): + def __workflow_from_dict( self, trans, workflow_dict, tools_metadata, repository_id, changeset_revision ): """Creates and returns workflow object from a dictionary.""" trans.workflow_building_mode = True workflow = model.Workflow() - workflow.name = data[ 'name' ] + workflow.name = workflow_dict[ 'name' ] workflow.has_errors = False steps = [] # Keep ids for each step that we need to use to make connections. @@ -322,12 +327,12 @@ # will be ( tool_id, tool_name, tool_version ). missing_tool_tups = [] # First pass to build step objects and populate basic values - for key, step_dict in data[ 'steps' ].iteritems(): + for key, step_dict in workflow_dict[ 'steps' ].iteritems(): # Create the model class for the step step = model.WorkflowStep() step.name = step_dict[ 'name' ] step.position = step_dict[ 'position' ] - module = module_factory.from_dict( trans, step_dict, tools_metadata=tools_metadata, secure=False ) + module = module_factory.from_dict( trans, repository_id, changeset_revision, step_dict, tools_metadata=tools_metadata, secure=False ) if module.type == 'tool' and module.tool is None: # A required tool is not available in the current repository. step.tool_errors = 'unavailable' Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket