From 6505b7b0a5a0f593769ed0985242d6715c41c18a Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@ie.suberic.net> Date: Sat, 26 May 2012 19:50:18 +0100 Subject: [PATCH] Use a with statement. --- chkcrontab_lib.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/chkcrontab_lib.py b/chkcrontab_lib.py index 52a7bb3..88e6f6b 100755 --- a/chkcrontab_lib.py +++ b/chkcrontab_lib.py @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# For Python 2.5 +from __future__ import with_statement + """Processes crontab files and try to catch common errors. Parse crontab files and check each type of line for potential syntax errors. @@ -1024,14 +1027,15 @@ def CheckCrontab(crontab_file, log): line_no = 0 cron_line_factory = CronLineFactory() - for line in open(crontab_file, 'r'): - line = line.strip() - line_no += 1 + with open(crontab_file, 'r') as crontab_f: + for line in crontab_f: + line = line.strip() + line_no += 1 - cron_line = cron_line_factory.ParseLine(line) - cron_line.ValidateAndLog(log) + cron_line = cron_line_factory.ParseLine(line) + cron_line.ValidateAndLog(log) - log.Emit(line_no, line) + log.Emit(line_no, line) # Summarize the log messages if there were any. return log.Summary() -- GitLab