<commit_before># coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import logging

from pants.binaries import binary_util
from pants.reporting.reporting_server import ReportingServerManager
from pants.task.task import QuietTaskMixin, Task


logger = logging.getLogger(__name__)


class ReportingServerRun(QuietTaskMixin, Task):
  """Run the reporting server."""

  @classmethod
  def register_options(cls, register):
    super(ReportingServerRun, cls).register_options(register)
    register('--port', type=int, default=0,
             help='Serve on this port. Leave unset to choose a free port '
                  'automatically (recommended if using pants concurrently in '
                  'multiple workspaces on the same host).')
    register('--allowed-clients', type=list, default=['127.0.0.1'],
             help='Only requests from these IPs may access this server. Useful for '
                  'temporarily showing build results to a colleague. The special '
                  'value ALL means any client may connect. Use with caution, as '
                  'your source code is exposed to all allowed clients!')
    register('--open', type=bool,
             help='Attempt to open the server web ui in a browser.')
    register('--template-dir', advanced=True,
             help='Use templates from this dir instead of the defaults.')
    register('--assets-dir', advanced=True,
             help='Use assets from this dir instead of the defaults.')

  def _maybe_open(self, port):
    if self.get_options().open:
      binary_util.ui_open('http://localhost:{port}'.format(port=port))

  def execute(self):
    manager = ReportingServerManager(self.context, self.get_options())

    if manager.is_alive():
      logger.info('Server already running with pid {pid} at http://localhost:{port}'
                  .format(pid=manager.pid, port=manager.socket))
    else:
      manager.daemonize()
      manager.await_socket(10)

      logger.info('Launched server with pid {pid} at http://localhost:{port}'
                  .format(pid=manager.pid, port=manager.socket))
      logger.info('To kill, run ./pants killserver')

    self._maybe_open(manager.socket)<commit_msg>logs kill server info when creating server<commit_after># coding=utf-8
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import logging

from pants.binaries import binary_util
from pants.reporting.reporting_server import ReportingServerManager
from pants.task.task import QuietTaskMixin, Task


logger = logging.getLogger(__name__)


class ReportingServerRun(QuietTaskMixin, Task):
  """Run the reporting server."""

  @classmethod
  def register_options(cls, register):
    super(ReportingServerRun, cls).register_options(register)
    register('--port', type=int, default=0,
             help='Serve on this port. Leave unset to choose a free port '
                  'automatically (recommended if using pants concurrently in '
                  'multiple workspaces on the same host).')
    register('--allowed-clients', type=list, default=['127.0.0.1'],
             help='Only requests from these IPs may access this server. Useful for '
                  'temporarily showing build results to a colleague. The special '
                  'value ALL means any client may connect. Use with caution, as '
                  'your source code is exposed to all allowed clients!')
    register('--open', type=bool,
             help='Attempt to open the server web ui in a browser.')
    register('--template-dir', advanced=True,
             help='Use templates from this dir instead of the defaults.')
    register('--assets-dir', advanced=True,
             help='Use assets from this dir instead of the defaults.')

  def _maybe_open(self, port):
    if self.get_options().open:
      binary_util.ui_open('http://localhost:{port}'.format(port=port))

  def execute(self):
    manager = ReportingServerManager(self.context, self.get_options())

    if manager.is_alive():
      logger.info('Server already running with pid {pid} at http://localhost:{port}'
                  .format(pid=manager.pid, port=manager.socket))
    else:
      manager.daemonize()
      manager.await_socket(10)

      logger.info('Launched server with pid {pid} at http://localhost:{port}'
                  .format(pid=manager.pid, port=manager.socket))
      logger.info('To kill, run `./pants killserver`')

    self._maybe_open(manager.socket)
{'fraction_non_alphanumeric': 0.10373698182560752, 'fraction_numerical': 0.006534613028384725, 'mean_word_length': 3.098744769874477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930250', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1275, 'n_words': 411}