# -*- python -*-
# ex: set syntax=python:

from buildbot.plugins import *

# 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.BuildSlave("Avalon4mini", "password"),
                buildslave.BuildSlave("Avalon nano 2.0", "password")]

# 'protocols' contains information about protocols which master will use for
# communicating with slaves.
# You must define at least 'port' option that slaves could connect to your master
# with this protocol.
# 'port' must match the value configured into the buildslaves (with their
# --master option)
c['protocols'] = {'pb': {'port': 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'] = []
c['change_source'].append(changes.GitPoller(
        'https://github.com/Canaan-Creative/Avalon-nano',
        workdir='gitpoller-workdir', branch='master',
        pollinterval=300))

####### SCHEDULERS

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

c['schedulers'] = []
c['schedulers'].append(schedulers.SingleBranchScheduler(
                            name="all",
                            change_filter=util.ChangeFilter(branch='master'),
                            treeStableTimer=None,
                            builderNames=["Avalon4mini_release", "Avalonnano2_release"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="A4MR_force",
                            builderNames=["Avalon4mini_release"]))
c['schedulers'].append(schedulers.ForceScheduler(
                            name="A3N2R_force",
                            builderNames=["Avalonnano2_release"]))
####### 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.

# Avalon4 mini realase
build_steps = [
        steps.Git(repourl='https://github.com/Canaan-Creative/Avalon-nano', mode='full'),
        steps.ShellCommand(command=["make", "clean"],
                workdir="build/firmware/mini",
		env={'PATH': ["/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/tools/bin/",
                "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/",
                "${PATH}"],
                'LPCLINK_FIRM': "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/LPCXpressoWIN.enc"}),
        steps.ShellCommand(command=["make", "all"],
                workdir="build/firmware/mini",
                env={'PATH': ["/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/tools/bin/",
                "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/",
                "${PATH}"],
                'LPCLINK_FIRM': "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/LPCXpressoWIN.enc"}),
	steps.ShellCommand(command=["sh", "-c", "rsync -avz firmware/mini/bin/* /home/mikeqin/public_html/avalon4mini"]),
	steps.ShellCommand(command=["sh", "-c", "chmod 755 -R /home/mikeqin/public_html/avalon4mini"]),
]

factory = util.BuildFactory(build_steps)

c['builders'] = []
c['builders'].append(
    util.BuilderConfig(name="Avalon4mini_release",
      slavenames=["Avalon4mini"],
      factory=factory))

# Avalonnano2_release
build_steps = [
        steps.Git(repourl='https://github.com/Canaan-Creative/Avalon-nano', mode='full'),
	steps.ShellCommand(command=["make", "clean"],
                workdir="build/firmware/nano",
                env={'PATH': ["/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/tools/bin/",
                "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/",
                "${PATH}"],
                'LPCLINK_FIRM': "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/LPCXpressoWIN.enc"}),
        steps.ShellCommand(command=["make", "all"],
                workdir="build/firmware/nano",
                env={'PATH': ["/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/tools/bin/",
                "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/",
                "${PATH}"],
                'LPCLINK_FIRM': "/usr/local/lpcxpresso_7.9.0_455/lpcxpresso/bin/LPCXpressoWIN.enc"}),
	steps.ShellCommand(command=["sh", "-c", "rsync -avz firmware/nano/bin/* /home/mikeqin/public_html/avalonnano2"]),
	steps.ShellCommand(command=["sh", "-c", "chmod 755 -R /home/mikeqin/public_html/avalonnano2"]),
]

factory = util.BuildFactory(build_steps)
c['builders'].append(
    util.BuilderConfig(name="Avalonnano2_release",
      slavenames=["Avalon nano 2.0"],
      factory=factory))

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

from buildbot.plugins import status

irc = status.IRC("irc.freenode.org", "avalonbot",
                 useColors=False,
                 channels=[{"channel": "#avalon"}],
                 noticeOnChannel=True,
                 notify_events={
                   'exception': 1,
                   'success': 1,
                   'failure': 1
                 })

c['status'].append(irc)

####### 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'] = "Canaan Creative"
c['titleURL'] = "https://github.com/Canaan-Creative"

# 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://build.canaan-creative.com:8010/"

####### 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",
}
