Example #1
0
	def notify(self, noteType, title, description, icon=None, sticky=False, priority=None):
		"""Send a GNTP notifications

		.. warning::
			Must have registered with growl beforehand or messages will be ignored

		:param string noteType: One of the notification names registered earlier
		:param string title: Notification title (usually displayed on the notification)
		:param string description: The main content of the notification
		:param string icon: Icon URL path
		:param boolean sticky: Sticky notification
		:param integer priority: Message priority level from -2 to 2
		"""
		logger.info('Sending notification [%s] to %s:%s', noteType, self.hostname, self.port)
		assert noteType in self.notifications
		notice = gntp.GNTPNotice()
		notice.add_header('Application-Name', self.applicationName)
		notice.add_header('Notification-Name', noteType)
		notice.add_header('Notification-Title', title)
		if self.password:
			notice.set_password(self.password, self.passwordHash)
		if sticky:
			notice.add_header('Notification-Sticky', sticky)
		if priority:
			notice.add_header('Notification-Priority', priority)
		if icon:
			notice.add_header('Notification-Icon', self._checkIcon(icon))
		if description:
			notice.add_header('Notification-Text', description)

		self.add_origin_info(notice)
		self.notify_hook(notice)

		return self._send('notify', notice)
Example #2
0
    def _send_growl(self, options, message=None):

        # Send Notification
        notice = gntp.GNTPNotice()

        # Required
        notice.add_header('Application-Name', options['app'])
        notice.add_header('Notification-Name', options['name'])
        notice.add_header('Notification-Title', options['title'])

        if options['password']:
            notice.set_password(options['password'])

        # Optional
        if options['sticky']:
            notice.add_header('Notification-Sticky', options['sticky'])
        if options['priority']:
            notice.add_header('Notification-Priority', options['priority'])
        if options['icon']:
            notice.add_header('Notification-Icon', sickbeard.LOGO_URL)

        if message:
            notice.add_header('Notification-Text', message)

        response = self._send(options['host'], options['port'], notice.encode(), options['debug'])
        return True if isinstance(response, gntp.GNTPOK) else False
Example #3
0
    def notify(self,
               noteType,
               title,
               description,
               icon=None,
               sticky=False,
               priority=None):
        '''
		Send a GNTP notifications
		'''
        assert noteType in self.notifications
        notice = gntp.GNTPNotice()
        notice.add_header('Application-Name', self.applicationName)
        notice.add_header('Notification-Name', noteType)
        notice.add_header('Notification-Title', title)
        if self.password:
            notice.set_password(self.password, self.passwordHash)
        if sticky:
            notice.add_header('Notification-Sticky', sticky)
        if priority:
            notice.add_header('Notification-Priority', priority)
        if icon:
            notice.add_header('Notification-Icon', self._checkIcon(icon))
        if description:
            notice.add_header('Notification-Text', description)
        response = self.send('notify', notice.encode())
        if isinstance(response, gntp.GNTPOK): return True
        return response.error()
Example #4
0
    def notify(self,
               noteType,
               title,
               description,
               icon=None,
               sticky=False,
               priority=None,
               callback=None,
               identifier=None):
        """Send a GNTP notifications

		.. warning::
			Must have registered with growl beforehand or messages will be ignored

		:param string noteType: One of the notification names registered earlier
		:param string title: Notification title (usually displayed on the notification)
		:param string description: The main content of the notification
		:param string icon: Icon URL path
		:param boolean sticky: Sticky notification
		:param integer priority: Message priority level from -2 to 2
		:param string callback:  URL callback

		.. warning::
			For now, only URL callbacks are supported. In the future, the
			callback argument will also support a function
		"""
        logger.info('Sending notification [%s] to %s:%s', noteType,
                    self.hostname, self.port)
        assert noteType in self.notifications
        notice = gntp.GNTPNotice()
        notice.add_header('Application-Name', self.applicationName)
        notice.add_header('Notification-Name', noteType)
        notice.add_header('Notification-Title', title)
        if self.password:
            notice.set_password(self.password, self.passwordHash)
        if sticky:
            notice.add_header('Notification-Sticky', sticky)
        if priority:
            notice.add_header('Notification-Priority', priority)
        if icon:
            if self._checkIcon(icon):
                notice.add_header('Notification-Icon', icon)
            else:
                id = notice.add_resource(icon)
                notice.add_header('Notification-Icon', id)

        if description:
            notice.add_header('Notification-Text', description)
        if callback:
            notice.add_header('Notification-Callback-Target', callback)
        if identifier:
            notice.add_header('Notification-Coalescing-ID', identifier)

        self.add_origin_info(notice)
        self.notify_hook(notice)

        return self._send('notify', notice)
Example #5
0
 def test_single_resource(self):
     notification = gntp.GNTPNotice(
         app=self.application,
         name=self.notification_name,
         title="Testing Single Resource",
         password=self.growl.password,
     )
     resource = notification.add_resource(ICON_DATA)
     notification.add_header('Notification-Icon', resource)
     self.assertIsTrue(self.growl._send('notify', notification))
Example #6
0
    def notify(self,
               noteType,
               title,
               description,
               icon=None,
               sticky=False,
               priority=None,
               id=None):
        """Send a GNTP notifications

		.. warning::
			Must have registered with growl beforehand or messages will be ignored

		:param string noteType: One of the notification names registered earlier
		:param string title: Notification title (usually displayed on the notification)
		:param string description: The main content of the notification
		:param string icon: Icon URL path
		:param boolean sticky: Sticky notification
		:param integer priority: Message priority level from -2 to 2
		"""
        logger.info('Sending notification [%s] to %s:%s', noteType,
                    self.hostname, self.port)
        assert noteType in self.notifications
        notice = gntp.GNTPNotice()
        notice.add_header('Application-Name', self.applicationName)
        notice.add_header('Notification-Name', noteType)
        notice.add_header('Notification-Title', title)
        if self.password:
            notice.set_password(self.password, self.passwordHash)
        if sticky:
            notice.add_header('Notification-Sticky', sticky)
        if priority is not None:  #Changed by Pako
            notice.add_header('Notification-Priority', priority)
        if icon is not None:  #Changed by Pako
            notice.add_header('Notification-Icon', self._checkIcon(icon))
        if id is not None:  #Added by Pako
            notice.add_header('Notification-ID', id)
            notice.add_header('Notification-Coalescing-ID', id)
        if description:
            notice.add_header('Notification-Text', description)
        response = self._send('notify', notice.encode())
        if isinstance(response, gntp.GNTPOK):
            return True
        logger.error('Invalid response %s', response.error())
        return response.error()