Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
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
        )
Esempio n. 9
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()
Esempio n. 10
0
 for blog, (url, filter, stick) in feeds.items():
     print "=> %s [%s]" % (blog, datetime.now())
     try:
         feed = parse(url)
         if not hasattr(feed, 'status'):
             raise feed.bozo_exception
         if feed.status != 200:
             raise ValueError("Got %s for %s" % (feed.status, url))
         entries = feed['entries']
         if virgin_run:
             cache[blog] = blog_cache = set()
             for entry in entries:
                 blog_cache.add(entry.link)
             if DEBUG and entries:
                 entry = sorted(entries, key=lambda p: p.updated)[-1]
                 notifier.notify('post', blog, entry.title, sticky=False)
                 print
                 print "  ", entry.link
                 print
                 recent.append(entry.link)
         else:
             blog_cache = cache[blog]
             for entry in entries:
                 if entry.link not in blog_cache:
                     if filter:
                         try:
                             if not filter(entry):
                                 blog_cache.add(entry.link)
                                 continue
                         except Exception:
                             print
Esempio n. 11
0
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)