Skip to content

Commit

Permalink
use context manager for tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored and renovate[bot] committed Oct 21, 2024
1 parent 607f201 commit 468d452
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions prometheuspvesd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ def _write(self, host_list: HostList):
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
Expand Down

0 comments on commit 468d452

Please sign in to comment.