From fa93d4e04bccd31ba347bbb916b9c7b23b6c5c9d Mon Sep 17 00:00:00 2001 From: Dave B Date: Mon, 12 Feb 2018 13:18:08 -0500 Subject: [PATCH] Close tempfile handles. --- lib/galaxy/tools/repositories.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/galaxy/tools/repositories.py b/lib/galaxy/tools/repositories.py index dec44e8e336..1a25684e6a1 100644 --- a/lib/galaxy/tools/repositories.py +++ b/lib/galaxy/tools/repositories.py @@ -27,28 +27,24 @@ class ValidationContext(object): 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