-
Raphael Kubo da Costa authored
Sometimes, InputApi users need to create temporary files, write to them and pass them to another process, like this: with input_api.tempfile.NamedTemporaryFile() as f: f.write('foo') input_api.subprocess.check_output(['/path/to/script', '--reading-from', f.name]) While this works fine on Unix, on Windows subprocess cannot open and read the file while we have it open for writing. To work around this, we now offer a CreateTemporaryFile() that wraps a call to tempfile.NamedTemporaryFile(delete=False), and we then take care of removing all files created this way at the end of a presubmit run. The idea is for users to do something like this: with input_api.CreateTemporaryFile() as f: f.write('foo') f.close() input_api.subprocess.check_output(['/path/to/script', '--reading-from', f.name]) with the temporary file being removed automatically in a transparent fashion later. Bug: 780629 Change-Id: I0d705a5d52928a43f39a51f94a2c48d277bd5ced Reviewed-on: https://chromium-review.googlesource.com/758637 Commit-Queue: Raphael Kubo da Costa (rakuco) <raphael.kubo.da.costa@intel.com> Reviewed-by: Aaron Gable <agable@chromium.org>
f2d1615b