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

Source Code for Module buildbot.scripts.reconfig

 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   
19  import os 
20  import signal 
21  import platform 
22  from twisted.internet import reactor 
23   
24  from buildbot.scripts.logwatcher import LogWatcher, BuildmasterTimeoutError, \ 
25       ReconfigError 
26  from buildbot.util import in_reactor 
27 28 -class Reconfigurator:
29 30 rc = 0 31
32 - def run(self, basedir, quiet):
33 # Returns "Microsoft" for Vista and "Windows" for other versions 34 if platform.system() in ("Windows", "Microsoft"): 35 print "Reconfig (through SIGHUP) is not supported on Windows." 36 print "The 'buildbot debugclient' tool can trigger a reconfig" 37 print "remotely, but requires Gtk+ libraries to run." 38 return 39 40 with open(os.path.join(basedir, "twistd.pid"), "rt") as f: 41 self.pid = int(f.read().strip()) 42 if quiet: 43 os.kill(self.pid, signal.SIGHUP) 44 return 45 46 # keep reading twistd.log. Display all messages between "loading 47 # configuration from ..." and "configuration update complete" or 48 # "I will keep using the previous config file instead.", or until 49 # 10 seconds have elapsed. 50 51 self.sent_signal = False 52 reactor.callLater(0.2, self.sighup) 53 54 lw = LogWatcher(os.path.join(basedir, "twistd.log")) 55 d = lw.start() 56 d.addCallbacks(self.success, self.failure) 57 d.addBoth(lambda _ : self.rc) 58 return d
59
60 - def sighup(self):
61 if self.sent_signal: 62 return 63 print "sending SIGHUP to process %d" % self.pid 64 self.sent_signal = True 65 os.kill(self.pid, signal.SIGHUP)
66
67 - def success(self, res):
68 print """ 69 Reconfiguration appears to have completed successfully. 70 """
71
72 - def failure(self, why):
73 self.rc = 1 74 if why.check(BuildmasterTimeoutError): 75 print "Never saw reconfiguration finish." 76 elif why.check(ReconfigError): 77 print """ 78 Reconfiguration failed. Please inspect the master.cfg file for errors, 79 correct them, then try 'buildbot reconfig' again. 80 """ 81 elif why.check(IOError): 82 # we were probably unable to open the file in the first place 83 self.sighup() 84 else: 85 print "Error while following twistd.log: %s" % why
86
87 @in_reactor 88 -def reconfig(config):
89 basedir = config['basedir'] 90 quiet = config['quiet'] 91 r = Reconfigurator() 92 return r.run(basedir, quiet)
93