-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrowl.py
92 lines (68 loc) · 2.25 KB
/
growl.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from lxml import html as lhtml
import httplib2
import time
import sys
import Growl
import getopt
import settings
"""Growl Ping
-h/--help
Displays this message
-t/--title
Specify the title of the notification
-m/--message
Specify the message to be displayed
-i/--icon
A path to an image
-s/--sticky
Make the notification sticky
"""
class GrowlPing(object):
def __init__(self):
self.icon_path = '%s/jenkins.png' % settings.PROJECT_ROOT_PATH
self.app_name = 'Growl Ping'
self.notifications = ['update']
self.title = 'Growl Ping Notification'
self.message = 'This notification was generated by growl-ping.py'
self.sticky = False
self.process_opts()
try: self.icon = Growl.Image.imageFromPath(self.icon_path)
except: self.icon = None
def usage(self, code, msg=''):
if code: fd = sys.stderr
else: fd = sys.stdout
print __doc__
if msg: print >> fd, msg
sys.exit(code)
def process_opts(self):
try:
opts, args = getopt.getopt(sys.argv[1:], 'ht:m:i:s',
['help', 'title', 'message',
'icon', 'sticky'])
except getopt.error, msg:
self.usage(1, msg)
for opt, arg in opts:
if opt in ('-h', '--help'):
self.usage(0)
elif opt in ('-t', '--title'):
self.title = arg
elif opt in ('-m', '--message'):
self.message = arg
elif opt in ('-i', '--icon'):
self.icon_path = arg
elif opt in ('-s', '--sticky'):
self.sticky = True
def run(self):
self.notify()
def ping(self):
return
def notify(self, jobs_broken):
title = "Jenkins Notifier Alert!"
message = "Build quebrado!\n\n%s" % ('\n'.join(jobs_broken))
notification = 'update'
g = Growl.GrowlNotifier(self.app_name, self.notifications,
applicationIcon=self.icon)
g.register()
g.notify(notification, title, message, sticky=True, priority=1)