summaryrefslogtreecommitdiffstats
path: root/pipe_notify.py
blob: 2436e408611780be581204f9e8225e807b6919e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
"""
pipe_notify.py - Phenny Pipe Notification
Copyright 2013, Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
Licensed under the Eiffel Forum License 2.

http://inamidst.com/phenny/
"""

import os, fcntl, threading

PIPE_PATH = os.path.join('/', 'var', 'run', 'phenny', 'pipe')

def setup(phenny):
    dir = os.path.dirname(PIPE_PATH)
    if not os.path.exists(dir):
        os.makedirs(dir)

    t = threading.Thread(target=monitor_pipe, args=(phenny, PIPE_PATH,))
    t.start()
    
def monitor_pipe(phenny, name):
    if not os.path.exists(name):
        prev = os.umask(0o000)
        os.mkfifo(name)
        os.umask(prev)

    while True:
        fifo = open(name, 'r')
        for line in fifo:
            for chan in phenny.config.channels:
                phenny.msg(chan, line)