def __init__(self, app):
     """
     Construction
     """
     self._app = app
     # Get the task daa required
     task = self._find_task(self._app.context.task['id'])
     # Initialize the event filter instance
     self._event_filter = EventsFilter(self._app.shotgun, task)
     self._event_filter.add_filter(TaskStatusChangedFilter)
     self._event_filter.add_filter(NewPublishFilter)
     self._event_filter.add_filter(NewNoteFilter)
     # Initialize the notification widget
     self._widget = TankNotificationWidget(self, self._event_filter)
 def __init__(self, app):
     """
     Construction
     """
     self._app = app
     # Get the task daa required
     task = self._find_task(self._app.context.task['id'])
     # Initialize the event filter instance
     self._event_filter = EventsFilter(self._app.shotgun, task)
     self._event_filter.add_filter(TaskStatusChangedFilter)
     self._event_filter.add_filter(NewPublishFilter)
     self._event_filter.add_filter(NewNoteFilter)
     # Initialize the notification widget
     self._widget = TankNotificationWidget(self, self._event_filter)
class TankNotificationsService(object):
    def __init__(self, app):
        """
        Construction
        """
        self._app = app
        # Get the task daa required
        task = self._find_task(self._app.context.task['id'])
        # Initialize the event filter instance
        self._event_filter = EventsFilter(self._app.shotgun, task)
        self._event_filter.add_filter(TaskStatusChangedFilter)
        self._event_filter.add_filter(NewPublishFilter)
        self._event_filter.add_filter(NewNoteFilter)
        # Initialize the notification widget
        self._widget = TankNotificationWidget(self, self._event_filter)

    def _find_task(self, task_id):
        """ Return the task data of of the provided task id """
        return self._app.shotgun.find_one("Task",
                                          filters=[['id', 'is', task_id]],
                                          fields=['id', 'entity'])

    def is_running(self):
        """ Return True if the service is running """
        if self._widget is None:
            return False
        return self._widget._active

    def start(self):
        log('Notifications service starting ...')
        # Only start the service if there is a task in the current context
        if self._app.context.task is None:
            log('The context is not valid. Notifications service cannot start.'
                )
            return False
        self._widget.start()
        return self._widget._active

    def stop(self):
        log('Notifications service stopping ...')
        self._widget.stop()
        return self._widget._active

    def restart(self):
        if self.is_running():
            self.stop()
        self.start()
        return self.is_running()
class TankNotificationsService(object):
    def __init__(self, app):
        """
        Construction
        """
        self._app = app
        # Get the task daa required
        task = self._find_task(self._app.context.task['id'])
        # Initialize the event filter instance
        self._event_filter = EventsFilter(self._app.shotgun, task)
        self._event_filter.add_filter(TaskStatusChangedFilter)
        self._event_filter.add_filter(NewPublishFilter)
        self._event_filter.add_filter(NewNoteFilter)
        # Initialize the notification widget
        self._widget = TankNotificationWidget(self, self._event_filter)

    def _find_task(self, task_id):
        """ Return the task data of of the provided task id """
        return self._app.shotgun.find_one("Task", filters=[['id', 'is', task_id]], fields=['id', 'entity'])

    def is_running(self):
        """ Return True if the service is running """
        if self._widget is None:
            return False
        return self._widget._active

    def start(self):
        log('Notifications service starting ...')
        # Only start the service if there is a task in the current context
        if self._app.context.task is None:
            log('The context is not valid. Notifications service cannot start.')
            return False
        self._widget.start()
        return self._widget._active

    def stop(self):
        log('Notifications service stopping ...')
        self._widget.stop()
        return self._widget._active

    def restart(self):
        if self.is_running():
            self.stop()
        self.start()
        return self.is_running()
def test():
    task_id = 560
    task = sg.find_one("Task",
                       filters=[['id', 'is', task_id]],
                       fields=['id', 'entity'])

    event_filter = EventsFilter(sg, task)
    event_filter.last_event_id = 239000
    event_filter.add_filter(TaskStatusChangedFilter)
    event_filter.add_filter(NewPublishFilter)
    event_filter.add_filter(NewNoteFilter)
    event_filter.run()
    print '-' * 100
    for f in event_filter.filters():
        for n in f.get_notifications():
            print '--'
            print n.get_message()
            print n.get_url()
def test():
    task_id = 560
    task = sg.find_one("Task", filters=[['id', 'is', task_id]], fields=['id', 'entity'])

    event_filter = EventsFilter(sg, task)
    event_filter.last_event_id = 239000
    event_filter.add_filter(TaskStatusChangedFilter)
    event_filter.add_filter(NewPublishFilter)
    event_filter.add_filter(NewNoteFilter)
    event_filter.run()
    print '-' * 100
    for f in event_filter.filters():
        for n in f.get_notifications():
            print '--'
            print n.get_message()
            print n.get_url()