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 sys
20 import traceback
21 from twisted.internet import defer
22 from twisted.python import util, runtime
23 from buildbot import config as config_module
24 from buildbot import monkeypatches
25 from buildbot.db import connector
26 from buildbot.master import BuildMaster
27 from buildbot.util import in_reactor
28 from buildbot.scripts import base
31 if not config['quiet']:
32 print "checking basedir"
33
34 if not base.isBuildmasterDir(config['basedir']):
35 return False
36
37 if runtime.platformType != 'win32':
38 if not config['quiet']:
39 print "checking for running master"
40 pidfile = os.path.join(config['basedir'], 'twistd.pid')
41 if os.path.exists(pidfile):
42 print "'%s' exists - is this master still running?" % (pidfile,)
43 return False
44
45 return True
46
47 -def loadConfig(config, configFileName='master.cfg'):
48 if not config['quiet']:
49 print "checking %s" % configFileName
50
51 try:
52 master_cfg = config_module.MasterConfig.loadConfig(
53 config['basedir'], configFileName)
54 except config_module.ConfigErrors, e:
55 print "Errors loading configuration:"
56 for msg in e.errors:
57 print " " + msg
58 return
59 except:
60 print "Errors loading configuration:"
61 traceback.print_exc(file=sys.stdout)
62 return
63
64 return master_cfg
65
66 -def installFile(config, target, source, overwrite=False):
67 with open(source, "rt") as f:
68 new_contents = f.read()
69 if os.path.exists(target):
70 with open(target, "rt") as f:
71 old_contents = f.read()
72 if old_contents != new_contents:
73 if overwrite:
74 if not config['quiet']:
75 print "%s has old/modified contents" % target
76 print " overwriting it with new contents"
77 with open(target, "wt") as f:
78 f.write(new_contents)
79 else:
80 if not config['quiet']:
81 print "%s has old/modified contents" % target
82 print " writing new contents to %s.new" % target
83 with open(target + ".new", "wt") as f:
84 f.write(new_contents)
85
86 else:
87 if not config['quiet']:
88 print "creating %s" % target
89 with open(target, "wt") as f:
90 f.write(new_contents)
91
93 if not config['quiet']:
94 print "upgrading basedir"
95
96 webdir = os.path.join(config['basedir'], "public_html")
97 if not os.path.exists(webdir):
98 if not config['quiet']:
99 print "creating public_html"
100 os.mkdir(webdir)
101
102 templdir = os.path.join(config['basedir'], "templates")
103 if not os.path.exists(templdir):
104 if not config['quiet']:
105 print "creating templates"
106 os.mkdir(templdir)
107
108 for file in ('bg_gradient.jpg', 'default.css',
109 'robots.txt', 'favicon.ico'):
110 source = util.sibpath(__file__, "../status/web/files/%s" % (file,))
111 target = os.path.join(webdir, file)
112 try:
113 installFile(config, target, source)
114 except IOError:
115 print "Can't write '%s'." % (target,)
116
117 installFile(config, os.path.join(config['basedir'], "master.cfg.sample"),
118 util.sibpath(__file__, "sample.cfg"), overwrite=True)
119
120
121 index_html = os.path.join(webdir, "index.html")
122 root_html = os.path.join(templdir, "root.html")
123 if os.path.exists(index_html):
124 if os.path.exists(root_html):
125 print "Notice: %s now overrides %s" % (root_html, index_html)
126 print " as the latter is not used by buildbot anymore."
127 print " Decide which one you want to keep."
128 else:
129 try:
130 print "Notice: Moving %s to %s." % (index_html, root_html)
131 print " You can (and probably want to) remove it if " \
132 "you haven't modified this file."
133 os.renames(index_html, root_html)
134 except Exception, e:
135 print "Error moving %s to %s: %s" % (index_html, root_html,
136 str(e))
137
149
150 @in_reactor
151 @defer.inlineCallbacks
152 -def upgradeMaster(config, _noMonkey=False):
175