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