Esempio n. 1
0
    def update(self):
        logging.info("[Trac] Started refreshing timeline for tracker named %s." % self.tracker_name)

        # Check when the timeline was last updated.
        timeline_age = datetime.datetime.utcnow() - self.timeline.last_polled

        # First step is to use the actual timeline to update the date_reported and
        # last_touched fields for each bug.
        # Add one to days count here to account for possible timezone differences.
        for entry in self.generate_timeline_entries_from_rss(timeline_age.days + 1):
            # Format the data.
            entry_url = entry.link.rsplit("#", 1)[0]
            entry_date = datetime.datetime(*entry.date_parsed[0:6])
            entry_status = entry.title.split("): ", 1)[0].rsplit(" ", 1)[1]

            logging.info("[Trac] Updating %s entry on %s for %s" % (entry_status, entry_date, entry_url))
            # Get or create a TracBugTimes object.
            try:
                tb_times = self.timeline.tracbugtimes_set.get(canonical_bug_link = entry_url)
            except TracBugTimes.DoesNotExist:
                tb_times = TracBugTimes(canonical_bug_link = entry_url,
                                        timeline = self.timeline)

            # Set the date values as appropriate.
            if 'created' in entry_status:
                tb_times.date_reported = entry_date
            if tb_times.last_touched < entry_date:
                tb_times.last_touched = entry_date
                # Store entry status as well for use in second step.
                tb_times.latest_timeline_status = entry_status

            # Save the TracBugTimes object.
            tb_times.save()

        # Second step is to use the RSS feed for each individual bug to update the
        # last_touched field. This would be unneccessary if the timeline showed
        # update events as well as creation and closing ones, and in fact later
        # versions of Trac have this option - but then the later versions of Trac
        # also hyperlink to the timeline from the bug, making this all moot.
        # Also, we cannot just use the RSS feed for everything, as it is missing
        # the date_reported time, as well as a lot of information about the bug
        # itself (e.g. Priority).
        for tb_times in self.timeline.tracbugtimes_set.all():
            # Check that the bug has not beeen seen as 'closed' in the timeline.
            # This will reduce network load by not grabbing the RSS feed of bugs
            # whose last_touched info is definitely correct.
            if 'closed' not in tb_times.latest_timeline_status:
                logging.info("[Trac] Grabbing RSS feed for %s" % tb_times.canonical_bug_link)
                feed = feedparser.parse(tb_times.canonical_bug_link + '?format=rss')
                comment_dates =  [datetime.datetime(*e.date_parsed[0:6]) for e in feed.entries]
                # Check if there are comments to grab from.
                if comment_dates:
                    tb_times.last_polled = max(comment_dates)
                    tb_times.save()

        # Finally, update the timeline's last_polled.
        self.timeline.last_polled = datetime.datetime.utcnow()
        self.timeline.save()
Esempio n. 2
0
    def handle_timeline_rss(self, timeline_rss):
        # There are two steps to updating the timeline.
        # First step is to use the actual timeline to update the date_reported and
        # last_touched fields for each bug.

        # Parse the returned timeline RSS feed.
        feed = feedparser.parse(timeline_rss)
        for entry in feed.entries:
            # Format the data.
            entry_url = entry.link.rsplit("#", 1)[0]
            entry_date = datetime.datetime(*entry.date_parsed[0:6])
            entry_status = entry.title.split("): ", 1)[0].rsplit(" ", 1)[1]

            try:
                tb_times = self.timeline.tracbugtimes_set.get(
                    canonical_bug_link=entry_url)
            except TracBugTimes.DoesNotExist:
                tb_times = TracBugTimes(canonical_bug_link=entry_url,
                                        timeline=self.timeline)

            # Set the date values as appropriate.
            if 'created' in entry_status:
                tb_times.date_reported = entry_date
            if tb_times.last_touched < entry_date:
                tb_times.last_touched = entry_date
                # Store entry status as well for use in second step.
                tb_times.latest_timeline_status = entry_status

            # Save the TracBugTimes object.
            tb_times.save()

        # Second step is to use the RSS feed for each individual bug to update the
        # last_touched field. This would be unneccessary if the timeline showed
        # update events as well as creation and closing ones, and in fact later
        # versions of Trac have this option - but then the later versions of Trac
        # also hyperlink to the timeline from the bug, making this all moot.
        # Also, we cannot just use the RSS feed for everything, as it is missing
        # the date_reported time, as well as a lot of information about the bug
        # itself (e.g. Priority).
        for tb_times in self.timeline.tracbugtimes_set.all():
            # Check that the bug has not beeen seen as 'closed' in the timeline.
            # This will reduce network load by not grabbing the RSS feed of bugs
            # whose last_touched info is definitely correct.
            if 'closed' not in tb_times.latest_timeline_status:
                self.add_url_to_waiting_list(url=tb_times.canonical_bug_link +
                                             '?format=rss',
                                             callback=self.handle_bug_rss,
                                             callback_args=tb_times)

        # URLs are now all prepped, so start pushing them onto the reactor.
        self.push_urls_onto_reactor()
Esempio n. 3
0
    def handle_timeline_rss(self, timeline_rss):
        # There are two steps to updating the timeline.
        # First step is to use the actual timeline to update the date_reported and
        # last_touched fields for each bug.

        # Parse the returned timeline RSS feed.
        feed = feedparser.parse(timeline_rss)
        for entry in feed.entries:
            # Format the data.
            entry_url = entry.link.rsplit("#", 1)[0]
            entry_date = datetime.datetime(*entry.date_parsed[0:6])
            entry_status = entry.title.split("): ", 1)[0].rsplit(" ", 1)[1]

            try:
                tb_times = self.timeline.tracbugtimes_set.get(canonical_bug_link=entry_url)
            except TracBugTimes.DoesNotExist:
                tb_times = TracBugTimes(canonical_bug_link=entry_url, timeline=self.timeline)

            # Set the date values as appropriate.
            if "created" in entry_status:
                tb_times.date_reported = entry_date
            if tb_times.last_touched < entry_date:
                tb_times.last_touched = entry_date
                # Store entry status as well for use in second step.
                tb_times.latest_timeline_status = entry_status

            # Save the TracBugTimes object.
            tb_times.save()

        # Second step is to use the RSS feed for each individual bug to update the
        # last_touched field. This would be unneccessary if the timeline showed
        # update events as well as creation and closing ones, and in fact later
        # versions of Trac have this option - but then the later versions of Trac
        # also hyperlink to the timeline from the bug, making this all moot.
        # Also, we cannot just use the RSS feed for everything, as it is missing
        # the date_reported time, as well as a lot of information about the bug
        # itself (e.g. Priority).
        for tb_times in self.timeline.tracbugtimes_set.all():
            # Check that the bug has not beeen seen as 'closed' in the timeline.
            # This will reduce network load by not grabbing the RSS feed of bugs
            # whose last_touched info is definitely correct.
            if "closed" not in tb_times.latest_timeline_status:
                self.add_url_to_waiting_list(
                    url=tb_times.canonical_bug_link + "?format=rss",
                    callback=self.handle_bug_rss,
                    callback_args=tb_times,
                )

        # URLs are now all prepped, so start pushing them onto the reactor.
        self.push_urls_onto_reactor()
Esempio n. 4
0
def trac_udate_timeline(base_url=None, entry_url=None, entry_status=None, entry_date=None):
    try:
        timeline = TracTimeline.all_timelines.get(
                base_url=base_url)
    except TracTimeline.DoesNotExist:
        timeline = TracTimeline(base_url=base_url)

    try:
        tb_times = timeline.tracbugtimes_set.get(
                canonical_bug_link=entry_url)
    except TracBugTimes.DoesNotExist:
        tb_times = TracBugTimes(canonical_bug_link=entry_url,
            timeline=timeline)

    # Set the date values as appropriate.
    if 'created' in entry_status:
        tb_times.date_reported = entry_date
    if tb_times.last_touched < entry_date:
        tb_times.last_touched = entry_date
        # Store entry status as well for use in second step.
        tb_times.latest_timeline_status = entry_status

    # Save the TracBugTimes object.
    tb_times.save()