<commit_before># -*- python -*-
# ex: set syntax=python:

# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This is the buildmaster config file for the 'nacl' bot. It must
# be installed as 'master.cfg' in your buildmaster's base directory
# (although the filename can be changed with the --basedir option to
# 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .

# This file follows this naming convention:
# Factories: f_nacl_[dbg/opt/sdk]_[os]
# Builders:  b_nacl_[dbg/opt/sdk]_[os]
# BuildDir:  [dbg/opt/sdk]-[os]
#
# os = xp/linux/mac

from buildbot import locks
from buildbot.changes import svnpoller
from buildbot.scheduler import Scheduler

from master import master_utils
from master import slaves_list
from master.factory import nacl_factory
from master.factory import gclient_factory

import config
<commit_msg>Monkey patch buildbot console in custom ways for llvm.<commit_after># -*- python -*-
# ex: set syntax=python:

# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This is the buildmaster config file for the 'nacl' bot. It must
# be installed as 'master.cfg' in your buildmaster's base directory
# (although the filename can be changed with the --basedir option to
# 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .

# This file follows this naming convention:
# Factories: f_nacl_[dbg/opt/sdk]_[os]
# Builders:  b_nacl_[dbg/opt/sdk]_[os]
# BuildDir:  [dbg/opt/sdk]-[os]
#
# os = xp/linux/mac


import time


from buildbot import locks
from buildbot.changes import svnpoller
from buildbot.scheduler import Scheduler
from buildbot.status.web import console

from master import master_utils
from master import slaves_list
from master.factory import nacl_factory
from master.factory import gclient_factory

import config


# -------- MONKEY PATCHING functions from console.py in third_party buildbot.
# Done to add:
#   - Increase console history to 200 revisions (instead of 40).
#   - Ignore got_revision for the purpose of console sorting (not accurate for
#   this waterfall).


def getBuildsForRevision(self, request, builder, builderName, lastRevision,
                         numBuilds, debugInfo):
    """Return the list of all the builds for a given builder that we will
    need to be able to display the console page. We start by the most recent
    build, and we go down until we find a build that was built prior to the
    last change we are interested in."""

    revision = lastRevision
    cachedRevision = self.cache.getRevision(builderName)
    if cachedRevision and cachedRevision > lastRevision:
        revision = cachedRevision

    builds = []
    build = self.getHeadBuild(builder)
    number = 0
    while build and number < numBuilds:
        debugInfo["builds_scanned"] += 1
        number += 1

        # CHANGED WAS HERE:
        # Dropped got_revision as a source for got_rev.

        # Get the last revision in this build.
        got_rev = -1
        try:
            if got_rev == -1:
               got_rev = build.getProperty("revision")
            if not self.comparator.isValidRevision(got_rev):
                got_rev = -1
        except:
            pass

        # We ignore all builds that don't have last revisions.
        # TODO(nsylvain): If the build is over, maybe it was a problem
        # with the update source step. We need to find a way to tell the
        # user that his change might have broken the source update.
        if got_rev and got_rev != -1:
            details = self.getBuildDetails(request, builderName, build)
            devBuild = console.DevBuild(got_rev, build.getResults(),
                                         console.getInProgressResults(build),
                                         build.getNumber(),
                                         build.isFinished(),
                                         build.getText(),
                                         build.getETA(),
                                         details,
                                         build.getTimes()[0])

            builds.append(devBuild)

            # Now break if we have enough builds.
            if self.comparator.getSortingKey() == "when":
                current_revision = self.getChangeForBuild(
                    builder.getBuild(-1), revision)
                if self.comparator.isRevisionEarlier(
                    devBuild, current_revision):
                    break
            else:
                if int(got_rev) < int(revision):
                    break;


        build = build.getPreviousBuild()

    return builds


def body(self, request):
    "This method builds the main console view display."

    # Debug information to display at the end of the page.
    debugInfo = dict()
    debugInfo["load_time"] = time.time()

    # get url parameters
    # Categories to show information for.
    categories = request.args.get("category", [])
    # List of all builders to show on the page.
    builders = request.args.get("builder", [])
    # Branch used to filter the changes shown.
    branch = request.args.get("branch", [console.ANYBRANCH])[0]
    # List of all the committers name to display on the page.
    devName = request.args.get("name", [])
    # json format.
    jsonFormat = request.args.get("json", [False])[0]


    # and the data we want to render
    status = self.getStatus(request)

    projectURL = status.getProjectURL()
    projectName = status.getProjectName()

    # Get all revisions we can find.
    source = self.getChangemaster(request)
    allChanges = self.getAllChanges(source, status, debugInfo)

    debugInfo["source_all"] = len(allChanges)

    # Keep only the revisions we care about.
    # By default we process the last 40 revisions.
    # If a dev name is passed, we look for the changes by this person in the
    # last 160 revisions.
    # CHANGED!!!:
    #   Switched from 40 to 200.
    numRevs = 200
    if devName:
      numRevs *= 4
    numBuilds = numRevs


    revisions = self.stripRevisions(allChanges, numRevs, branch, devName)
    debugInfo["revision_final"] = len(revisions)

    # Fetch all the builds for all builders until we get the next build
    # after lastRevision.
    builderList = None
    allBuilds = None
    if revisions:
        lastRevision = revisions[len(revisions)-1].revision
        debugInfo["last_revision"] = lastRevision

        (builderList, allBuilds) = self.getAllBuildsForRevision(status,
                                            request,
                                            lastRevision,
                                            numBuilds,
                                            categories,
                                            builders,
                                            debugInfo)

    tempCache = console.TemporaryCache()
    debugInfo["added_blocks"] = 0
    debugInfo["from_cache"] = 0

    data = ""

    if request.args.get("display_cache", None):
        data += "<br>Global Cache"
        data += self.cache.display()
        data += "<br>Temporary Cache"
        data += tempCache.display()

    if (jsonFormat and int(jsonFormat) == 1):
        revisions = revisions[0:1]
    data += self.displayPage(request, status, builderList, allBuilds,
                            revisions, categories, branch, tempCache,
                            debugInfo, jsonFormat)

    if not devName and branch == console.ANYBRANCH and not categories and not jsonFormat:
      tempCache.updateGlobalCache(self.cache)
      self.cache.trim()

    return data


# Monkey patch console.
console.ConsoleStatusResource.getBuildsForRevision = getBuildsForRevision
console.ConsoleStatusResource.body = body

{'fraction_non_alphanumeric': 0.0784576085634351, 'fraction_numerical': 0.005352146940761465, 'mean_word_length': 2.291433146517214, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5925335', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2113, 'n_words': 786}