tools/cr/cr/base/host.py
def _Execute(self, command,
               shell=False, capture=False, silent=False,
               ignore_dry_run=False, return_status=False,
               ignore_interrupt_signal=False):
    """This is the only method that launches external programs.

    It is a thin wrapper around subprocess.Popen that handles cr specific
    issues. The command is expanded in the active context so that variables
    are substituted.
    Args:
      command: the command to run.
      shell: whether to run the command using the shell.
      capture: controls wether the output of the command is captured.
      ignore_dry_run: Normally, if the context is in dry run mode the command is
        printed but not executed. This flag overrides that behaviour, causing
        the command to be run anyway.
      return_status: switches the function to returning the status code rather
        the output.
      ignore_interrupt_signal: Ignore the interrupt signal (i.e., Ctrl-C) while
        the command is running. Useful for letting interactive programs manage
        Ctrl-C by themselves.
    Returns:
      the status if return_status is true, or the output if capture is true,
      otherwise nothing.
    """
    with cr.context.Trace():
      command = [cr.context.Substitute(arg) for arg in command if arg]
      command = filter(bool, command)
    trail = cr.context.trail
    if not command:
      print('Empty command passed to execute')
      exit(1)
    if cr.context.verbose:
      print(' '.join(command))
      if cr.context.verbose >= _TRAIL_VERBOSITY:
        PrintTrail(trail)
    if ignore_dry_run or not cr.context.dry_run:
      out = None
      if capture:
        out = subprocess.PIPE
      elif silent:
        out = open(os.devnull, "w")
      try:
        p = subprocess.Popen(
            command, shell=shell,
            env={k: str(v) for k, v in cr.context.exported.items()},
            stdout=out)
      except OSError:
        print('Failed to exec', command)
        # Don't log the trail if we already have
        if cr.context.verbose < _TRAIL_VERBOSITY:
          PrintTrail(trail)
        exit(1)
      try:
        if ignore_interrupt_signal:
          signal.signal(signal.SIGINT, signal.SIG_IGN)
        output, _ = p.communicate()
      finally:
        if ignore_interrupt_signal:
          signal.signal(signal.SIGINT, signal.SIG_DFL)
        if silent:
          out.close()
      if return_status:
        return p.returncode
      if p.returncode != 0:
        print('Error {0} executing command {1}'.format(p.returncode, command))
        exit(p.returncode)
      if output is not None:
        output = output.decode('utf-8')
      return output or ''
    return ''
This is the only method that launches external programs.

    It is a thin wrapper around subprocess.Popen that handles cr specific
    issues. The command is expanded in the active context so that variables
    are substituted.
    Args:
      command: the command to run.
      shell: whether to run the command using the shell.
      capture: controls wether the output of the command is captured.
      ignore_dry_run: Normally, if the context is in dry run mode the command is
        printed but not executed. This flag overrides that behaviour, causing
        the command to be run anyway.
      return_status: switches the function to returning the status code rather
        the output.
      ignore_interrupt_signal: Ignore the interrupt signal (i.e., Ctrl-C) while
        the command is running. Useful for letting interactive programs manage
        Ctrl-C by themselves.
    Returns:
      the status if return_status is true, or the output if capture is true,
      otherwise nothing.
    
This is the only method that launches external programs.
It is a thin wrapper around subprocess.Popen that handles cr specific
issues. The command is expanded in the active context so that variables
are substituted.
This is the only method that launches external programs . It is a thin wrapper around subprocess . Popen that handles cr specific issues . The command is expanded in the active context so that variables are substituted .
def _Execute(self, command,
               shell=False, capture=False, silent=False,
               ignore_dry_run=False, return_status=False,
               ignore_interrupt_signal=False):
    with cr.context.Trace():
      command = [cr.context.Substitute(arg) for arg in command if arg]
      command = filter(bool, command)
    trail = cr.context.trail
    if not command:
      print('Empty command passed to execute')
      exit(1)
    if cr.context.verbose:
      print(' '.join(command))
      if cr.context.verbose >= _TRAIL_VERBOSITY:
        PrintTrail(trail)
    if ignore_dry_run or not cr.context.dry_run:
      out = None
      if capture:
        out = subprocess.PIPE
      elif silent:
        out = open(os.devnull, "w")
      try:
        p = subprocess.Popen(
            command, shell=shell,
            env={k: str(v) for k, v in cr.context.exported.items()},
            stdout=out)
      except OSError:
        print('Failed to exec', command)
        if cr.context.verbose < _TRAIL_VERBOSITY:
          PrintTrail(trail)
        exit(1)
      try:
        if ignore_interrupt_signal:
          signal.signal(signal.SIGINT, signal.SIG_IGN)
        output, _ = p.communicate()
      finally:
        if ignore_interrupt_signal:
          signal.signal(signal.SIGINT, signal.SIG_DFL)
        if silent:
          out.close()
      if return_status:
        return p.returncode
      if p.returncode != 0:
        print('Error {0} executing command {1}'.format(p.returncode, command))
        exit(p.returncode)
      if output is not None:
        output = output.decode('utf-8')
      return output or ''
    return ''
def _Execute ( self , command , shell = False , capture = False , silent = False , ignore_dry_run = False , return_status = False , ignore_interrupt_signal = False ) : with cr . context . Trace ( ) : command = [ cr . context . Substitute ( arg ) for arg in command if arg ] command = filter ( bool , command ) trail = cr . context . trail if not command : print ( 'Empty command passed to execute' ) exit ( 1 ) if cr . context . verbose : print ( ' ' . join ( command ) ) if cr . context . verbose >= _TRAIL_VERBOSITY : PrintTrail ( trail ) if ignore_dry_run or not cr . context . dry_run : out = None if capture : out = subprocess . PIPE elif silent : out = open ( os . devnull , "w" ) try : p = subprocess . Popen ( command , shell = shell , env = { k : str ( v ) for k , v in cr . context . exported . items ( ) } , stdout = out ) except OSError : print ( 'Failed to exec' , command ) if cr . context . verbose < _TRAIL_VERBOSITY : PrintTrail ( trail ) exit ( 1 ) try : if ignore_interrupt_signal : signal . signal ( signal . SIGINT , signal . SIG_IGN ) output , _ = p . communicate ( ) finally : if ignore_interrupt_signal : signal . signal ( signal . SIGINT , signal . SIG_DFL ) if silent : out . close ( ) if return_status : return p . returncode if p . returncode != 0 : print ( 'Error {0} executing command {1}' . format ( p . returncode , command ) ) exit ( p . returncode ) if output is not None : output = output . decode ( 'utf-8' ) return output or '' return ''
This is the only method that launches external programs.
This is the only method that launches external programs .
"""This is the only method that launches external programs.

    It is a thin wrapper around subprocess.Popen that handles cr specific
    issues. The command is expanded in the active context so that variables
    are substituted.
    Args:
      command: the command to run.
      shell: whether to run the command using the shell.
      capture: controls wether the output of the command is captured.
      ignore_dry_run: Normally, if the context is in dry run mode the command is
        printed but not executed. This flag overrides that behaviour, causing
        the command to be run anyway.
      return_status: switches the function to returning the status code rather
        the output.
      ignore_interrupt_signal: Ignore the interrupt signal (i.e., Ctrl-C) while
        the command is running. Useful for letting interactive programs manage
        Ctrl-C by themselves.
    Returns:
      the status if return_status is true, or the output if capture is true,
      otherwise nothing.
    """ # Don't log the trail if we already have
the status if return_status is true, or the output if capture is true,
otherwise nothing.
the status if return_status is true or the output if capture is true otherwise nothing .
self
command
the command to run.
the command to run .
shell
whether to run the command using the shell.
whether to run the command using the shell .
capture
controls wether the output of the command is captured.
controls wether the output of the command is captured .
silent
ignore_dry_run
Normally, if the context is in dry run mode the command is
printed but not executed. This flag overrides that behaviour, causing
the command to be run anyway.
Normally if the context is in dry run mode the command is printed but not executed . This flag overrides that behaviour causing the command to be run anyway .
return_status
switches the function to returning the status code rather
the output.
switches the function to returning the status code rather the output .
ignore_interrupt_signal
Ignore the interrupt signal  while
the command is running. Useful for letting interactive programs manage
Ctrl-C by themselves.
Ignore the interrupt signal while the command is running . Useful for letting interactive programs manage Ctrl - C by themselves .