1
# This file is part of Buildbot. Buildbot is free software: you can
2
# redistribute it and/or modify it under the terms of the GNU General Public
3
# License as published by the Free Software Foundation, version 2.
5
# This program is distributed in the hope that it will be useful, but WITHOUT
6
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10
# You should have received a copy of the GNU General Public License along with
11
# this program; if not, write to the Free Software Foundation, Inc., 51
12
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14
# Copyright Buildbot Team Members
18
from twisted.python import util
19
from twisted.internet import defer
20
from buildbot.util import in_reactor
21
from buildbot.db import connector
22
from buildbot.master import BuildMaster
23
from buildbot import config as config_module
24
from buildbot import monkeypatches
26
def makeBasedir(config):
27
if os.path.exists(config['basedir']):
28
if not config['quiet']:
29
print "updating existing installation"
31
if not config['quiet']:
32
print "mkdir", config['basedir']
33
os.mkdir(config['basedir'])
36
# render buildbot_tac.tmpl using the config
37
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
38
env = jinja2.Environment(loader=loader, undefined=jinja2.StrictUndefined)
39
env.filters['repr'] = repr
40
tpl = env.get_template('buildbot_tac.tmpl')
41
cxt = dict((k.replace('-', '_'), v) for k,v in config.iteritems())
42
contents = tpl.render(cxt)
44
tacfile = os.path.join(config['basedir'], "buildbot.tac")
45
if os.path.exists(tacfile):
46
with open(tacfile, "rt") as f:
47
oldcontents = f.read()
48
if oldcontents == contents:
49
if not config['quiet']:
50
print "buildbot.tac already exists and is correct"
52
if not config['quiet']:
53
print "not touching existing buildbot.tac"
54
print "creating buildbot.tac.new instead"
56
with open(tacfile, "wt") as f:
59
def makeSampleConfig(config):
60
source = util.sibpath(__file__, "sample.cfg")
61
target = os.path.join(config['basedir'], "master.cfg.sample")
62
if not config['quiet']:
63
print "creating %s" % target
64
with open(source, "rt") as f:
65
config_sample = f.read()
67
config_sample = config_sample.replace('sqlite:///state.sqlite',
69
with open(target, "wt") as f:
70
f.write(config_sample)
71
os.chmod(target, 0600)
73
def makePublicHtml(config):
75
'bg_gradient.jpg' : "../status/web/files/bg_gradient.jpg",
76
'default.css' : "../status/web/files/default.css",
77
'robots.txt' : "../status/web/files/robots.txt",
78
'favicon.ico' : "../status/web/files/favicon.ico",
80
webdir = os.path.join(config['basedir'], "public_html")
81
if os.path.exists(webdir):
82
if not config['quiet']:
83
print "public_html/ already exists: not replacing"
87
if not config['quiet']:
88
print "populating public_html/"
89
for target, source in files.iteritems():
90
source = util.sibpath(__file__, source)
91
target = os.path.join(webdir, target)
92
with open(target, "wt") as f:
93
with open(source, "rt") as i:
96
def makeTemplatesDir(config):
98
'README.txt' : "../status/web/files/templates_readme.txt",
100
template_dir = os.path.join(config['basedir'], "templates")
101
if os.path.exists(template_dir):
102
if not config['quiet']:
103
print "templates/ already exists: not replacing"
106
os.mkdir(template_dir)
107
if not config['quiet']:
108
print "populating templates/"
109
for target, source in files.iteritems():
110
source = util.sibpath(__file__, source)
111
target = os.path.join(template_dir, target)
112
with open(target, "wt") as f:
113
with open(source, "rt") as i:
116
@defer.inlineCallbacks
117
def createDB(config, _noMonkey=False):
118
# apply the db monkeypatches (and others - no harm)
119
if not _noMonkey: # pragma: no cover
120
monkeypatches.patch_all()
122
# create a master with the default configuration, but with db_url
124
master_cfg = config_module.MasterConfig()
125
master_cfg.db['db_url'] = config['db']
126
master = BuildMaster(config['basedir'])
127
master.config = master_cfg
128
db = connector.DBConnector(master, config['basedir'])
129
yield db.setup(check_version=False, verbose=not config['quiet'])
130
if not config['quiet']:
131
print "creating database (%s)" % (master_cfg.db['db_url'],)
132
yield db.model.upgrade()
136
@defer.inlineCallbacks
137
def createMaster(config):
140
makeSampleConfig(config)
141
makePublicHtml(config)
142
makeTemplatesDir(config)
143
yield createDB(config)
145
if not config['quiet']:
146
print "buildmaster configured in %s" % (config['basedir'],)