# -*- python -*-
# ex: set syntax=python tabstop=2 expandtab background=dark:

from buildbot.buildslave import BuildSlave
from buildbot.schedulers.forcesched import *
from buildbot.changes.gitpoller import GitPoller
from buildbot.changes import filter
from buildbot.changes.pb import PBChangeSource
from buildbot.config import BuilderConfig
from buildbot.process.factory import BuildFactory
from buildbot.process import factory
from buildbot.process.properties import WithProperties
from buildbot.scheduler import Nightly, Dependent
from buildbot.schedulers.basic import SingleBranchScheduler
from buildbot.schedulers.basic import SingleBranchScheduler as Scheduler
from buildbot.status import html
from buildbot.status.mail import MailNotifier
from buildbot.status.web import authz
from buildbot.steps.master import MasterShellCommand
from buildbot.steps.shell import Compile
from buildbot.steps.shell import ShellCommand
from buildbot.steps.shell import Test
from buildbot.steps.source import Git
from buildbot.steps.transfer import DirectoryUpload
import itertools
import re


# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

# The 'slaves' list defines the set of recognized buildslaves. Each element is
# a BuildSlave object, specifying a unique slave name and password.  The same
# slave name and password must be configured on the slave.
c['slaves'] = [BuildSlave("mongoperf", "zxcasd")]

# 'slavePortnum' defines the TCP port to listen on for connections from slaves.
# This must match the value configured into the buildslaves (with their
# --master option)
c['slavePortnum'] = 9989

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.  Here we point to the buildbot clone of pyflakes.


c['change_source'] = PBChangeSource()

####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.  In this
# case, just kick off a 'runtests' build


c['schedulers'] = []

weekly_build_slow_tests = []


####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which slaves can execute them.  Note that any particular build will
# only take place on one slave.



####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

from buildbot.status.web import authz, auth
authz_cfg=authz.Authz(
    # change any of these to True to enable; see the manual for more
    # options
    gracefulShutdown = False,
    forceBuild = True, # use this to test your slave once it is set up
    forceAllBuilds = False,
    pingBuilder = False,
    stopBuild = True,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg))

####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot
# installation's html.WebStatus home page (linked to the
# 'titleURL') and is embedded in the title of the waterfall HTML page.

c['title'] = "mongoperf test"
c['titleURL'] = "http://github.com/mongodb/mongo-perf"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.WebStatus page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://54.243.226.88:8010/"

####### DB URL

# This specifies what database buildbot uses to store change and scheduler
# state.  You can leave this at its default for all but the largest
# installations.
c['db_url'] = "sqlite:///state.sqlite"


# factories
standard = []#"client", "core", "shard", "repl", "replset", "dur", "aggregation"]
nightlyTests = ["slowNightly", "small_oplog", "parallel"]
push = standard + nightlyTests + ["push"]
all_no_push = standard + nightlyTests
weekly_steps = ["slowWeekly"]

solaris = []   
solaris_push = ["push"]

# The nightlies build 2.0, which does not have some unit test fixes,
# so for now I am running the old set of unit tests for nightlies
windowsNight = ["js", "tool", "dur", "parallel", "slowNightly", "push"]
windowsNightNoPush = [x for x in windowsNight if x != "push"]

def build_factory(builder_name, scons_options="", steps=standard, branch="master", test_with_auth=False):
    scons = "scons %(extra_options:-)s "
    if scons_options:
        scons = '%s %s ' % (scons, scons_options)

    halt_on_failure = "debug" in builder_name
    if "push" in steps:
        scons = '%s --release ' % scons
        halt_on_failure = True

    # additional step labeling; used by test_with_auth
    label = []

    # ERH change on 1/18/2012 - done b/c everything is broken
    halt_on_failure = True

    if branch == 'v2.0':
        compile_all_target = '.'
    else:
        compile_all_target = 'all'

    f = factory.BuildFactory()

    """
    f.addStep(Git(repourl="git://github.com/mongodb/mongo.git",
                  workdir="mongo",
                  branch=branch,
                  mode="update"))

    f.addStep(Compile(command=WithProperties(scons + " %(compile_options:-)s " + compile_all_target + " "),
                      workdir="mongo",
                      suppressionFile="supressions.cfg"))


    if "Windows" in builder_name:
        # killing does not work on Windows, as currently implemented
        f.addStep(ShellCommand(command=["python", "buildscripts/cleanbb.py", "--nokill"],
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["cleaning", "bb"],
                               descriptionDone=["clean", "bb"]))
    else:
        f.addStep(ShellCommand(command=["python", "buildscripts/cleanbb.py"],
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["cleaning", "bb"],
                               descriptionDone=["clean", "bb"]))
   
    # to send test output to the buildlogs.mongodb.org application,
    # we need to set some environment variables to communicate build
    # info to the output wrapper script
    def test_env(phase):
        return {
            'MONGO_USE_BUILDLOGGER': 'true',
            'MONGO_BUILDER_NAME': WithProperties('%s', 'buildername'),
            'MONGO_BUILD_NUMBER': WithProperties('%s', 'buildnumber'),
            'MONGO_GIT_HASH': WithProperties('%s', 'got_revision'),
            'MONGO_BRANCH': branch,
            'MONGO_SLAVE_NAME': WithProperties('%s', 'slavename'),
            'MONGO_PHASE': phase,
        }

    if "lint" in steps:
        f.addStep(Test(command=WithProperties(scons + "lint"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       description=["testing", "lint"],
                       descriptionDone=["lint", "tests"],
                       timeout=10800,
                       env=test_env('lint')))

    if ("slowNightly" in steps and
        "64" in builder_name and
        "debug" not in builder_name and
        "DEBUG" not in builder_name):
        f.addStep(Test(command=WithProperties(scons + "smokeJsSlowNightly"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       description=["testing", "slowNightly"],
                       descriptionDone=["slowNightly", "tests"],
                       suppressionFile="suppressions.cfg",
                       timeout=10800,
                       env=test_env('slow nightly')))

    if "slowWeekly" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeJsSlowWeekly"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       description=["testing", "slowWeekly"],
                       descriptionDone=["slowWeekly", "tests"],
                       suppressionFile="suppressions.cfg",
                       timeout=10800,
                       env=test_env('slow weekly')))

    if test_with_auth and "slowWeekly" in steps:
        # some weekly builders also run the standard
        # tests with --smokeauth, which starts mongo
        # with --auth and --keyfile
        scons = '%s --smokeauth ' % scons
        steps = list(steps)
        steps.extend(standard)
        label = ['with auth']

    # small_oplog can't run on 32-bit machines because running all the jstests
    # on the same mongod exhausts all virtual address space.
    if "small_oplog" in steps and "32-bit" not in builder_name:
        f.addStep(Test(command=WithProperties(scons + "startMongodSmallOplog smokeJs"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "small", "oplog"] + label,
                       descriptionDone=["small", "oplog"] + label,
                       timeout=10800,
                       env=test_env('small oplog')))

    # put core things here
    # also we always halt on these since if this is broken
    # things are likely in a bad state

    if "js" in steps:
        f.addStep(Test(command=WithProperties(scons + "smoke smokeJs"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "js"] + label,
                       descriptionDone=["js"] + label,
                       timeout=10800,
                       env=test_env('js')))

    if "tool" in steps and "core" not in steps:
        # the tool suite is also run by core; if that
        # is specified, just defer to run it there
        f.addStep(Test(command=WithProperties(scons + "smokeTool"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "tools"] + label,
                       descriptionDone=["tool"] + label,
                       timeout=10800,
                       env=test_env('tools')))

    if "core" in steps:
        f.addStep(Test(command=WithProperties(scons + "smoke"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "core"] + label,
                       descriptionDone=["core"] + label,
                       timeout=10800,
                       env=test_env('core')))

        if branch == 'master':
            # recent versions on master drop a build/unittests.txt
            # file containing additional C++ unit tests to run
            f.addStep(Test(command=WithProperties(scons + "smokeCppUnittests"),
                           haltOnFailure=True,
                           workdir="mongo",
                           suppressionFile="suppressions.cfg",
                           description=["unit tests"] + label,
                           descriptionDone=["unit tests"] + label,
                           timeout=10800,
                           env=test_env('core')))

            f.addStep(Test(command=WithProperties(scons + "smokeFailPoint"),
                           haltOnFailure=True,
                           workdir="mongo",
                           suppressionFile="suppressions.cfg",
                           description=["testing", "failpoints"] + label,
                           descriptionDone=["failpoints"] + label,
                           timeout=10800,
                           env=test_env('failpoint')))
        f.addStep(Test(command=WithProperties(scons + "smokeDisk"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "disk"] + label,
                       descriptionDone=["disk"] + label,
                       timeout=10800,
                       env=test_env('disk')))
     
        f.addStep(Test(command=WithProperties(scons + "smokeTool"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "tools"] + label,
                       descriptionDone=["tool"] + label,
                       timeout=10800,
                       env=test_env('tools')))
        f.addStep(Test(command=WithProperties(scons + "smokeAuth"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "auth"] + label,
                       descriptionDone=["auth"] + label,
                       timeout=10800,
                       env=test_env('auth')))
        f.addStep(Test(command=WithProperties(scons + "smokeClient"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "client"] + label,
                       descriptionDone=["client"] + label,
                       timeout=10800,
                       env=test_env('client')))
        f.addStep(Test(command=WithProperties(scons + "smokeJs"),
                       haltOnFailure=True,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "js"] + label,
                       descriptionDone=["js"] + label,
                       timeout=10800,
                       env=test_env('js')))

    # major features

    if "replset" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeReplSets"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "replica sets"] + label,
                       descriptionDone=["replicasets"] + label,
                       timeout=10800,
                       env=test_env('replica sets')))

    if "dur" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeDur"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "durability"] + label,
                       descriptionDone=["durability"] + label,
                       timeout=10800,
                       env=test_env('durability')))

    if "shard" in steps:
        f.addStep(Test(command=WithProperties(scons + "mongosTest smokeSharding"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "sharding"] + label,
                       descriptionDone=["sharding"] + label,
                       timeout=10800,
                       env=test_env('sharding')))

    if "repl" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeRepl smokeClone"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "replication"] + label,
                       descriptionDone=["replication"] + label,
                       timeout=10800,
                       env=test_env('replication')))

    if ("parallel" in steps and
        "32" not in builder_name and
        "V2.0" not in builder_name and
        "V2.2" not in builder_name):
        f.addStep(ShellCommand(command=["python", "buildscripts/cleanbb.py"],
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["cleaning", "bb"],
                               descriptionDone=["clean", "bb"]))

        f.addStep(Test(command=WithProperties(scons + "smokeParallel"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "parallel"] + label,
                       descriptionDone=["parallel"] + label,
                       timeout=10800,
                       env=test_env('parallel')))

    if "no_js" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeAllNoJs"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "without", "js"] + label,
                       descriptionDone=["no", "js"] + label,
                       timeout=10800,
                       env=test_env('no js')))

    if "perf" in steps:
        f.addStep(Test(command=WithProperties(scons + "smokeJsPerf"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "performance"] + label,
                       descriptionDone=["performance"] + label,
                       timeout=10800,
                       env=test_env('perf')))

    if "aggregation" in steps and branch == "master":
        # aggregation tests only on master, ultimately
        # will be on 2.1/2.2 branches
        f.addStep(Test(command=WithProperties(scons + "smokeAggregation"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "aggregation"] + label,
                       descriptionDone=["aggregation"] + label,
                       timeout=10800,
                       env=test_env('aggregation')))

    if "multiVersion" in steps and branch == "master":
        # Runs multiVersion tests against master, 2.0, and 1.8 binaries
        f.addStep(Test(command=WithProperties(scons + "smokeMultiVersion"),
                       haltOnFailure=halt_on_failure,
                       workdir="mongo",
                       suppressionFile="suppressions.cfg",
                       description=["testing", "multiVersion"] + label,
                       descriptionDone=["multiVersion"] + label,
                       timeout=10800,
                       env=test_env('multiVersion')))

    # distribution stuff
    if "push" in steps:

        if "push_symbols" in steps:
            f.addStep(ShellCommand(command=WithProperties(scons + "--nostrip s3dist"),
                                   haltOnFailure=halt_on_failure,
                                   workdir="mongo",
                                   timeout=1800,
                                   description=["pushing", "symbols"],
                                   descriptionDone=["push", "symbols"]))

        f.addStep(ShellCommand(command=WithProperties(scons + "s3dist"),
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["pushing"],
                               descriptionDone=["push"]))
        if "push_static" in steps:
            f.addStep(ShellCommand(command=WithProperties(scons + "--static s3dist"),
                                   haltOnFailure=halt_on_failure,
                                   workdir="mongo",
                                   description=["pushing", "static"],
                                   descriptionDone=["push", "static"]))

        f.addStep(ShellCommand(command=WithProperties(scons + "dist_clean"),
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["cleaning"],
                               descriptionDone=["clean"]))

    if "coverage-report" in steps:
        f.addStep(ShellCommand(command=WithProperties(scons + "coverage"),
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["generating", "coverage", "reports"],
                               descriptionDone=["generated", "coverage", "reports"],
                               env=test_env('gcov')))

    if "doc" in steps:
        f.addStep(ShellCommand(command=WithProperties(scons + "docs"),
                               workdir="mongo",
                               description=["generating", "docs"],
                               descriptionDone=["docs"]))
        f.addStep(DirectoryUpload(slavesrc="docs/html",
                                  masterdest="~/mongodocs",
                                  workdir="mongo"))
        f.addStep(ShellCommand(command=["rm", "-rf", "docs/html"],
                               workdir="mongo",
                               description=["cleaning", "docs"],
                               descriptionDone=["clean", "docs"]))
        f.addStep(MasterShellCommand(command=["python", "upload_api_docs.py", "~/mongodocs/"]))

    if "client" in steps:
        name = "mongo-cxx-driver-nightly"
        if branch != "master":
            name = "mongo-cxx-driver-" + branch

        if branch == 'v2.0':
            f.addStep(ShellCommand(command=WithProperties("%s--prefix=%s %s dist" % (scons, name, name)),
                                   haltOnFailure=True,
                                   workdir="mongo",
                                   description=["tarring", "client"],
                                   descriptionDone=["client", "tarball"]))
            f.addStep(ShellCommand(command=WithProperties("%s--prefix=%s clientBuild" % (scons, name)),
                                   haltOnFailure=True,
                                   workdir="mongo",
                                   description=["testing", "client"],
                                   descriptionDone=["test", "client"]))
            f.addStep(ShellCommand(command=WithProperties("%s--prefix=%s s3dist" % (scons, name)),
                                   haltOnFailure=True,
                                   workdir="mongo",
                                   description=["pushing", "client"],
                                   descriptionDone=["push", "client"]))
        else:
          pass


    if "cleandir" in steps or "sunos-nexenta 32-bit" in builder_name:
        f.addStep(ShellCommand(command=WithProperties(scons + " -c . "),
                               haltOnFailure=halt_on_failure,
                               workdir="mongo",
                               description=["cleaning dir"],
                               descriptionDone=["cleandir"]))

    """
    # mongo-perf stuff

    f.addStep(ShellCommand(command="rm -rf mongo-perf",
                      workdir=".",
                      description=["cleaning mongo-perf dir"],
                      descriptionDone=["clean mongo perf"]))

    f.addStep(ShellCommand(command="git clone git://github.com/mongodb/mongo-perf.git",
                      workdir=".",
                      description=["cloning mongo-perf"],
                      descriptionDone=["clone mongo perf"]))

    f.addStep(Compile(command="scons",
                      workdir="mongo-perf/mongo-cxx-driver",
                      description=["building mongo-cxx-driver"],
                      descriptionDone=["build mongo-cxx"]))

    f.addStep(Compile(command="scons",
                      workdir="mongo-perf",
                      description=["building mongo-perf"],
                      descriptionDone=["build mongo perf"]))


    MONGO_PERF_RESULTS_HOST = "54.243.226.88"
    MONGO_PERF_RESULTS_PORT = "27017"

    f.addStep(ShellCommand(command=WithProperties("python runner.py --rhost " 
                                    + MONGO_PERF_RESULTS_HOST + " --rport " 
                                    + MONGO_PERF_RESULTS_PORT + " --port 30000 "
                                    + " --mongod %(workdir)s/mongo/mongod "
                                    + " --label " + builder_name.replace(" ", "_")),
                                    workdir="mongo-perf",
                                    timeout=10800,
                                    description=["running", "benchmark", "tests"],
                                    descriptionDone=["ran benchmark tests"]))


    return f

def package_factory():
    f = factory.BuildFactory()
    f.addStep(Git(repourl="git://github.com/mongodb/mongo.git",
                  workdir="/data/dist/mongo",
                  branch="HEAD",
                  mode="update"))
    command = "export PATH=.:$PATH; export TMPDIR=`pwd`; export PYTHONPATH=/data/dist/:$PYTHONPATH; python makealldists.py --use-internal-name n1.4.4:-stable,n1.5.4:-unstable,nlatest:-snapshot"
    f.addStep(ShellCommand(command=command,
                           workdir="/data/dist/mongo/buildscripts",
                           description=["packaging"],
                           descriptionDone=["packaging"]))
    return f


def shouldDoWeekly(name):
    lowername = name.lower()
    for build in ["32-bit", "debug", "freebsd", "netbsd",
              "solaris", "legacy", "compile", "rhel"]:
        if lowername.find(build) >= 0:
            return False

    return True

build_on_commit = []
build_nightly = []
weekly_build_slow_tests = []
default_nightlies = [("Nightly", "master"), ("V2.2", "v2.2"), ("V2.4", "v2.4")]


def get_builders(name, slavenames, nightlies=default_nightlies,
                 scons_options="", steps=standard, nightly_steps=push,
                 weekly_steps=weekly_steps, build_triggered=True,
                 build_weeklies=True):
    builders = []
    builddir = name.replace(" ", "_").replace("-", "").replace(".", "")
    if build_triggered:
        builders.append({"name": name,
                         "slavenames": slavenames,
                         "builddir": builddir,
                         "factory": build_factory(name, scons_options, steps)})
        build_on_commit.append(name)

    for (nightly_name, branch) in nightlies:
        builder_name = "%s %s" % (nightly_name, name)
        builders.append({"name": builder_name,
                         "slavenames": slavenames,
                         "builddir": "%s_%s" % (builddir, nightly_name),
                         "factory": build_factory(builder_name,
                                                  scons_options,
                                                  nightly_steps,
                                                  branch=branch)})
        build_nightly.append(builder_name)

    if build_weeklies and shouldDoWeekly(name):
        weekly_slow_tests_name = "%s Weekly Slow Tests" % name
        builders.append({"name": weekly_slow_tests_name,
                         "slavenames": slavenames,
                         "builddir": "%s_Weekly_Slow_Tests" % builddir,
                         "factory": build_factory(
                             weekly_slow_tests_name,
                             scons_options,
                             weekly_steps,
                             test_with_auth=True,
                         )})
        weekly_build_slow_tests.append(weekly_slow_tests_name)
    return builders


def get_package_builders():
    return []

c['builders'] = get_builders("Linux 64-bit", ["mongoperf"],
                     nightlies=[],
                     build_triggered=True,
                     build_weeklies=False)


        # took out lots of builders here - may need to put back in

        

def builderSort(a, b):
    a = a["name"].lower()
    b = b["name"].lower()

    def cmpContains(word):
        # Compare a and b with respect to the
        # presence of `word` in the name. If a
        # builder name has the `word`, it is
        # considered greater.
        isWordA = word in a
        isWordB = word in b

        if isWordA and isWordB:
            return 0
        elif isWordA:
            return 1
        elif isWordB:
            return -1
        return 0

    # compile-only builder comes first
    x = cmpContains("compile")
    if x != 0:
        return -x

    # weekly builders go last
    x = cmpContains("week")
    if x != 0:
        return x

    # non-master builders order by version
    # with older versions first
    def getVersion(x):
        r = re.compile("^v(\d+\.\d+)")
        m = r.match(x)
        if m is None:
            return 0
        return float(m.group(1)) * 100

    va = getVersion(a)
    vb = getVersion(b)

    if (va > 0 or vb > 0) and va != vb:
        return int(va - vb)

    # nightly comes after non-nightly
    x = cmpContains("night")
    if x != 0:
        return x

    # rough-order builders by platform
    for token in ('linux', 'os x', 'bsd', 'solaris', 'windows'):
        x = cmpContains(token)
        if x:
            return -x

    # sort longer build names later
    # this puts "Win... DEBUG" after "Win..."
    if len(a) != len(b):
        return cmp(len(a), len(b))

    # else sort alphabetically
    return cmp(a, b)


#c['builders'].sort(builderSort)

for x in c['builders']:
    print(x["name"])

build_packages = get_package_builders()
c['builders'] += build_packages

# schedulers
c['schedulers'] = []
c['schedulers'].append(Nightly(name="nightly", hour=1, minute=0,
                               onlyIfChanged=False,
                               builderNames=build_on_commit, branch=None))

c['schedulers'].append(ForceScheduler(
                            name="triggered",
                            builderNames=build_on_commit))

c['projectName'] = "Mongo Perf"
c['projectURL'] = "http://github.com/mongodb/mongo-perf"


def mergeRequests(builder, req1, req2):
    if req1.source.canBeMergedWith(req2.source) and req1.reason == req2.reason:
        return True
    return False
c['mergeRequests'] = mergeRequests


c['status'].append(MailNotifier(fromaddr="buildbot@mongodb.org",
                                lookup="10gen.com",
                                extraRecipients=["mongoperf@10gen.com"],
                                mode="all",
                                relayhost="ASPMX.L.GOOGLE.com"))

