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

Source Code for Module buildslave.commands.shell

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