allpy
changeset 973:325d165af197
allpy.processors: use NamedTemporaryFile(..., delete=True) in favour of removing the files manually (closes #137)
While writing the relevant line I failed to read the docs properly and was under impression that delete=True refers to the hack, when one creates the file and removes it at once before writing any data to it for the sake of making the file invisible. Which is actually not the case, and the file is removed after being closed.
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Sat, 25 Feb 2012 20:16:51 +0400 |
parents | 7637a33ecbd6 |
children | 21992bcc03fe |
files | allpy/processors.py |
diffstat | 1 files changed, 3 insertions(+), 5 deletions(-) [+] |
line diff
1.1 --- a/allpy/processors.py Sat Feb 25 19:25:42 2012 +0400 1.2 +++ b/allpy/processors.py Sat Feb 25 20:16:51 2012 +0400 1.3 @@ -20,17 +20,15 @@ 1.4 self.command = command 1.5 1.6 def __call__(self, block): 1.7 - kwargs = {'prefix': 'allpy_processor_', 'delete': False} 1.8 + kwargs = {'prefix': 'allpy_processor_', 'delete': True} 1.9 with NamedTemporaryFile(**kwargs) as infile: 1.10 - with NamedTemporaryFile('r', **kwargs) as outfile: 1.11 + with NamedTemporaryFile('rb', **kwargs) as outfile: 1.12 block.to_file(infile) 1.13 - infile.close() 1.14 + infile.flush() 1.15 subst_vars = {'infile': infile.name, 'outfile': outfile.name} 1.16 os.system(self.command % subst_vars) 1.17 Alignment = block.types.Alignment 1.18 new_alignment = Alignment().append_file(outfile) 1.19 - os.unlink(infile.name) 1.20 - os.unlink(outfile.name) 1.21 return new_alignment 1.22 1.23 #