Package buildbot :: Package scripts :: Module create_master
[frames] | no frames]

Source Code for Module buildbot.scripts.create_master

  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. 
  4  # 
  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 
  8  # details. 
  9  # 
 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. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16  from __future__ import with_statement 
 17   
 18  import os 
 19  import jinja2 
 20  from twisted.python import util 
 21  from twisted.internet import defer 
 22  from buildbot.util import in_reactor 
 23  from buildbot.db import connector 
 24  from buildbot.master import BuildMaster 
 25  from buildbot import config as config_module 
 26  from buildbot import monkeypatches 
27 28 -def makeBasedir(config):
29 if os.path.exists(config['basedir']): 30 if not config['quiet']: 31 print "updating existing installation" 32 return 33 if not config['quiet']: 34 print "mkdir", config['basedir'] 35 os.mkdir(config['basedir'])
36
37 -def makeTAC(config):
38 # render buildbot_tac.tmpl using the config 39 loader = jinja2.FileSystemLoader(os.path.dirname(__file__)) 40 env = jinja2.Environment(loader=loader, undefined=jinja2.StrictUndefined) 41 env.filters['repr'] = repr 42 tpl = env.get_template('buildbot_tac.tmpl') 43 cxt = dict((k.replace('-', '_'), v) for k,v in config.iteritems()) 44 contents = tpl.render(cxt) 45 46 tacfile = os.path.join(config['basedir'], "buildbot.tac") 47 if os.path.exists(tacfile): 48 with open(tacfile, "rt") as f: 49 oldcontents = f.read() 50 if oldcontents == contents: 51 if not config['quiet']: 52 print "buildbot.tac already exists and is correct" 53 return 54 if not config['quiet']: 55 print "not touching existing buildbot.tac" 56 print "creating buildbot.tac.new instead" 57 tacfile += ".new" 58 with open(tacfile, "wt") as f: 59 f.write(contents)
60
61 -def makeSampleConfig(config):
62 source = util.sibpath(__file__, "sample.cfg") 63 target = os.path.join(config['basedir'], "master.cfg.sample") 64 if not config['quiet']: 65 print "creating %s" % target 66 with open(source, "rt") as f: 67 config_sample = f.read() 68 if config['db']: 69 config_sample = config_sample.replace('sqlite:///state.sqlite', 70 config['db']) 71 with open(target, "wt") as f: 72 f.write(config_sample) 73 os.chmod(target, 0600)
74
75 -def makePublicHtml(config):
76 files = { 77 'bg_gradient.jpg' : "../status/web/files/bg_gradient.jpg", 78 'default.css' : "../status/web/files/default.css", 79 'robots.txt' : "../status/web/files/robots.txt", 80 'favicon.ico' : "../status/web/files/favicon.ico", 81 } 82 webdir = os.path.join(config['basedir'], "public_html") 83 if os.path.exists(webdir): 84 if not config['quiet']: 85 print "public_html/ already exists: not replacing" 86 return 87 else: 88 os.mkdir(webdir) 89 if not config['quiet']: 90 print "populating public_html/" 91 for target, source in files.iteritems(): 92 source = util.sibpath(__file__, source) 93 target = os.path.join(webdir, target) 94 with open(target, "wt") as f: 95 with open(source, "rt") as i: 96 f.write(i.read())
97
98 -def makeTemplatesDir(config):
99 files = { 100 'README.txt' : "../status/web/files/templates_readme.txt", 101 } 102 template_dir = os.path.join(config['basedir'], "templates") 103 if os.path.exists(template_dir): 104 if not config['quiet']: 105 print "templates/ already exists: not replacing" 106 return 107 else: 108 os.mkdir(template_dir) 109 if not config['quiet']: 110 print "populating templates/" 111 for target, source in files.iteritems(): 112 source = util.sibpath(__file__, source) 113 target = os.path.join(template_dir, target) 114 with open(target, "wt") as f: 115 with open(source, "rt") as i: 116 f.write(i.read())
117
118 @defer.inlineCallbacks 119 -def createDB(config, _noMonkey=False):
120 # apply the db monkeypatches (and others - no harm) 121 if not _noMonkey: # pragma: no cover 122 monkeypatches.patch_all() 123 124 # create a master with the default configuration, but with db_url 125 # overridden 126 master_cfg = config_module.MasterConfig() 127 master_cfg.db['db_url'] = config['db'] 128 master = BuildMaster(config['basedir']) 129 master.config = master_cfg 130 db = connector.DBConnector(master, config['basedir']) 131 yield db.setup(check_version=False, verbose=not config['quiet']) 132 if not config['quiet']: 133 print "creating database (%s)" % (master_cfg.db['db_url'],) 134 yield db.model.upgrade()
135
136 137 @in_reactor 138 @defer.inlineCallbacks 139 -def createMaster(config):
140 makeBasedir(config) 141 makeTAC(config) 142 makeSampleConfig(config) 143 makePublicHtml(config) 144 makeTemplatesDir(config) 145 yield createDB(config) 146 147 if not config['quiet']: 148 print "buildmaster configured in %s" % (config['basedir'],) 149 150 defer.returnValue(0)
151