python: Migrate open statements to use with.

This is low priority, but it's nice to be consistently using the best
practice pattern.

Fixes: #12419.
This commit is contained in:
Wyatt Hoodes
2019-07-14 09:37:08 -10:00
committed by Tim Abbott
parent e97179fc87
commit e331a758c3
30 changed files with 101 additions and 81 deletions

View File

@@ -18,7 +18,8 @@ def nagios_from_file(results_file: str, max_time_diff: int=60 * 2) -> 'Tuple[int
This file is created by various nagios checking cron jobs such as
check-rabbitmq-queues and check-rabbitmq-consumers"""
data = open(results_file).read().strip()
with open(results_file, 'r') as f:
data = f.read().strip()
pieces = data.split('|')
if not len(pieces) == 4:

View File

@@ -34,7 +34,8 @@ down_count = 0
for results_file_name in os.listdir(RESULTS_DIR):
this_state = "OK"
results_file = os.path.join(RESULTS_DIR, results_file_name)
data = open(results_file).read().strip()
with open(results_file, 'r') as f:
data = f.read().strip()
last_check = os.stat(results_file).st_mtime
time_since_last_check = time.time() - last_check
# time_since_last_check threshold needs to be strictly greater

View File

@@ -32,7 +32,8 @@ def report(state, data, last_check):
data))
exit(states[state])
data = open(RESULTS_FILE).read().strip()
with open(RESULTS_FILE, 'r') as f:
data = f.read().strip()
if data.split("\n")[-1].strip() == "0":
state = "OK"
else: