# -*- python -*-
# vim: ft=python

# 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 = {}

components = [
	"rna-seqlyze" + part for part in ('', '-cli', '-web', '-worker')
]

####### 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.
from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave("@@HOSTNAME@@", "pass", max_builds=1)]

# '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'] = "tcp:9989:interface=127.0.0.1"

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.

from buildbot.changes.pb import PBChangeSource
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

from buildbot.schedulers.basic import SingleBranchScheduler, Dependent

core_scheduler = SingleBranchScheduler(
                            name="build-core",
                            branch="master",
                            builderNames=components[:1])

components_scheduler = Dependent(
                            name="build-components",
                            upstream=core_scheduler,
                            builderNames=components[1:])

c['schedulers'] = [core_scheduler, components_scheduler]

####### 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.

from buildbot.process.factory import BuildFactory
from buildbot.steps.source import Git
from buildbot.steps.shell import ShellCommand
from buildbot.steps.python import PyFlakes
from buildbot.config import BuilderConfig

c['builders'] = []

for component in components:

    factory = BuildFactory()

    # check out the source
    factory.addStep(Git(repourl='@@TOPDIR@@', shallow=True))

    factory.addStep(PyFlakes(command=["pyflakes", "."],
			     workdir="build/src/" + component,
			     description=["style-checking", component],
			     descriptionDone=["style-check", component]))
    factory.addStep(ShellCommand(command=["python", "setup.py", "test"],
			         workdir="build/src/" + component,
				 description=["testing", component],
				 descriptionDone=["test", component]))
    factory.addStep(ShellCommand(command=["setup_devok"],
			         workdir="build/src/" + component,
				 description=["installing", component],
				 descriptionDone=["install", component]))

    c['builders'].append(
	BuilderConfig(factory=factory, name=component,
		      slavenames=["@@HOSTNAME@@"], slavebuilddir="builddir"))

####### 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 import html
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
#    auth=auth.BasicAuth([("admin","fhnw")]),
#    forceBuild = 'auth', # use this to test your slave once it is set up
    forceBuild = False,
    gracefulShutdown = False,
    forceAllBuilds = False,
    pingBuilder = False,
    stopBuild = False,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(
	http_port=8010,
#	authz=authz_cfg,
	order_console_by_time=True))

####### 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'] = "RNA-seqlyze"
c['titleURL'] = "http://@@HOSTNAME@@/@@WWWBASE_@@"

# 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://@@HOSTNAME@@/@@WWWBASE_@@buildbot/"

####### DB URL

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