From 468d45299618e8a818fb52d3fa96cd7f05fed278 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 21 Oct 2024 20:25:28 +0200 Subject: [PATCH] use context manager for tempfile --- prometheuspvesd/cli.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/prometheuspvesd/cli.py b/prometheuspvesd/cli.py index 36a4a21..8a92c9f 100644 --- a/prometheuspvesd/cli.py +++ b/prometheuspvesd/cli.py @@ -174,11 +174,10 @@ class PrometheusSD: output.append(host.to_sd_json()) # Write to tmp file and move after write - temp_file = tempfile.NamedTemporaryFile(mode="w", prefix="prometheus-pve-sd", delete=False) - with temp_file as tf: + with tempfile.NamedTemporaryFile(mode="w", prefix="prometheus-pve-sd", delete=False) as tf: json.dump(output, tf, indent=4) - shutil.move(temp_file.name, self.config.config["output_file"]) + shutil.move(tf.name, self.config.config["output_file"]) chmod(self.config.config["output_file"], int(self.config.config["output_file_mode"], 8)) def _terminate(self, signal, frame): # noqa