Skip to content

Commit

Permalink
added icon support for all growl versions (v1 and v2); defaults to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Jul 30, 2015
1 parent e429b1a commit 3691f20
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
15 changes: 15 additions & 0 deletions Notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ def notify(self, servers, body, title, notify_type):
# #######################################################################
elif server['schema'] == NOTIFY_GROWL_SCHEMA:

version = None
if 'version' in server['qsd'] and len(server['qsd']['version']):
# Allow the user to specify the version of the protocol to
# use
try:
version = int(unquote(server['qsd']['version']).strip().split('.')[0])
except (AttributeError, IndexError, TypeError, ValueError):
self.logger.warning(
'An invalid Growl version of "%s" ' % server['qsd']['version'] +\
'was specified and will be ignored.'
)
pass

# Because of the URL formatting; the password is actually where
# the username field is; for this reason, we just preform
# this small hack to make it conform correctly; the following
Expand All @@ -524,6 +537,8 @@ def notify(self, servers, body, title, notify_type):
notify_args = dict(notify_args)
notify_args['user'] = None
notify_args['password'] = server.get('user', None)
if version:
notify_args['version'] = version
notify_args = notify_args.items()

# Limit results to just the first 2 line otherwise
Expand Down
16 changes: 13 additions & 3 deletions Notify/pnotify/NotifyBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from Logger import init_logger

from os.path import join
from os.path import basename
from os.path import dirname
from os.path import abspath

class NotifyType(object):
Expand Down Expand Up @@ -78,7 +78,7 @@ class NotifyImageSize(object):
'nzbget-notify-{TYPE}-{XY}.png'

NOTIFY_IMAGE_FILE = abspath(join(
basename(__file__),
dirname(__file__),
'var',
'nzbget-notify-{TYPE}-{XY}.png',
))
Expand Down Expand Up @@ -244,13 +244,23 @@ def image_raw(self, notify_type):
re.IGNORECASE,
)

print 'file=%s' % NOTIFY_IMAGE_FILE
# Now we open and return the file
file = re_table.sub(lambda x: re_map[x.group()], NOTIFY_IMAGE_FILE)
try:
return open(file, 'rb').read()
fd = open(file, 'rb')
except:
return None

try:
return fd.read()

except:
return None

finally:
fd.close()

def to_html(self, body):
"""
Returns the specified title in an html format and factors
Expand Down
43 changes: 30 additions & 13 deletions Notify/pnotify/NotifyGrowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
# Default Growl Port
GROWL_UDP_PORT = 23053

# Image Support (128x128)
GROWL_IMAGE_XY = NotifyImageSize.XY_128
# Image Support (72x72)
GROWL_IMAGE_XY = NotifyImageSize.XY_72

# Priorities
class GrowlPriority(object):
Expand All @@ -53,7 +53,7 @@ class NotifyGrowl(NotifyBase):
A wrapper to Growl Notifications
"""
def __init__(self, priority=GrowlPriority.NORMAL, **kwargs):
def __init__(self, priority=GrowlPriority.NORMAL, version=2, **kwargs):
"""
Initialize Growl Object
"""
Expand All @@ -75,6 +75,12 @@ def __init__(self, priority=GrowlPriority.NORMAL, **kwargs):
else:
self.priority = priority

# Always default the sticky flag to False
self.sticky = False

# Store Version
self.version = version

payload = {
'applicationName': self.app_id,
'notifications': ["New Updates","New Messages"],
Expand All @@ -86,7 +92,7 @@ def __init__(self, priority=GrowlPriority.NORMAL, **kwargs):
if self.password is not None:
payload['password'] = self.password

self.logger.debug('Growl Payload: %s' % str(payload))
self.logger.debug('Growl Registration Payload: %s' % str(payload))
self.growl = GrowlNotifier(**payload)

try:
Expand Down Expand Up @@ -126,17 +132,28 @@ def _notify(self, title, body, notify_type, **kwargs):

icon = None
if self.include_image:
icon = self.image_raw(notify_type)
if self.version >= 2:
# URL Based
icon = self.image_url(notify_type)
else:
# Raw
icon = self.image_raw(notify_type)

payload = {
'noteType': "New Updates",
'title': title,
'description': body,
'icon': icon is not None,
'sticky': False,
'priority': self.priority,
}
self.logger.debug('Growl Payload: %s' % str(payload))

# Update icon of payload to be raw data
payload['icon'] = icon

try:
self.growl.notify(
noteType="New Updates",
title=title,
description=body,
icon=icon,
sticky=False,
priority=self.priority,
)
self.growl.notify(**payload)

self.logger.debug(
'Growl notification sent successfully.'
Expand Down

0 comments on commit 3691f20

Please sign in to comment.