From 76fa6dd8dbdbe9bf30fb608e7d9775759bea7677 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Thu, 22 Aug 2013 14:38:18 -0700 Subject: [PATCH] make sure we close this file handle --- configure-syslog.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/configure-syslog.py b/configure-syslog.py index 0799cf3..995ee5f 100644 --- a/configure-syslog.py +++ b/configure-syslog.py @@ -651,7 +651,6 @@ def get_installed_syslog_configuration(syslog_id): source = '' Logger.printLog("Reading default configuration directory path from (%s)." % default_config_file_name.get(syslog_id), prio = 'debug') - text_file = open(default_config_file_name.get(syslog_id), "r") if syslog_id == PROD_RSYSLOG: include_pattern = r"^\s*[^#]\s*IncludeConfig\s+([\S]+/)" @@ -673,18 +672,19 @@ def get_installed_syslog_configuration(syslog_id): auth_token_compiled_regex = re.compile(auth_token_pattern, re.MULTILINE | re.IGNORECASE) - for line in text_file: - if len(default_directory) <= 0: - include_match_grp = include_compiled_regex.match(line.rstrip('\n')) - if include_match_grp: - default_directory = include_match_grp.group(1) - default_directory = default_directory.lstrip('"').rstrip('"') - - if len(auth_token) <= 0: - auth_token_match_grp = auth_token_compiled_regex.match\ - (line.rstrip('\n')) - if auth_token_match_grp: - auth_token = auth_token_match_grp.group(1) + with open(default_config_file_name.get(syslog_id), "r") as text_file: + for line in text_file: + if not default_directory: + include_match_grp = include_compiled_regex.match(line.rstrip('\n')) + if include_match_grp: + default_directory = include_match_grp.group(1) + default_directory = default_directory.lstrip('"').rstrip('"') + + if not auth_token: + auth_token_match_grp = auth_token_compiled_regex.match\ + (line.rstrip('\n')) + if auth_token_match_grp: + auth_token = auth_token_match_grp.group(1) if syslog_id == PROD_SYSLOG_NG: source = get_syslog_ng_source(default_config_file_name.get(syslog_id))