1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 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 
 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   
 38       
 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   
 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   
 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   
 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): 
 135   
136   
137  @in_reactor 
138  @defer.inlineCallbacks 
139 -def createMaster(config): 
 151