Merge pull request #6932 from mvdbeek/fix_toolshed_bugs

[18.09] Fix toolshed error in display_tool if tool is invalid
This commit is contained in:
John Chilton
2018-10-29 09:26:30 -04:00
committed by GitHub
4 changed files with 21 additions and 24 deletions
+4 -4
View File
@@ -166,10 +166,10 @@ class ToolsController(BaseAPIController):
with ValidationContext.from_app(trans.app) as validation_context:
tv = tool_validator.ToolValidator(validation_context)
repository, tool, message = tv.load_tool_from_changeset_revision(tsr_id,
changeset,
found_tool.tool_config)
if message:
repository, tool, valid, message = tv.load_tool_from_changeset_revision(tsr_id,
changeset,
found_tool.tool_config)
if message or not valid:
status = 'error'
return dict(message=message, status=status)
tool_help = ''
@@ -875,17 +875,16 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
@web.expose
def display_tool(self, trans, repository_id, tool_config, changeset_revision, **kwd):
message = escape(kwd.get('message', ''))
status = kwd.get('status', 'done')
render_repository_actions_for = kwd.get('render_repository_actions_for', 'tool_shed')
with ValidationContext.from_app(trans.app) as validation_context:
tv = tool_validator.ToolValidator(validation_context)
repository, tool, message = tv.load_tool_from_changeset_revision(repository_id,
repository, tool, valid, message = tv.load_tool_from_changeset_revision(repository_id,
changeset_revision,
tool_config)
if message:
if message or not valid:
status = 'error'
tool_state = tool_util.new_state(trans, tool, invalid=False)
tool_state = tool_util.new_state(trans, tool, invalid=not valid)
metadata = metadata_util.get_repository_metadata_by_repository_id_changeset_revision(trans.app,
repository_id,
changeset_revision,
@@ -1772,7 +1771,7 @@ class RepositoryController(BaseUIController, ratings_util.ItemRatings):
with ValidationContext.from_app(trans.app) as validation_context:
tv = tool_validator.ToolValidator(validation_context)
repository, tool, error_message = tv.load_tool_from_changeset_revision(repository_id,
repository, tool, valid, error_message = tv.load_tool_from_changeset_revision(repository_id,
changeset_revision,
tool_config)
tool_state = tool_util.new_state(trans, tool, invalid=True)
+9 -11
View File
@@ -202,7 +202,6 @@ class ToolValidator(object):
"""
message = ''
sample_files = self.copy_disk_sample_files_to_dir(repo_files_dir, work_dir)
tool_data_table_config = None
if sample_files:
if 'tool_data_table_conf.xml.sample' in sample_files:
# Load entries into the tool_data_tables if the tool requires them.
@@ -216,6 +215,7 @@ class ToolValidator(object):
def handle_sample_files_and_load_tool_from_tmp_config(self, repo, repository_id, changeset_revision,
tool_config_filename, work_dir):
tool = None
valid = False
message = ''
# We're not currently doing anything with the returned list of deleted_sample_files here. It is
# intended to help handle sample files that are in the manifest, but have been deleted from disk.
@@ -224,16 +224,13 @@ class ToolValidator(object):
if 'tool_data_table_conf.xml.sample' in sample_files:
# Load entries into the tool_data_tables if the tool requires them.
tool_data_table_config = os.path.join(work_dir, 'tool_data_table_conf.xml')
if tool_data_table_config:
error, message = self.stdtm.handle_sample_tool_data_table_conf_file(tool_data_table_config,
persist=False)
if error:
log.debug(message)
error, message = self.stdtm.handle_sample_tool_data_table_conf_file(tool_data_table_config,
persist=False)
manifest_ctx, ctx_file = hg_util.get_ctx_file_path_from_manifest(tool_config_filename, repo, changeset_revision)
if manifest_ctx and ctx_file:
tool, message2 = self.load_tool_from_tmp_config(repo, repository_id, manifest_ctx, ctx_file, work_dir)
tool, valid, message2 = self.load_tool_from_tmp_config(repo, repository_id, manifest_ctx, ctx_file, work_dir)
message = self.concat_messages(message, message2)
return tool, message, sample_files
return tool, valid, message, sample_files
def load_tool_from_changeset_revision(self, repository_id, changeset_revision, tool_config_filename):
"""
@@ -273,7 +270,7 @@ class ToolValidator(object):
displaying_invalid_tool=True)
message = self.concat_messages(message, message2)
else:
tool, message, sample_files = \
tool, valid, message, sample_files = \
self.handle_sample_files_and_load_tool_from_tmp_config(repo,
repository_id,
changeset_revision,
@@ -282,7 +279,7 @@ class ToolValidator(object):
basic_util.remove_dir(work_dir)
# Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file.
self.stdtm.reset_tool_data_tables()
return repository, tool, message
return repository, tool, valid, message
def load_tool_from_config(self, repository_id, full_path):
tool_source = get_tool_source(
@@ -308,6 +305,7 @@ class ToolValidator(object):
def load_tool_from_tmp_config(self, repo, repository_id, ctx, ctx_file, work_dir):
tool = None
valid = False
message = ''
tmp_tool_config = hg_util.get_named_tmpfile_from_ctx(ctx, ctx_file, work_dir)
if tmp_tool_config:
@@ -332,4 +330,4 @@ class ToolValidator(object):
os.unlink(tmp_tool_config)
except Exception:
pass
return tool, message
return tool, valid, message
+4 -4
View File
@@ -43,10 +43,10 @@ class RepoToolModule(ToolModule):
tv = tool_validator.ToolValidator(validation_context)
for tool_dict in tools_metadata:
if self.tool_id in [tool_dict['id'], tool_dict['guid']]:
repository, self.tool, message = tv.load_tool_from_changeset_revision(repository_id,
changeset_revision,
tool_dict['tool_config'])
if message and self.tool is None:
repository, self.tool, valid, message = tv.load_tool_from_changeset_revision(repository_id,
changeset_revision,
tool_dict['tool_config'])
if self.tool is None and message or not valid:
self.errors = 'unavailable'
break
else: