コード例 #1
0
ファイル: listener.py プロジェクト: pombredanne/trachacks
    class NotifyEmailTaskEvent(NotifyEmail):

        template_name = "notify_task_event_template.txt"

        def __init__(self, env):
            NotifyEmail.__init__(self, env)
            self.cronconf = CronConfig(self.env)

        def get_recipients(self, resid):
            """
                Return the recipients as defined in trac.ini.                
                """
            reclist = self.cronconf.get_email_notifier_task_recipient_list()
            return (reclist, [])

        def notifyTaskEvent(self, task_event_list):
            """
                Send task event by mail if recipients is defined in trac.ini
                """
            self.env.log.debug("notifying task event...")
            if self.cronconf.get_email_notifier_task_recipient():
                # prepare the data for the email content generation
                mess = ""
                start = True
                for event in task_event_list:
                    if start:
                        mess = mess + "task[%s]" % (event.task.getId(), )
                        mess = mess + "\nstarted at %d h %d" % (
                            event.time.tm_hour, event.time.tm_min)
                        mess = mess + "\n"
                    else:
                        mess = mess + "ended at %d h %d" % (event.time.tm_hour,
                                                            event.time.tm_min)
                        if (event.success):
                            mess = mess + "\nsuccess"
                        else:
                            mess = mess + "\nFAILURE"
                        mess = mess + "\n\n"
                    start = not start

                self.data.update({
                    "notify_body": mess,
                })
                NotifyEmail.notify(self, None, "task event notification")
            else:
                self.env.log.debug("no recipient for task event, aborting")

        def send(self, torcpts, ccrcpts):
            return NotifyEmail.send(self, torcpts, ccrcpts)
コード例 #2
0
ファイル: listener.py プロジェクト: nyuhuhuu/trachacks
    class NotifyEmailTaskEvent(NotifyEmail):
            
            template_name  = "notify_task_event_template.txt"
            
            def __init__(self, env):
                NotifyEmail.__init__(self, env)
                self.cronconf = CronConfig(self.env)

            def get_recipients(self, resid):
                """
                Return the recipients as defined in trac.ini.                
                """
                reclist = self.cronconf.get_email_notifier_task_recipient_list()     
                return (reclist, [])
                
            
            def notifyTaskEvent(self, task_event_list):
                """
                Send task event by mail if recipients is defined in trac.ini
                """
                self.env.log.debug("notifying task event...")             
                if self.cronconf.get_email_notifier_task_recipient() :                                    
                    # prepare the data for the email content generation
                    mess = ""      
                    start = True
                    for event in task_event_list:
                        if start:                        
                            mess = mess + "task[%s]" % (event.task.getId(),)                       
                            mess = mess + "\nstarted at %d h %d" % (event.time.tm_hour, event.time.tm_min)
                            mess = mess + "\n"
                        else:
                            mess = mess + "ended at %d h %d" % (event.time.tm_hour, event.time.tm_min)
                            if (event.success):
                                mess = mess + "\nsuccess"
                            else:
                                mess = mess + "\nFAILURE"
                            mess = mess + "\n\n"
                        start = not start                            

                    self.data.update({
                                     "notify_body": mess,                                        
                                      })                                          
                    NotifyEmail.notify(self, None, "task event notification")
                else:
                    self.env.log.debug("no recipient for task event, aborting")

            def send(self, torcpts, ccrcpts):
                return NotifyEmail.send(self, torcpts, ccrcpts)
コード例 #3
0
ファイル: task.py プロジェクト: nyuhuhuu/trachacks
        class UnreachableMilestoneNotification(BaseTicketNotification):
            """
            Notify the specified person (ex: admin, release manager) that a milestone
            is about to closed but there still are opened ticket 
            """
            
            template_name  = "unreachable_milestone_template.txt"
            
            def __init__(self, env, milestone):
                BaseTicketNotification.__init__(self, env, milestone)
                self.cronconf = CronConfig(self.env)                
                
            def get_recipients(self, milestone):
                reclist = self.cronconf.get_unreachable_milestone_task_recipient_list()
                return (reclist,[])
            
            def notify_unreachable_milestone(self, tickets):
                """
                Send a digest mail listing all tickets still opened in the milestone
                """
                self.populate_unreachable_tickets_data(tickets)
               
                NotifyEmail.notify(self, self.milestone, "Milestone %s still has opened ticket" % self.milestone)


            def send(self, torcpts, ccrcpts):
                return NotifyEmail.send(self, torcpts, ccrcpts)            
コード例 #4
0
ファイル: task.py プロジェクト: pombredanne/trachacks
        class UnreachableMilestoneNotification(BaseTicketNotification):
            """
            Notify the specified person (ex: admin, release manager) that a milestone
            is about to closed but there still are opened ticket 
            """

            template_name = "unreachable_milestone_template.txt"

            def __init__(self, env, milestone):
                BaseTicketNotification.__init__(self, env, milestone)
                self.cronconf = CronConfig(self.env)

            def get_recipients(self, milestone):
                reclist = self.cronconf.get_unreachable_milestone_task_recipient_list(
                )
                return (reclist, [])

            def notify_unreachable_milestone(self, tickets):
                """
                Send a digest mail listing all tickets still opened in the milestone
                """
                self.populate_unreachable_tickets_data(tickets)

                NotifyEmail.notify(
                    self, self.milestone,
                    "Milestone %s still has opened ticket" % self.milestone)

            def send(self, torcpts, ccrcpts):
                return NotifyEmail.send(self, torcpts, ccrcpts)
コード例 #5
0
ファイル: scheduler.py プロジェクト: pombredanne/trachacks
class SchedulerType(ISchedulerType):
    """
    Define a sort of scheduling. Base class for any scheduler type implementation
    """
    
    implements(ISchedulerType)   
    
    def __init__(self):    
        self.cronconf = CronConfig(self.env)
                

        
    def getId(self):
        """
        Return the id to use in trac.ini for this schedule type
        """
        raise NotImplementedError
    
    def getHint(self):
        """
        Return a description of what it is and the format used to defined the schedule
        """
        return ""
    
    def isTriggerTime(self, task, currentTime):
        """
        Test is accordingly to this scheduler and given currentTime, is time to fire the task
        """
        # read the configuration value for the task
        self.env.log.debug("looking for schedule of type " + self.getId())
        for schedule_value in self._get_task_schedule_value_list(task):
            self.env.log.debug("task [" + task.getId() + "] is scheduled for " + schedule_value)
            if self.compareTime(currentTime, schedule_value):
                return True
        self.env.log.debug("no matching schedule found")
        return False
    
    def compareTime(self, currentTime, schedule_value):
        """
        Test is accordingly to this scheduler, given currentTime and schedule value,
        is time to fire the task.
        currentTime is a structure computed by time.localtime(time())
        scheduled_value is the value of the configuration in trac.ini      
        """
        raise NotImplementedError
    
    def _get_task_schedule_value_list(self, task):
        return self.cronconf.get_schedule_value_list(task, self)
コード例 #6
0
ファイル: task.py プロジェクト: nyuhuhuu/trachacks
 def __init__(self, env, milestone):
     BaseTicketNotification.__init__(self, env, milestone)
     self.cronconf = CronConfig(self.env)                
コード例 #7
0
ファイル: scheduler.py プロジェクト: pombredanne/trachacks
 def __init__(self):    
     self.cronconf = CronConfig(self.env)
コード例 #8
0
ファイル: listener.py プロジェクト: pombredanne/trachacks
 def __init__(self):
     self.cronconf = CronConfig(self.env)
     self.task_event_buffer = []
     self.task_count = 0
     self.notifier = NotificationEmailTaskEvent.NotifyEmailTaskEvent(
         self.env)
コード例 #9
0
ファイル: listener.py プロジェクト: pombredanne/trachacks
 def __init__(self, env):
     NotifyEmail.__init__(self, env)
     self.cronconf = CronConfig(self.env)
コード例 #10
0
ファイル: listener.py プロジェクト: pombredanne/trachacks
class NotificationEmailTaskEvent(Component, ITaskEventListener,
                                 ITemplateProvider):
    """
    This task listener send notification mail about task event.
    """
    implements(ITaskEventListener)

    class NotifyEmailTaskEvent(NotifyEmail):

        template_name = "notify_task_event_template.txt"

        def __init__(self, env):
            NotifyEmail.__init__(self, env)
            self.cronconf = CronConfig(self.env)

        def get_recipients(self, resid):
            """
                Return the recipients as defined in trac.ini.                
                """
            reclist = self.cronconf.get_email_notifier_task_recipient_list()
            return (reclist, [])

        def notifyTaskEvent(self, task_event_list):
            """
                Send task event by mail if recipients is defined in trac.ini
                """
            self.env.log.debug("notifying task event...")
            if self.cronconf.get_email_notifier_task_recipient():
                # prepare the data for the email content generation
                mess = ""
                start = True
                for event in task_event_list:
                    if start:
                        mess = mess + "task[%s]" % (event.task.getId(), )
                        mess = mess + "\nstarted at %d h %d" % (
                            event.time.tm_hour, event.time.tm_min)
                        mess = mess + "\n"
                    else:
                        mess = mess + "ended at %d h %d" % (event.time.tm_hour,
                                                            event.time.tm_min)
                        if (event.success):
                            mess = mess + "\nsuccess"
                        else:
                            mess = mess + "\nFAILURE"
                        mess = mess + "\n\n"
                    start = not start

                self.data.update({
                    "notify_body": mess,
                })
                NotifyEmail.notify(self, None, "task event notification")
            else:
                self.env.log.debug("no recipient for task event, aborting")

        def send(self, torcpts, ccrcpts):
            return NotifyEmail.send(self, torcpts, ccrcpts)

    def __init__(self):
        self.cronconf = CronConfig(self.env)
        self.task_event_buffer = []
        self.task_count = 0
        self.notifier = NotificationEmailTaskEvent.NotifyEmailTaskEvent(
            self.env)

    class StartTaskEvent():
        """
        Store the event of a task start
        """
        def __init__(self, task):
            self.task = task
            self.time = localtime(time())

    class EndTaskEvent():
        """
        Store the event of a task end
        """
        def __init__(self, task, success):
            self.task = task
            self.time = localtime(time())
            self.success = success

    def get_htdocs_dirs(self):
        return []

    def get_templates_dirs(self):
        from pkg_resources import resource_filename
        return [resource_filename(__name__, 'templates')]

    def onStartTask(self, task):
        """
        called by the core system when the task is triggered,
        just before the waek_up method is called
        """
        self.task_event_buffer.append(
            NotificationEmailTaskEvent.StartTaskEvent(task))
        self.task_count = self.task_count + 1

    def onEndTask(self, task, success):
        """
        called by the core system when the task execution is finished,
        just after the task wake_up method exit
        """
        self.task_event_buffer.append(
            NotificationEmailTaskEvent.EndTaskEvent(task, success))
        # if the buffer reach the count then we notify
        if (self.task_count >= self.cronconf.get_email_notifier_task_limit()):
            # send the mail
            self.notifier.notifyTaskEvent(self.task_event_buffer)

            # reset task event buffer
            self.task_event_buffer[:] = []
            self.task_count = 0

    def getId(self):
        return self.cronconf.EMAIL_NOTIFIER_TASK_BASEKEY
コード例 #11
0
ファイル: task.py プロジェクト: pombredanne/trachacks
 def __init__(self, env, milestone):
     BaseTicketNotification.__init__(self, env, milestone)
     self.cronconf = CronConfig(self.env)
コード例 #12
0
 def __init__(self):
     self.cronconf = CronConfig(self.env)
     self.task_event_buffer = []
     self.task_count = 0
     self.notifier = None
コード例 #13
0
ファイル: listener.py プロジェクト: nyuhuhuu/trachacks
 def __init__(self):        
     self.cronconf = CronConfig(self.env)
     self.task_event_buffer = []
     self.task_count = 0
     self.notifier = None
コード例 #14
0
ファイル: listener.py プロジェクト: nyuhuhuu/trachacks
 def __init__(self, env):
     NotifyEmail.__init__(self, env)
     self.cronconf = CronConfig(self.env)
コード例 #15
0
ファイル: listener.py プロジェクト: nyuhuhuu/trachacks
class NotificationEmailTaskEvent(Component, ITaskEventListener, ITemplateProvider):
    """
    This task listener send notification mail about task event.
    """
    implements(ITaskEventListener)
    
    
    class NotifyEmailTaskEvent(NotifyEmail):
            
            template_name  = "notify_task_event_template.txt"
            
            def __init__(self, env):
                NotifyEmail.__init__(self, env)
                self.cronconf = CronConfig(self.env)

            def get_recipients(self, resid):
                """
                Return the recipients as defined in trac.ini.                
                """
                reclist = self.cronconf.get_email_notifier_task_recipient_list()     
                return (reclist, [])
                
            
            def notifyTaskEvent(self, task_event_list):
                """
                Send task event by mail if recipients is defined in trac.ini
                """
                self.env.log.debug("notifying task event...")             
                if self.cronconf.get_email_notifier_task_recipient() :                                    
                    # prepare the data for the email content generation
                    mess = ""      
                    start = True
                    for event in task_event_list:
                        if start:                        
                            mess = mess + "task[%s]" % (event.task.getId(),)                       
                            mess = mess + "\nstarted at %d h %d" % (event.time.tm_hour, event.time.tm_min)
                            mess = mess + "\n"
                        else:
                            mess = mess + "ended at %d h %d" % (event.time.tm_hour, event.time.tm_min)
                            if (event.success):
                                mess = mess + "\nsuccess"
                            else:
                                mess = mess + "\nFAILURE"
                            mess = mess + "\n\n"
                        start = not start                            

                    self.data.update({
                                     "notify_body": mess,                                        
                                      })                                          
                    NotifyEmail.notify(self, None, "task event notification")
                else:
                    self.env.log.debug("no recipient for task event, aborting")

            def send(self, torcpts, ccrcpts):
                return NotifyEmail.send(self, torcpts, ccrcpts)

    
    
    def __init__(self):        
        self.cronconf = CronConfig(self.env)
        self.task_event_buffer = []
        self.task_count = 0
        self.notifier = None
    
    
    class StartTaskEvent():
        """
        Store the event of a task start
        """
        def __init__(self, task):
            self.task = task
            self.time = localtime(time())
    
    
    class EndTaskEvent():
        """
        Store the event of a task end
        """
        def __init__(self, task, success):
            self.task = task
            self.time = localtime(time())
            self.success = success
            
            
            
    def get_htdocs_dirs(self):
        return []


    def get_templates_dirs(self):
        from pkg_resources import resource_filename
        return [resource_filename(__name__, 'templates')]
    
    
    def onStartTask(self, task):
        """
        called by the core system when the task is triggered,
        just before the waek_up method is called
        """
        self.task_event_buffer.append(NotificationEmailTaskEvent.StartTaskEvent(task)) 
        self.task_count = self.task_count + 1

    def onEndTask(self, task, success):
        """
        called by the core system when the task execution is finished,
        just after the task wake_up method exit
        """
        if (self.cronconf.is_email_notifier_only_error() and success):
            self.task_event_buffer.pop()
            self.task_count -= 1
            return
        self.task_event_buffer.append(NotificationEmailTaskEvent.EndTaskEvent(task, success))
        # if the buffer reach the count then we notify
        if ( self.task_count >= self.cronconf.get_email_notifier_task_limit()):
            # send the mail
            if not self.notifier:
                self.notifier = NotificationEmailTaskEvent.NotifyEmailTaskEvent(self.env)
            self.notifier.notifyTaskEvent(self.task_event_buffer)
            
            # reset task event buffer
            self.task_event_buffer[:] = []
            self.task_count= 0

    def getId(self):
        return self.cronconf.EMAIL_NOTIFIER_TASK_BASEKEY
    
    def getDescription(self):
        return self.__doc__
コード例 #16
0
ファイル: listener.py プロジェクト: nyuhuhuu/trachacks
 def __init__(self):        
     self.cronconf = CronConfig(self.env)
     self.task_event_buffer = []
     self.task_count = 0
     self.notifier = NotificationEmailTaskEvent.NotifyEmailTaskEvent(self.env)