#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
 Copyright (C) 2004 jan gerber <j@reboot.fm>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Library General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'''

#
# tail -f --follow=name  /var/log/syslog | decoderbot.python

import sys
import re
fallback_change=None
fallback_end=""
fallback_start=""
pppd_connect=""

def pppd_log(line):
    global pppd_connect
    if re.search("ppd",line):
        ports=re.search("(...\ .*) (\w*) .* Serial connection established",line)
        if ports:
            pppd_connect=ports.group(1)

def jackmixer_log(line):
    global fallback_change,fallback_end,fallback_start
    if re.search("re_jackmixer",line):
        ports=re.search("(...\ .*) (\w*) re_jackmixer: switch to (.*) ports",line)
        if ports:
            port=ports.group(3)
            if port=='fallback':
                fallback_start=ports.group(1)
                fallback_end=""
                fallback_change="fallback"
            elif port=='in':
                fallback_end=ports.group(1)
                fallback_change="in"
            #print ports.group(1),"jackmixer: ",port

def update_syslog_status(input):
    while 1:
        line = input.readline()
        if not line:
            break
        jackmixer_log(line)
        pppd_log(line)

if __name__ == "__main__":
    update_syslog_status(sys.stdin)
