Browse Source

Growl improvements.

Reduce GNTP logging.
Limit GNTP timeout to 10 seconds (if Python version supports it).
Start GNTP notification in separate thread to prevent lockups when server does not respond.
pull/7/merge
ShyPike 14 years ago
parent
commit
bb30a5600a
  1. 12
      gntp/notifier.py
  2. 2
      sabnzbd/api.py
  3. 36
      sabnzbd/growler.py
  4. 2
      sabnzbd/interface.py

12
gntp/notifier.py

@ -118,13 +118,21 @@ class GrowlNotifier(object):
'''
Send the GNTP Packet
'''
logger.debug('To : %s:%s <%s>\n%s',self.hostname,self.port,type,data)
#logger.debug('To : %s:%s <%s>\n%s',self.hostname,self.port,type,data)
#Less verbose please
logger.debug('To : %s:%s <%s>',self.hostname,self.port,type)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.settimeout(10)
except:
pass
s.connect((self.hostname,self.port))
s.send(data.encode('utf-8', 'replace'))
response = gntp.parse_gntp(s.recv(1024))
s.close()
logger.debug('From : %s:%s <%s>\n%s',self.hostname,self.port,response.__class__,response)
#logger.debug('From : %s:%s <%s>\n%s',self.hostname,self.port,response.__class__,response)
#Less verbose please
logger.debug('From : %s:%s <%s>',self.hostname,self.port,response.__class__)
return response

2
sabnzbd/api.py

@ -624,7 +624,7 @@ def _api_test_email(name, output, kwargs):
def _api_test_notif(name, output, kwargs):
""" API: send a test notification, return result """
logging.info("Sending test notification")
res = sabnzbd.growler.send_notification('SABnzbd', T('Test Notification'), 'other')
res = sabnzbd.growler.send_notification('SABnzbd', T('Test Notification'), 'other', wait=True)
return report(output, error=res)
def _api_undefined(name, output, kwargs):

36
sabnzbd/growler.py

@ -23,6 +23,8 @@ from __future__ import with_statement
import os.path
import logging
import socket
import time
from threading import Thread
import sabnzbd
import sabnzbd.cfg
@ -32,9 +34,9 @@ from gntp.notifier import GrowlNotifier
try:
import Growl
# Detect classic Growl (older than 1.3)
_HAVE_OSX_GROWL = os.path.isfile('/Library/PreferencePanes/Growl.prefPane/Contents/MacOS/Growl')
_HAVE_CLASSIC_GROWL = os.path.isfile('/Library/PreferencePanes/Growl.prefPane/Contents/MacOS/Growl')
except ImportError:
_HAVE_OSX_GROWL = False
_HAVE_CLASSIC_GROWL = False
try:
import warnings
with warnings.catch_warnings():
@ -81,11 +83,6 @@ def change_value():
#------------------------------------------------------------------------------
def have_growl():
""" Return if any Growl support is present
"""
return True
def have_ntfosd():
""" Return if any PyNotify support is present
"""
@ -93,13 +90,22 @@ def have_ntfosd():
#------------------------------------------------------------------------------
def send_notification(title , msg, gtype):
def send_notification(title , msg, gtype, wait=False):
""" Send Notification message
Return '' when OK, otherwise an error string
"""
msg1 = msg2 = ""
if have_growl():
msg1 = send_growl(title, msg, gtype)
msg1 = ''
msg2 = ''
if sabnzbd.cfg.growl_enable():
if _HAVE_CLASSIC_GROWL and not sabnzbd.cfg.growl_server():
return send_local_growl(title, msg, gtype)
else:
if wait:
msg1 = send_growl(title, msg, gtype)
else:
msg1 = 'ok'
Thread(target=send_growl, args=(title, msg, gtype)).start()
time.sleep(0.5)
if have_ntfosd():
msg2 = send_notify_osd(title, msg)
return msg1 or msg2 or 'not active'
@ -153,12 +159,6 @@ def send_growl(title , msg, gtype):
""" Send Growl message
"""
global _GROWL, _GROWL_REG
if not sabnzbd.cfg.growl_enable():
return 'not enabled'
if _HAVE_OSX_GROWL and not sabnzbd.cfg.growl_server():
res = send_local_growl(title, msg, gtype)
return res
for n in (0, 1):
if not _GROWL_REG: _GROWL = None
@ -194,7 +194,7 @@ def send_growl(title , msg, gtype):
#------------------------------------------------------------------------------
# Local OSX Growl support
#
if _HAVE_OSX_GROWL:
if _HAVE_CLASSIC_GROWL:
_local_growl = None
if os.path.isfile('sabnzbdplus.icns'):
_OSX_ICON = Growl.Image.imageFromPath('sabnzbdplus.icns')

2
sabnzbd/interface.py

@ -2555,7 +2555,7 @@ class ConfigNotify(object):
conf['my_home'] = sabnzbd.DIR_HOME
conf['my_lcldata'] = sabnzbd.DIR_LCLDATA
conf['lastmail'] = self.__lastmail
conf['have_growl'] = sabnzbd.growler.have_growl()
conf['have_growl'] = True
conf['have_ntfosd'] = sabnzbd.growler.have_ntfosd()
for kw in LIST_EMAIL:

Loading…
Cancel
Save