~vcs-imports/kupfer/master-new

« back to all changes in this revision

Viewing changes to waflib/extras/print_commands.py

  • Committer: Ulrik Sverdrup
  • Date: 2012-02-26 17:32:06 UTC
  • mto: This revision was merged to the branch mainline in revision 2918.
  • Revision ID: git-v1:684a1e79e28fa3d9e346bdf2c1659e7d2c6e7718
Add waf-light and waflib from waf-1.6.11

http://code.google.com/p/waf/
Acquired from: http://waf.googlecode.com/files/waf-1.6.11.tar.bz2

"""
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
"""

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
"""
 
4
Illustrate how to override a class method to do something
 
5
 
 
6
In this case, print the commands being executed as strings
 
7
(the commands are usually lists, so this can be misleading)
 
8
"""
 
9
 
 
10
import sys
 
11
from waflib import Context, Utils, Logs
 
12
 
 
13
def exec_command(self, cmd, **kw):
 
14
        subprocess = Utils.subprocess
 
15
        kw['shell'] = isinstance(cmd, str)
 
16
 
 
17
        txt = cmd
 
18
        if isinstance(cmd, list):
 
19
                txt = ' '.join(cmd)
 
20
 
 
21
        print(txt)
 
22
        Logs.debug('runner_env: kw=%s' % kw)
 
23
 
 
24
        try:
 
25
                if self.logger:
 
26
                        # warning: may deadlock with a lot of output (subprocess limitation)
 
27
 
 
28
                        self.logger.info(cmd)
 
29
 
 
30
                        kw['stdout'] = kw['stderr'] = subprocess.PIPE
 
31
                        p = subprocess.Popen(cmd, **kw)
 
32
                        (out, err) = p.communicate()
 
33
                        if out:
 
34
                                self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
 
35
                        if err:
 
36
                                self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
 
37
                        return p.returncode
 
38
                else:
 
39
                        p = subprocess.Popen(cmd, **kw)
 
40
                        return p.wait()
 
41
        except OSError:
 
42
                return -1
 
43
 
 
44
Context.Context.exec_command = exec_command
 
45
 
 
46