Skip to content

Commit

Permalink
Close tempfile handles.
Browse files Browse the repository at this point in the history
  • Loading branch information
davebx committed Feb 16, 2018
1 parent 6b0e20a commit fa93d4e
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/galaxy/tools/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,24 @@ def __init__(self, app_name,
self.config = Bunch()
self.config.tool_data_path = tool_data_path
self.config.shed_tool_data_path = shed_tool_data_path
_, self.config.tool_data_table_config = tempfile.mkstemp()
_, self.config.shed_tool_data_table_config = tempfile.mkstemp()
self.temporary_path = tempfile.mkdtemp(prefix='tool_validation_')
self.config.tool_data_table_config = os.path.join(self.temporary_path, 'tool_data_table_conf.xml')
self.config.shed_tool_data_table_config = os.path.join(self.temporary_path, 'shed_tool_data_table_conf.xml')
self.tool_data_tables = tool_data_tables
self.datatypes_registry = registry or Registry()
self.hgweb_config_manager = hgweb_config_manager
_, self.config.len_file_path = tempfile.mkstemp()
_, self.config.builds_file_path = tempfile.mkstemp()
self.config.len_file_path = os.path.join(self.temporary_path, 'chromlen.txt')
# If the builds file path is set to None, tools/__init__.py will load the default.
# Otherwise it will attempt to load a nonexistent file and log an error. This does
# not appear to be an issue with the len_file_path config option.
self.config.builds_file_path = None
self.genome_builds = GenomeBuilds(self)

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
cleanup_paths = {self.config.builds_file_path,
self.config.len_file_path,
self.config.tool_data_table_config,
self.config.shed_tool_data_table_config}
for path in cleanup_paths:
try:
os.remove(path)
except Exception:
pass
shutil.rmtree(self.temporary_path)

@staticmethod
@contextmanager
Expand Down

0 comments on commit fa93d4e

Please sign in to comment.