mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-29 17:42:12 +08:00
Merge pull request #5099 from mvdbeek/toolshed_install_stability
[17.09] Toolshed install stability improvements
This commit is contained in:
@@ -143,7 +143,7 @@ class ToolShedRepository(object):
|
||||
if tool_id in tool_ids:
|
||||
self.shed_config_filename = name
|
||||
return shed_tool_conf_dict
|
||||
if self.includes_datatypes:
|
||||
if self.includes_datatypes or self.includes_data_managers:
|
||||
# We need to search by file paths here, which is less desirable.
|
||||
tool_shed = common_util.remove_protocol_and_port_from_tool_shed_url(self.tool_shed)
|
||||
for shed_tool_conf_dict in app.toolbox.dynamic_confs(include_migrated_tool_conf=True):
|
||||
|
||||
@@ -21,6 +21,7 @@ import requests
|
||||
from galaxy import util
|
||||
from galaxy.util.dictifiable import Dictifiable
|
||||
from galaxy.util.odict import odict
|
||||
from galaxy.util.renamed_temporary_file import RenamedTemporaryFile
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -186,7 +187,7 @@ class ToolDataTableManager(object):
|
||||
# add new elems
|
||||
out_elems.extend(new_elems)
|
||||
out_path_is_new = not os.path.exists(full_path)
|
||||
with open(full_path, 'wb') as out:
|
||||
with RenamedTemporaryFile(full_path) as out:
|
||||
out.write('<?xml version="1.0"?>\n<tables>\n')
|
||||
for elem in out_elems:
|
||||
out.write(util.xml_to_string(elem, pretty=True))
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Safely write file to temporary file and then move file into place."""
|
||||
# Copied from https://stackoverflow.com/a/12007885.
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
||||
class RenamedTemporaryFile(object):
|
||||
"""
|
||||
A temporary file object which will be renamed to the specified
|
||||
path on exit.
|
||||
"""
|
||||
def __init__(self, final_path, **kwargs):
|
||||
tmpfile_dir = kwargs.pop('dir', None)
|
||||
|
||||
# Put temporary file in the same directory as the location for the
|
||||
# final file so that an atomic move into place can occur.
|
||||
|
||||
if tmpfile_dir is None:
|
||||
tmpfile_dir = os.path.dirname(final_path)
|
||||
|
||||
self.tmpfile = tempfile.NamedTemporaryFile(dir=tmpfile_dir, **kwargs)
|
||||
self.final_path = final_path
|
||||
|
||||
def __getattr__(self, attr):
|
||||
"""
|
||||
Delegate attribute access to the underlying temporary file object.
|
||||
"""
|
||||
return getattr(self.tmpfile, attr)
|
||||
|
||||
def __enter__(self):
|
||||
self.tmpfile.__enter__()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if exc_type is None:
|
||||
self.tmpfile.delete = False
|
||||
result = self.tmpfile.__exit__(exc_type, exc_val, exc_tb)
|
||||
os.rename(self.tmpfile.name, self.final_path)
|
||||
else:
|
||||
result = self.tmpfile.__exit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user