def build_alert_hooks(patterns_file, warnfile, overrides_file=None):
 pattern_lines = patterns_file.readlines()
 patterns = zip(pattern_lines[0::4], pattern_lines[1::4], pattern_lines[2::4])
 _assert_is_all_blank_lines(pattern_lines[3::4], patterns_file)
 overrides_map = _read_overrides(overrides_file)
 hooks = []
 for (msgtype, regex, alert) in patterns:
  regex = overrides_map.get(regex, regex)
  regex = re.compile(regex.rstrip('\n'))
  alert_function = make_alert(warnfile, msgtype.rstrip('\n'), alert.rstrip('\n'))
  hooks.append((regex, alert_function))
 return hooks

def build_alert_hooks ( patterns_file , warnfile , overrides_file = None ) : pattern_lines = patterns_file . readlines ( ) patterns = zip ( pattern_lines [ 0 : : 4 ] , pattern_lines [ 1 : : 4 ] , pattern_lines [ 2 : : 4 ] ) _assert_is_all_blank_lines ( pattern_lines [ 3 : : 4 ] , patterns_file ) overrides_map = _read_overrides ( overrides_file ) hooks = [ ] for ( msgtype , regex , alert ) in patterns : regex = overrides_map . get ( regex , regex ) regex = re . compile ( regex . rstrip ( '\n' ) ) alert_function = make_alert ( warnfile , msgtype . rstrip ( '\n' ) , alert . rstrip ( '\n' ) ) hooks . append ( ( regex , alert_function ) ) return hooks
parse data in patterns file and transform into alert_hook list .