<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Name="Configuration Tree" Expanded="True" Version="1462" Guid="{2A057C55-1C84-4206-A12A-3E312E5E194A}" Time="1271400612.32">
    <Autostart Name="Autostart" Expanded="True">
        <Plugin File="DirectoryWatcher" Identifier="DirectoryWatcher">
            gAJYCwAAAEQ6XFRlbXBcTE9HcQCIhnEBLg==
        </Plugin>
        <Plugin File="FileOperations" Identifier="FileOperations">
            gAIpLg==
        </Plugin>
        <Plugin File="Timer" Identifier="Timer">
            gAIpLg==
        </Plugin>
    </Autostart>
    <Folder Name="Example config" Expanded="True">
        <Macro Name="After init of EG find the latest log file and starts monitoring" Expanded="True">
            <Event Name="Main.OnInit" />
            <Action>
                EventGhost.PythonScript(u'pattern = "BTV-XXXXXXXXXX.log"\npth = r"D:\\Temp\\LOG"\n\nfrom os import path, listdir\n#Find all the log files that match the pattern:\nfiles = [(path.getmtime(path.join(pth,f)), path.join(pth,f)) for f in listdir(pth) if (f[:4] == pattern[:4] and f[-4:] == pattern[-4:])]\n#sort log sort files by time changes:\nfiles.sort()\n#last changed file:\nlastLogFile = files[-1][1]\n#if file exist, trigger event\nif lastLogFile:\n        eg.TriggerEvent("lastLogFile",prefix = "BTV",payload = (lastLogFile,))')
            </Action>
        </Macro>
        <Macro Name="Start last log file monitoring" Expanded="True">
            <Event Name="DirectoryWatcher.Created" />
            <Event Name="BTV.lastLogFile" />
            <Action>
                EventGhost.PythonScript(u'pattern = "BTV-XXXXXXXXXX.log"\nfrom os import path\nfp = eg.event.payload[0]\np,f = path.split(fp)\nif f[:4] == pattern[:4] and f[-4:] == pattern[-4:]:\n    eg.result = fp\n    eg.globals.BTV_log_last_line = "DUMMY" #Reset variable\nelse:\n    eg.programCounter = None #Stop macro processing\n')
            </Action>
            <Action>
                FileOperations.ReadPeriodically([0, u'{eg.result}', 0, 0, 'cp1250', 50, True, 50, 5.0, u'BTVerror', 3])
            </Action>
        </Macro>
        <Macro Name="Python Script" Expanded="True">
            <Event Name="File.BTVerror" />
            <Action>
                EventGhost.PythonScript(u'pattern = "Adding error: \'12\'"\ndata = eg.event.payload\n\n#exist eg.globals.BTV_log_last_line in data ?\nfor bgn in range(len(data)):\n    if data[bgn] == eg.globals.BTV_log_last_line:\n        break\nbgn += 1\nif bgn &gt;= len(data):\n    bgn = 0\n\n#exists pattern in line ?\nfor i in range(bgn, len(data)):\n    if pattern in data[i]:\n        eg.TriggerEvent("error_occured",prefix ="BTV",payload = data[i])\n        break #Simply trigger only one event, even if multiple occurrences of error\n\n#Update eg.globals.BTV_log_last_line\nfor i in range(len(data)-1,-1,-1):\n    if data[i].strip()!="":\n        eg.globals.BTV_log_last_line = data[i]\n        break')
            </Action>
        </Macro>
        <Macro Name="Transmit IR" Expanded="True">
            <Event Name="BTV.error_occured" />
            <Action Name="Transmit IR off">
                EventGhost.Comment()
            </Action>
            <Action>
                Timer.TimerAction(u'BTVon', 0, 1, 120.0, u'BTVon', False, True, 1, u'00:00:00')
            </Action>
        </Macro>
        <Macro Name="Transmit IR on" Expanded="True">
            <Event Name="Timer.BTVon" />
            <Action Name="Transmit IR on">
                EventGhost.Comment()
            </Action>
        </Macro>
    </Folder>
</EventGhost>
