Use NamedTemporaryFile opened in text mode

This commit is contained in:
Nicola Soranzo
2018-08-21 12:35:06 +01:00
parent 61041a7c6b
commit cd11a8c19a
+4 -8
View File
@@ -1,15 +1,11 @@
import logging
import os
import tempfile
from six import string_types, text_type
from six.moves import shlex_quote
from galaxy import exceptions
from galaxy.util import (
odict,
smart_str,
)
from galaxy.util import odict
from galaxy.util.none_like import NoneDataset
from galaxy.util.object_wrapper import wrap_with_safe_string
@@ -321,10 +317,10 @@ class HasDatasets(object):
return DatasetFilenameWrapper(dataset, **wrapper_kwds)
def paths_as_file(self, sep="\n"):
handle, filepath = tempfile.mkstemp(prefix="gx_file_list", dir=self.job_working_directory)
contents = sep.join(map(str, self))
os.write(handle, smart_str(contents))
os.close(handle)
with tempfile.NamedTemporaryFile(mode='w+', prefix="gx_file_list", dir=self.job_working_directory, delete=False) as fh:
fh.write(contents)
filepath = fh.name
return filepath