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 - ['keep_stdin_open']: unless True, the command's stdin will be 38 closed as soon as initial_stdin has been 39 written. Set this to True if you plan to write 40 to stdin after the command has been started. 41 - ['want_stdout']: 0 if stdout should be thrown away 42 - ['want_stderr']: 0 if stderr should be thrown away 43 - ['usePTY']: True or False if the command should use a PTY (defaults to 44 configuration of the slave) 45 - ['not_really']: 1 to skip execution and return rc=0 46 - ['timeout']: seconds of silence to tolerate before killing command 47 - ['maxTime']: seconds before killing command 48 - ['logfiles']: dict mapping LogFile name to the workdir-relative 49 filename of a local log file. This local file will be 50 watched just like 'tail -f', and all changes will be 51 written to 'log' status updates. 52 - ['logEnviron']: False to not log the environment variables on the slave 53 54 ShellCommand creates the following status messages: 55 - {'stdout': data} : when stdout data is available 56 - {'stderr': data} : when stderr data is available 57 - {'header': data} : when headers (command start/stop) are available 58 - {'log': (logfile_name, data)} : when log files have new contents 59 - {'rc': rc} : when the process has terminated 60 """ 61
62 - def start(self):
63 args = self.args 64 # args['workdir'] is relative to Builder directory, and is required. 65 assert args['workdir'] is not None 66 workdir = os.path.join(self.builder.basedir, args['workdir']) 67 68 c = runprocess.RunProcess( 69 self.builder, 70 args['command'], 71 workdir, 72 environ=args.get('env'), 73 timeout=args.get('timeout', None), 74 maxTime=args.get('maxTime', None), 75 sendStdout=args.get('want_stdout', True), 76 sendStderr=args.get('want_stderr', True), 77 sendRC=True, 78 initialStdin=args.get('initial_stdin'), 79 keepStdinOpen=args.get('keep_stdin_open', False), 80 logfiles=args.get('logfiles', {}), 81 usePTY=args.get('usePTY', "slave-config"), 82 logEnviron=args.get('logEnviron', True), 83 ) 84 c._reactor = self._reactor 85 self.command = c 86 d = self.command.start() 87 return d
88
89 - def interrupt(self):
90 self.interrupted = True 91 self.command.kill("command interrupted")
92
93 - def writeStdin(self, data):
94 self.command.writeStdin(data)
95
96 - def closeStdin(self):
97 self.command.closeStdin()
98