mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-11-24 02:10:40 +00:00
use context manager for tempfile
This commit is contained in:
parent
607f201888
commit
468d452996
@ -174,11 +174,10 @@ class PrometheusSD:
|
|||||||
output.append(host.to_sd_json())
|
output.append(host.to_sd_json())
|
||||||
|
|
||||||
# Write to tmp file and move after write
|
# Write to tmp file and move after write
|
||||||
temp_file = tempfile.NamedTemporaryFile(mode="w", prefix="prometheus-pve-sd", delete=False)
|
with tempfile.NamedTemporaryFile(mode="w", prefix="prometheus-pve-sd", delete=False) as tf:
|
||||||
with temp_file as tf:
|
|
||||||
json.dump(output, tf, indent=4)
|
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))
|
chmod(self.config.config["output_file"], int(self.config.config["output_file_mode"], 8))
|
||||||
|
|
||||||
def _terminate(self, signal, frame): # noqa
|
def _terminate(self, signal, frame): # noqa
|
||||||
|
Loading…
Reference in New Issue
Block a user