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          - ['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   
59          args = self.args 
60           
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   
87   
90   
 93