Package buildslave :: Package commands :: Module shell
[frames] | no frames]

Source Code for Module buildslave.commands.shell

 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  import os 
17   
18  from buildslave.commands import base 
19  from buildslave import runprocess 
20   
21 -class SlaveShellCommand(base.Command):
22 """This is a Command which runs a shell command. The args dict contains 23 the following keys: 24 25 - ['command'] (required): a shell command to run. If this is a string, 26 it will be run with /bin/sh (['/bin/sh', 27 '-c', command]). If it is a list 28 (preferred), it will be used directly. 29 - ['workdir'] (required): subdirectory in which the command will be 30 run, relative to the builder dir 31 - ['env']: a dict of environment variables to augment/replace 32 os.environ . PYTHONPATH is treated specially, and 33 should be a list of path components to be prepended to 34 any existing PYTHONPATH environment variable. 35 - ['initial_stdin']: a string which will be written to the command's 36 stdin as soon as it starts 37 - ['want_stdout']: 0 if stdout should be thrown away 38 - ['want_stderr']: 0 if stderr should be thrown away 39 - ['usePTY']: True or False if the command should use a PTY (defaults to 40 configuration of the slave) 41 - ['not_really']: 1 to skip execution and return rc=0 42 - ['timeout']: seconds of silence to tolerate before killing command 43 - ['maxTime']: seconds before killing command 44 - ['logfiles']: dict mapping LogFile name to the workdir-relative 45 filename of a local log file. This local file will be 46 watched just like 'tail -f', and all changes will be 47 written to 'log' status updates. 48 - ['logEnviron']: False to not log the environment variables on the slave 49 50 ShellCommand creates the following status messages: 51 - {'stdout': data} : when stdout data is available 52 - {'stderr': data} : when stderr data is available 53 - {'header': data} : when headers (command start/stop) are available 54 - {'log': (logfile_name, data)} : when log files have new contents 55 - {'rc': rc} : when the process has terminated 56 """ 57
58 - def start(self):
59 args = self.args 60 # args['workdir'] is relative to Builder directory, and is required. 61 assert args['workdir'] is not None 62 workdir = os.path.join(self.builder.basedir, args['workdir']) 63 64 c = runprocess.RunProcess( 65 self.builder, 66 args['command'], 67 workdir, 68 environ=args.get('env'), 69 timeout=args.get('timeout', None), 70 maxTime=args.get('maxTime', None), 71 sendStdout=args.get('want_stdout', True), 72 sendStderr=args.get('want_stderr', True), 73 sendRC=True, 74 initialStdin=args.get('initial_stdin'), 75 logfiles=args.get('logfiles', {}), 76 usePTY=args.get('usePTY', "slave-config"), 77 logEnviron=args.get('logEnviron', True), 78 ) 79 c._reactor = self._reactor 80 self.command = c 81 d = self.command.start() 82 return d
83
84 - def interrupt(self):
85 self.interrupted = True 86 self.command.kill("command interrupted")
87
88 - def writeStdin(self, data):
89 self.command.writeStdin(data)
90
91 - def closeStdin(self):
92 self.command.closeStdin()
93