class SimpleNotifier(object): def __init__(self, app_name='unittest2'): self.growl = GrowlNotifier( applicationName=app_name, notifications=[GROWL_NOTIFICATIONS_DEFAULT] ) def register(self): self.growl.register() def start(self, title, description): self.notify(title, description) def success(self, title, description): self.notify(title, description) def fail(self, title, description): self.notify(title=title, description=description) def notify(self, title, description, icon=None, sticky=False): self.growl.notify(noteType=GROWL_NOTIFICATIONS_DEFAULT, title=title, description=description, icon=icon, sticky=sticky)
class GrowlService(service.Service, ConfigurableMixin): implements(IOutput) enabled = True platform = "darwin" name = "fizzjik" notifications = None def __init__(self): self.notifications = ["event"] def _config_notifications(self, value): self.notifications = value.split(",") @if_config('enabled') def startService(self): service.Service.startService(self) self.notifier = GrowlNotifier(self.name, self.notifications) self.notifier.register() def stopService(self): service.Service.stopService(self) def notify(self, *args, **kw): self.notifier.notify(*args, **kw) def defaultNotify(self, event): self.notify("event", title=event.__class__.__name__, description=event.data)
class SimpleNotifier(object): def __init__(self, app_name='PyTest'): self.app_icon = resource_string('nosegrowl', 'python.png') self.ok_icon = resource_string('nosegrowl', 'dialog-ok.png') self.fail_icon = resource_string('nosegrowl', 'dialog-cancel.png') self.growl = GrowlNotifier(applicationName=app_name, notifications=[GROWL_NOTIFICATIONS_DEFAULT], applicationIcon=self.app_icon) def register(self): self.growl.register() def start(self, title, description): self.notify(title, description, icon=self.app_icon) def success(self, title, description): self.notify(title, description, icon=self.ok_icon) def fail(self, title, description): self.notify(title=title, description=description, icon=self.fail_icon) def notify(self, title, description, icon=None, sticky=False): self.growl.notify(noteType=GROWL_NOTIFICATIONS_DEFAULT, title=title, description=description, icon=icon, sticky=sticky)
def notifierFactory(): '''Returns the configured notifier, according to environment.''' gn = GrowlNotifier( applicationName= 'LogNotifier', notifications= notifications, applicationIcon= Image.imageWithIconForCurrentApplication() ) gn.register() return gn
class Pest(object): def __init__(self, notifications=[PASS, FAIL], root=os.path.abspath(os.curdir)): self.init_growl(notifications) self.root = root self.last_search_time = 0 self.name = root.split('/')[-1] def init_growl(self, notifications): try: self.gn = GrowlNotifier(applicationName='pest', notifications=notifications) self.gn.register() except: self.gn = None def notify(self, result): if self.gn: if result == PASS: self.gn.notify(noteType=PASS, title="%s: Tests Passed" % self.name.upper(), description="All tests passed!", icon=Image.imageFromPath(os.path.join(os.path.dirname(__file__), "images", "pass.png"))) elif result == FAIL: self.gn.notify(noteType=FAIL, title="%s: Tests Failed" % self.name.upper(), description="FAIL!!!", icon=Image.imageFromPath(os.path.join(os.path.dirname(__file__), "images", "fail.png"))) else: self.gn.notify(noteType=PASS, title="%s: Running Tests" % self.name.upper(), description="Running tests...", icon=Image.imageFromPath(os.path.join(os.path.dirname(__file__), "images", "pending.png"))) def grade_result(self, results): result = FAIL if results == 0: result = PASS return result def exclude_dir(self, name): return name.startswith('.') def exclude_file(self, name): return (not name.endswith('.py') and not name.endswith('.html')) or name.startswith('.') def run_tests(self): self.notify('RUN') def has_changed(self): last_search_time = self.last_search_time self.last_search_time = time.time() for root, dirs, files in os.walk(self.root): map(dirs.remove, [d for d in dirs if self.exclude_dir(d)]) map(files.remove, [f for f in files if self.exclude_file(f)]) for name in files: f = os.path.join(root, name) if os.path.getmtime(f) > last_search_time: return True return False
def sendGrowl(message, icon=None): g = GrowlNotifier(notifications=['yapper']) g.register() if type(message) is dict: g.notify('yapper', message.get('title', ''), message['text'], sticky=message.get('sticky', False), icon=icon) else: if message[0] == '!': sticky = True message = message[1:] else: sticky = False if message.count(':') > 0: title, message = string.split(message, ':', 1) else: title = '' g.notify('yapper', title.strip(), message.strip(), sticky=sticky, icon=icon)
class Sneazr(Plugin): name = 'sneazr' def __init__(self): Plugin.__init__(self) self.notifier = GrowlNotifier(applicationName='Sneazr', notifications=GROWL_NOTIFICATIONS_DEFAULT) self.notifier.register() def finalize(self, result=None): if result.wasSuccessful(): self.__notify('Success!', 'All tests passed successfully.') else: self.__notify('Failure!', 'Failed with %s failures and %s errors' % (len(result.failures), len(result.errors))) def __notify(self, title, message): self.notifier.notify(GROWL_NOTIFICATIONS_DEFAULT[0], title, message)
class GrowlNotifier(Notifier): ''' Notifier wrapper for osx growl notifications ''' def __init__(self): ''' Inititialize a new instance of the Gnome Notifier''' self._notify = GrowlNotifier(applicationName='amqp-notify', notifications=['amqp-notify'], defaultNotifications=['amqp-notify']) self._notify.register() self.image = None def notify(self, msg): ''' Create a new notification :param msg: The next message to alert the user with ''' try: self._notify.notify('amqp-notify', msg['title'], msg['message'], self.image, True) except Exception, ex: pass
def handle(self, *args, **options): gn = GrowlNotifier(applicationName='django_test_runner', notifications=["PASS","FAIL"]) gn.register() def test_stuff(): print "Running Tests..." from django.test.utils import get_runner verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive', True) failfast = options.get('failfast', False) TestRunner = get_runner(settings) test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast) failures = test_runner.run_tests(args) if failures: #sys.exit(bool(failures)) gn.notify("FAIL", "Tests Failed","Check the console to see failing tests") else: gn.notify("PASS", "Tests Passed","Way to go, you rock!") from django.utils import autoreload autoreload.main(test_stuff)
class Sneazr(Plugin): ''' A Nose plugin which displays Growl notifications indicating the number of (un)successful tests. ''' name = 'sneazr' def __init__(self): '''Registers a Growl notifier.''' super(Sneazr, self).__init__() # Store resource path to icons in dict. self.icon_paths = {} for status in ['pass', 'error', 'fail']: self.icon_paths[status] = resource_filename( 'resources', 'logo_%s.png' % status ) app_icon = Image.imageFromPath( resource_filename('resources', 'logo.png') ) self.notifier = GrowlNotifier( applicationName='Sneazr', notifications=GROWL_NOTIFICATIONS_DEFAULT, applicationIcon=app_icon ) self.notifier.register() def finalize(self, result=None): ''' Checks results of nosetests and prepares notification body. ''' if result.wasSuccessful(): self.__notify( 'Success!', 'All tests passed successfully.', self.icon_paths['pass'] ) elif len(result.errors) > len(result.failures): self.__notify( 'Failure!', 'Failed with %s errors and %s failures.' % ( len(result.errors), len(result.failures) ), self.icon_paths['error'] ) else: self.__notify( 'Failure!', 'Failed with %s failures and %s errors' % ( len(result.failures), len(result.errors) ), self.icon_paths['fail'] ) def __notify(self, title, message, icon_path=None): ''' Sends a Growl notification with the given parameters. ''' if icon_path is not None: icon = Image.imageFromPath(icon_path) else: icon = None self.notifier.notify( GROWL_NOTIFICATIONS_DEFAULT[0], title, message, icon=icon )
from twisted.web.http import HTTPClient from twisted.web.client import HTTPClientFactory from twisted.web import server, resource, error, http from twisted.internet import reactor from twisted.python import log import simplejson as json from twisted.web import client from Growl import GrowlNotifier, Image import sys notifier = GrowlNotifier('notify.io', notifications=['notify']) notifier.register() def sendGrowl(notice): def notify(notice, icon=None): notifier.notify('notify', notice.get('title', ''), notice['text'], sticky=notice.get('sticky', False), icon=icon) if 'icon' in notice: client.getPage(notice['icon']) \ .addCallback(lambda x: notify(notice, Image.imageWithData(x))) \ .addErrback(lambda x: notify(notice)) else: notify(notice) class CometStream(HTTPClient): stream = 0
def main(url, fname, tmpfname = None): gn = GrowlNotifier('rssgrowler', ['newarticle']) gn.register() for article in RSSTracker(url, fname, tmpfname = tmpfname): gn.notify('newarticle', article.title, article.summary) article.save()
from repeattimer import RepeatTimer from pyvoice import GoogleVoice from Growl import GrowlNotifier from Growl import Image as GrowlImage def notify(): unread_messages = gv.get_unread_messages() for msg in unread_messages: growlifier.notify(noteType="update", title="New GV Message!", description=("%s- %s" % (msg.elapsedTimeSincePlaced, msg.phoneNumber))) icon_path = "txt.icon.png" if (__name__ == "__main__"): growl_icon = GrowlImage.imageFromPath(icon_path) growlifier = GrowlNotifier(applicationName="Google Voice", notifications=['update'], applicationIcon=growl_icon) growlifier.register() gv = GoogleVoice("*****@*****.**", "laner8") #check for new messages, and update with new Growl alert every 10 minutes timer = RepeatTimer(interval=600, function=notify) timer.run()
def notify(header,body): gi = Image.imageFromPath('static/images/arduino_logo.png') gn = GrowlNotifier(applicationName="Notify!",notifications=['alert','notification'],applicationIcon=gi) gn.register() gn.notify(noteType='notification',title=header,description=body,icon=gi)