From 57531aaa135ea6ad19430ff8d5398a378db4e7b4 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 17 Nov 2014 17:14:48 +0000 Subject: Clean up use of a temporary file slightly --- baserockimport/mainloop.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index 345e45e..a84d547 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -327,17 +327,14 @@ class ImportLoop(object): return lorry def _run_lorry(self, lorry): - f = tempfile.NamedTemporaryFile(delete=False) - try: + with tempfile.NamedTemporaryFile() as f: logging.debug(json.dumps(lorry)) json.dump(lorry, f) - f.close() + f.flush() cliapp.runcmd([ 'lorry', '--working-area', self.app.settings['lorry-working-dir'], '--pull-only', '--bundle', 'never', '--tarball', 'never', f.name]) - finally: - os.unlink(f.name) def _fetch_or_update_source(self, lorry): assert len(lorry) == 1 -- cgit v1.2.1