-
Notifications
You must be signed in to change notification settings - Fork 0
/
gntp-tee.py
executable file
·57 lines (52 loc) · 1.4 KB
/
gntp-tee.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import sys
import signal
from optparse import OptionParser
try:
from gntp.notifier import GrowlNotifier
except ImportError:
sys.exit('Requires http://github.com/kfdm/gntp')
APPLICATION_NAME = 'gntp-tee'
NOTIFICATION_NAME = 'Pipe'
def signal_exit(a,b): sys.exit()
class Parser(OptionParser):
def __init__(self):
OptionParser.__init__(self)
self.add_option('-H','--hostname',
help='Destination Host',
dest='host',
default='localhost')
self.add_option('-p','--port',
help='Destination Port',
dest='port',
default=23053)
self.add_option('-P','--password',
help='GNTP Password',
dest='password',
default=None)
self.add_option('-A','--appname',
help='GNTP Application Name',
dest='app',
default=APPLICATION_NAME)
self.add_option('-v',dest='debug',
help='Print Debugging to stderr',
action='store_true',
default=False)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_exit)
parser = Parser()
(options, args) = parser.parse_args()
growl = GrowlNotifier(
applicationName = options.app,
notifications = [NOTIFICATION_NAME],
hostname = options.host,
password = options.password,
port = options.port,
debug = options.debug,
)
growl.register()
while( True ):
line = sys.stdin.readline()
if not line: break
sys.stdout.write(line)
growl.notify(NOTIFICATION_NAME,NOTIFICATION_NAME,line)