1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os
17
18 from buildslave.commands import base
19 from buildslave import runprocess
20
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
63 args = self.args
64
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
92
95
98