Beispiel #1
0
    def _connect_and_execute(self, port):
        # Merge the nailgun TTY capability environment variables with the passed environment dict.
        ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout,
                                               self._stderr)
        modified_env = combined_dict(self._env, ng_env)
        modified_env['PANTSD_RUNTRACKER_CLIENT_START_TIME'] = str(
            self._start_time)

        assert isinstance(port, int), 'port {} is not an integer!'.format(port)

        # Instantiate a NailgunClient.
        client = NailgunClient(port=port,
                               ins=self._stdin,
                               out=self._stdout,
                               err=self._stderr,
                               exit_on_broken_pipe=True,
                               expects_pid=True)

        with self._trapped_signals(client), STTYSettings.preserved():
            # Execute the command on the pailgun.
            result = client.execute(self.PANTS_COMMAND, *self._args,
                                    **modified_env)

        # Exit.
        self._exiter.exit(result)
    def _connect_and_execute(self, pantsd_handle):
        port = pantsd_handle.port
        # Merge the nailgun TTY capability environment variables with the passed environment dict.
        ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout,
                                               self._stderr)
        modified_env = combined_dict(self._env, ng_env)
        modified_env['PANTSD_RUNTRACKER_CLIENT_START_TIME'] = str(
            self._start_time)
        modified_env['PANTSD_REQUEST_TIMEOUT_LIMIT'] = str(
            self._bootstrap_options.for_global_scope(
            ).pantsd_timeout_when_multiple_invocations)

        assert isinstance(port, int), \
          'port {} is not an integer! It has type {}.'.format(port, type(port))

        # Instantiate a NailgunClient.
        client = NailgunClient(
            port=port,
            ins=self._stdin,
            out=self._stdout,
            err=self._stderr,
            exit_on_broken_pipe=True,
            metadata_base_dir=pantsd_handle.metadata_base_dir)

        with self._trapped_signals(client), STTYSettings.preserved():
            # Execute the command on the pailgun.
            result = client.execute(self.PANTS_COMMAND, *self._args,
                                    **modified_env)

        # Exit.
        self._exiter.exit(result)
    def test_isatty_to_env_without_tty(self):
        mock_stdin = self._make_mock_stream(False, 0)
        mock_stdout = self._make_mock_stream(False, 1)
        mock_stderr = self._make_mock_stream(False, 2)

        self.assertEqual(
            NailgunProtocol.isatty_to_env(mock_stdin, mock_stdout, mock_stderr),
            {"NAILGUN_TTY_0": b"0", "NAILGUN_TTY_1": b"0", "NAILGUN_TTY_2": b"0",},
        )
    def test_isatty_to_env_without_tty(self):
        mock_stdin = self._make_mock_stream(False, 0)
        mock_stdout = self._make_mock_stream(False, 1)
        mock_stderr = self._make_mock_stream(False, 2)

        self.assertEqual(
            NailgunProtocol.isatty_to_env(mock_stdin, mock_stdout,
                                          mock_stderr), {
                                              'NAILGUN_TTY_0': b'0',
                                              'NAILGUN_TTY_1': b'0',
                                              'NAILGUN_TTY_2': b'0',
                                          })
  def test_isatty_to_env_without_tty(self):
    mock_stdin = self._make_mock_stream(False, 0)
    mock_stdout = self._make_mock_stream(False, 1)
    mock_stderr = self._make_mock_stream(False, 2)

    self.assertEqual(
      NailgunProtocol.isatty_to_env(mock_stdin, mock_stdout, mock_stderr),
      {
        'NAILGUN_TTY_0': b'0',
        'NAILGUN_TTY_1': b'0',
        'NAILGUN_TTY_2': b'0',
      })
Beispiel #6
0
  def run(self, args=None):
    # Merge the nailgun TTY capability environment variables with the passed environment dict.
    ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout, self._stderr)
    modified_env = self._combine_dicts(self._env, ng_env)

    # Instantiate a NailgunClient.
    client = NailgunClient(port=self._port, ins=self._stdin, out=self._stdout, err=self._stderr)

    with self._trapped_control_c(client):
      # Execute the command on the pailgun.
      result = client.execute(self.PANTS_COMMAND, *self._args, **modified_env)

    # Exit.
    self._exiter.exit(result)
Beispiel #7
0
  def test_isatty_to_env_with_mock_tty(self, mock_ttyname):
    mock_ttyname.return_value = self._fake_ttyname
    mock_stdin = self._make_mock_stream(True, 0)
    mock_stdout = self._make_mock_stream(True, 1)
    mock_stderr = self._make_mock_stream(True, 2)

    self.assertEqual(
      NailgunProtocol.isatty_to_env(mock_stdin, mock_stdout, mock_stderr),
      {
        'NAILGUN_TTY_0': b'1',
        'NAILGUN_TTY_1': b'1',
        'NAILGUN_TTY_2': b'1',
        'NAILGUN_TTY_PATH_0': self._fake_ttyname,
        'NAILGUN_TTY_PATH_1': self._fake_ttyname,
        'NAILGUN_TTY_PATH_2': self._fake_ttyname,
      })
Beispiel #8
0
  def run(self, args=None):
    # Merge the nailgun TTY capability environment variables with the passed environment dict.
    ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout, self._stderr)
    modified_env = self._combine_dicts(self._env, ng_env)

    # Instantiate a NailgunClient.
    client = NailgunClient(port=self._port,
                           ins=self._stdin,
                           out=self._stdout,
                           err=self._stderr,
                           exit_on_broken_pipe=True)

    with self._trapped_control_c(client):
      # Execute the command on the pailgun.
      result = client.execute(self.PANTS_COMMAND, *self._args, **modified_env)

    # Exit.
    self._exiter.exit(result)
Beispiel #9
0
  def _connect_and_execute(self, port):
    # Merge the nailgun TTY capability environment variables with the passed environment dict.
    ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout, self._stderr)
    modified_env = combined_dict(self._env, ng_env)

    assert isinstance(port, int), 'port {} is not an integer!'.format(port)

    # Instantiate a NailgunClient.
    client = NailgunClient(port=port,
                           ins=self._stdin,
                           out=self._stdout,
                           err=self._stderr,
                           exit_on_broken_pipe=True)

    with self._trapped_control_c(client):
      # Execute the command on the pailgun.
      result = client.execute(self.PANTS_COMMAND, *self._args, **modified_env)

    # Exit.
    self._exiter.exit(result)
Beispiel #10
0
  def _connect_and_execute(self, port):
    # Merge the nailgun TTY capability environment variables with the passed environment dict.
    ng_env = NailgunProtocol.isatty_to_env(self._stdin, self._stdout, self._stderr)
    modified_env = combined_dict(self._env, ng_env)

    assert isinstance(port, int), 'port {} is not an integer!'.format(port)

    # Instantiate a NailgunClient.
    client = NailgunClient(port=port,
                           ins=self._stdin,
                           out=self._stdout,
                           err=self._stderr,
                           exit_on_broken_pipe=True)

    with self._trapped_signals(client), STTYSettings.preserved():
      # Execute the command on the pailgun.
      result = client.execute(self.PANTS_COMMAND, *self._args, **modified_env)

    # Exit.
    self._exiter.exit(result)