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