#! /usr/bin/python

# NOTE: this configuration file is from the buildbot-0.7.5 era or earlier. It
# has not been brought up-to-date with the standards of buildbot-0.7.6 . For
# examples of modern usage, please see hello.cfg, or the sample.cfg which is
# installed when you run 'buildbot create-master'.

# This configuration file is described in $BUILDBOT/docs/config.xhtml

# This is used (with online=True) to run the Twisted Buildbot at
# http://www.twistedmatrix.com/buildbot/ . Passwords and other secret
# information are loaded from a neighboring file called 'private.py'.

import sys
sys.path.append('/home/buildbot/BuildBot/support-master')

import os.path

from buildbot.changes.pb import PBChangeSource
from buildbot.scheduler import Scheduler, Try_Userpass
from buildbot.steps.source import SVN
from buildbot.process.factory import s
from buildbot.process.process_twisted import \
     QuickTwistedBuildFactory, \
     FullTwistedBuildFactory, \
     TwistedReactorsBuildFactory
from buildbot.status import html, words, client, mail

import extra_factory
reload(extra_factory)
from extra_factory import GoodTwistedBuildFactory

import private # holds passwords
reload(private) # make it possible to change the contents without a restart

BuildmasterConfig = c = {}

# I set really=False when testing this configuration at home
really = True
usePBChangeSource = True


c['slaves'] = []
for slave in private.bot_passwords.keys():
    c['slaves'].append(BuildSlave(slave, private.bot_passwords[slave]))

c['sources'] = []

# the Twisted buildbot currently uses the contrib/svn_buildbot.py script.
# This makes a TCP connection to the ChangeMaster service to push Changes
# into the build master. The script is invoked by
# /svn/Twisted/hooks/post-commit, so it will only be run for things inside
# the Twisted repository. However, the standard SVN practice is to put the
# actual trunk in a subdirectory named "trunk/" (to leave room for
# "branches/" and "tags/"). We want to only pay attention to the trunk, so
# we use "trunk" as a prefix for the ChangeSource. This also strips off that
# prefix, so that the Builders all see sensible pathnames (which means they
# can do things like ignore the sandbox properly).

source = PBChangeSource(prefix="trunk/")
c['sources'].append(source)


## configure the builders

if 0:
    # always build on trunk
    svnurl = "svn://svn.twistedmatrix.com/svn/Twisted/trunk"
    source_update = s(SVN, svnurl=svnurl, mode="update")
    source_copy = s(SVN, svnurl=svnurl, mode="copy")
    source_export = s(SVN, svnurl=svnurl, mode="export")
else:
    # for build-on-branch, we use these instead
    baseURL = "svn://svn.twistedmatrix.com/svn/Twisted/"
    defaultBranch = "trunk"
    source_update = s(SVN, baseURL=baseURL, defaultBranch=defaultBranch,
                      mode="update")
    source_copy = s(SVN, baseURL=baseURL, defaultBranch=defaultBranch,
                    mode="copy")
    source_export = s(SVN, baseURL=baseURL, defaultBranch=defaultBranch,
                      mode="export")


builders = []



b24compile_opts = [
    "-Wignore::PendingDeprecationWarning:distutils.command.build_py",
    "-Wignore::PendingDeprecationWarning:distutils.command.build_ext",
    ]


b25compile_opts = b24compile_opts # FIXME


b1 = {'name': "quick",
      'slavename': "bot1",
      'builddir': "quick",
      'factory': QuickTwistedBuildFactory(source_update,
                                          python=["python2.3", "python2.4"]),
      }
builders.append(b1)

b23compile_opts = [
    "-Wignore::PendingDeprecationWarning:distutils.command.build_py",
    "-Wignore::PendingDeprecationWarning:distutils.command.build_ext",
    ]
b23 = {'name': "debian-py2.3-select",
       'slavename': "bot-exarkun",
       'builddir': "full2.3",
       'factory': FullTwistedBuildFactory(source_copy,
                                          python=["python2.3", "-Wall"],
                                          # use -Werror soon
                                          compileOpts=b23compile_opts,
                                          processDocs=1,
                                          runTestsRandomly=1),
       }
builders.append(b23)

b24 = {'name': "debian-py2.4-select",
       'slavenames': ["bot-exarkun"],
       'builddir': "full2.4",
       'factory': FullTwistedBuildFactory(source_copy,
                                          python=["python2.4", "-Wall"],
                                          # use -Werror soon
                                          compileOpts=b24compile_opts,
                                          runTestsRandomly=1),
       }
builders.append(b24)

b24debian64 = {
    'name': 'debian64-py2.4-select',
    'slavenames': ['bot-idnar-debian64'],
    'builddir': 'full2.4-debian64',
    'factory': FullTwistedBuildFactory(source_copy,
                                       python=["python2.4", "-Wall"],
                                       compileOpts=b24compile_opts),
    }
builders.append(b24debian64)

b25debian = {
    'name': 'debian-py2.5-select',
    'slavenames': ['bot-idnar-debian'],
    'builddir': 'full2.5-debian',
    'factory': FullTwistedBuildFactory(source_copy,
                                       python=["python2.5", "-Wall"],
                                       compileOpts=b24compile_opts)}
builders.append(b25debian)


b25suse = {
    'name': 'suse-py2.5-select',
    'slavenames': ['bot-scmikes-2.5'],
    'builddir': 'bot-scmikes-2.5',
    'factory': FullTwistedBuildFactory(source_copy,
                                       python=["python2.5", "-Wall"],
                                       compileOpts=b24compile_opts),
    }
builders.append(b25suse)

reactors = ['poll', 'epoll', 'gtk', 'gtk2']
b4 = {'name': "debian-py2.4-reactors",
      'slavename': "bot2",
      'builddir': "reactors",
      'factory': TwistedReactorsBuildFactory(source_copy,
                                             python="python2.4",
                                             reactors=reactors),
      }
builders.append(b4)

bosx24 = {
    'name': 'osx-py2.4-select',
    'slavenames': ['bot-exarkun-osx'],
    'builddir': 'full2.4-exarkun-osx',
    'factory': FullTwistedBuildFactory(source_copy,
                                       python=["python2.4", "-Wall"],
                                       compileOpts=b24compile_opts,
                                       runTestsRandomly=1)}
builders.append(bosx24)

forcegc = {
    'name': 'osx-py2.4-select-gc',
    'slavenames': ['bot-exarkun-osx'],
    'builddir': 'full2.4-force-gc-exarkun-osx',
    'factory': GoodTwistedBuildFactory(source_copy,
                                       python="python2.4")}
builders.append(forcegc)


# debuild is offline while we figure out how to build 2.0 .debs from SVN
# b3 = {'name': "debuild",
#       'slavename': "bot2",
#       'builddir': "debuild",
#       'factory': TwistedDebsBuildFactory(source_export,
#                                          python="python2.4"),
#       }
# builders.append(b3)

b24w32_scmikes_select = {
          'name': "win32-py2.4-select",
          'slavename': "bot-scmikes-win32",
          'builddir': "W32-full2.4-scmikes-select",
          'factory': TwistedReactorsBuildFactory(source_copy,
                                                 python="python",
                                                 compileOpts2=["-c","mingw32"],
                                                 reactors=["default"]),
          }
builders.append(b24w32_scmikes_select)

b25w32_scmikes_select = {
          'name': "win32-py2.5-select",
          'slavename': "bot-scmikes-win32-2.5",
          'builddir': "W32-full2.5-scmikes-select",
          'factory': TwistedReactorsBuildFactory(source_copy,
                                                 python="python",
                                                 compileOpts2=["-c","mingw32"],
                                                 reactors=["default"]),
          }
builders.append(b25w32_scmikes_select)

b24w32_win32er = {
          'name': "win32-py2.4-er",
          'slavename': "bot-win32-win32er",
          'builddir': "W32-full2.4-win32er",
          'factory': TwistedReactorsBuildFactory(source_copy,
                                                 python="python",
                                                 compileOpts2=["-c","mingw32"],
                                                 reactors=["win32"]),
          }
builders.append(b24w32_win32er)


b24w32_iocp = {
          'name': "win32-py2.4-iocp",
          'slavename': "bot-win32-iocp",
          'builddir': "W32-full2.4-iocp",
          'factory': TwistedReactorsBuildFactory(source_copy,
                                                 python="python",
                                                 compileOpts2=[],
                                                 reactors=["iocp"]),
          }
builders.append(b24w32_iocp)


b24freebsd = {'name': "freebsd-py2.4-select-kq",
              'slavename': "bot-landonf",
              'builddir': "freebsd-full2.4",
              'factory':
              TwistedReactorsBuildFactory(source_copy,
                                          python="python2.4",
                                          reactors=["default",
                                                    "kqueue",
                                                    ]),
              }
builders.append(b24freebsd)


osxtsr = {'name': "osx-py2.4-tsr",
          'slavename': "bot-exarkun-osx",
          'builddir': "osx-tsr",
          'factory': TwistedReactorsBuildFactory(
              source_copy,
              python="python2.4",
              reactors=["tsr"])}
builders.append(osxtsr)


bpypyc = {'name': 'osx-pypyc-select',
          'slavename': 'bot-jerub-pypy',
          'builddir': 'pypy-c',
          'factory': TwistedReactorsBuildFactory(source_copy,
						 python="pypy-c",
						 reactors=["default"])}
builders.append(bpypyc)

c['builders'] = builders

# now set up the schedulers. We do this after setting up c['builders'] so we
# can auto-generate a list of all of them.
all_builders = [b['name'] for b in c['builders']]
all_builders.sort()
all_builders.remove("quick")

## configure the schedulers
s_quick = Scheduler(name="quick", branch=None, treeStableTimer=30,
                    builderNames=["quick"])
s_try = Try_Userpass("try", all_builders, port=9989,
                     userpass=private.try_users)

s_all = []
for i, builderName in enumerate(all_builders):
    s_all.append(Scheduler(name="all-" + builderName,
                           branch=None, builderNames=[builderName],
                           treeStableTimer=(5 * 60 + i * 30)))
c['schedulers'] = [s_quick, s_try] + s_all



# configure other status things

c['slavePortnum'] = 9987
c['status'] = []
if really:
    p = os.path.expanduser("~/.twistd-web-pb")
    c['status'].append(html.Waterfall(distrib_port=p))
else:
    c['status'].append(html.Waterfall(http_port=9988))
if really:
    c['status'].append(words.IRC(host="irc.freenode.net",
                                 nick='buildbot',
                                 channels=["twisted"]))

c['debugPassword'] = private.debugPassword
#c['interlocks'] = [("do-deb", ["full-2.2"], ["debuild"])]
if hasattr(private, "manhole"):
    from buildbot import manhole
    c['manhole'] = manhole.PasswordManhole(*private.manhole)
c['status'].append(client.PBListener(9936))
m = mail.MailNotifier(fromaddr="buildbot@twistedmatrix.com",
                      builders=["quick", "debian-py2.3-select"],
                      sendToInterestedUsers=True,
		      extraRecipients=["warner@lothar.com"],
		      mode="problem",
		      )
c['status'].append(m)
c['title'] = "Twisted"
c['titleURL'] = "http://twistedmatrix.com/"
c['buildbotURL'] = "http://twistedmatrix.com/buildbot/"
