示例#1
0
def dispatch():
    setup_logging()
    dispatcher = DocoptDispatcher(Base, {
        'options_first': True,
        'version': VERSION
    })

    options, handler, command_options = dispatcher.parse(sys.argv[1:])
    setup_console_handler(console_handler, options.get('--verbose'),
                          options.get('--no-ansi'), options.get("--log-level"))
    setup_parallel_logger(options.get('--no-ansi'))
    if options.get('--no-ansi'):
        command_options['--no-color'] = True
    return functools.partial(perform_command, options, handler,
                             command_options)
示例#2
0
def apiDispatch(args):
    """
    Does the same thing as the dispatch function in compose.cli.main.py but instead
    of using os.argv it uses a the passed args array. Also does not catch any
    exceptions so they can be caught programatically.
    params:
        args: Array of argument strings.
    """
    setup_logging()
    dispatcher = dp.DocoptDispatcher(TopLevelCommand, {
        'options_first': True,
        'version': get_version_info('compose')
    })
    # Don't handle argument exceptions here, let them be caught outside of the apiDispatch.
    options, handler, command_options = dispatcher.parse(args)
    setup_console_handler(console_handler, options.get('--verbose'))
    return functools.partial(perform_command, options, handler,
                             command_options)
示例#3
0
def _call_docker_compose(command: str, args: Iterable[str]):
    if not COMPOSE_INSTALLED:
        click.secho(
            "docker-compose not found! install it by using `pip install nb-cli[deploy]`",
            fg="red")
        return
    console_stream = sys.stderr
    console_handler = logging.StreamHandler(console_stream)
    dispatcher = DocoptDispatcher(TopLevelCommand, {"options_first": True})
    options, handler, command_options = dispatcher.parse([command, *args])
    ansi_mode = AnsiMode.AUTO
    setup_console_handler(logging.StreamHandler(sys.stderr),
                          options.get('--verbose'),
                          ansi_mode.use_ansi_codes(console_handler.stream),
                          options.get("--log-level"))
    setup_parallel_logger(ansi_mode)
    if ansi_mode is AnsiMode.NEVER:
        command_options['--no-color'] = True
    return perform_command(options, handler, command_options)
示例#4
0
 def test_with_not_a_tty(self, logging_handler):
     logging_handler.stream.isatty.return_value = False
     setup_console_handler(logging_handler, False)
     assert type(logging_handler.formatter) == logging.Formatter
示例#5
0
 def test_with_tty_not_verbose(self, logging_handler):
     setup_console_handler(logging_handler, False)
     assert type(logging_handler.formatter) == ConsoleWarningFormatter
     assert '%(name)s' not in logging_handler.formatter._fmt
     assert '%(funcName)s' not in logging_handler.formatter._fmt
示例#6
0
 def test_with_not_a_tty(self):
     self.stream.isatty.return_value = False
     setup_console_handler(self.handler, False)
     assert type(self.handler.formatter) == logging.Formatter
示例#7
0
 def test_with_tty_not_verbose(self):
     setup_console_handler(self.handler, False)
     assert type(self.handler.formatter) == ConsoleWarningFormatter
     assert '%(name)s' not in self.handler.formatter._fmt
     assert '%(funcName)s' not in self.handler.formatter._fmt
示例#8
0
 def test_with_tty_verbose(self):
     setup_console_handler(self.handler, True)
     assert type(self.handler.formatter) == ConsoleWarningFormatter
     assert '%(name)s' in self.handler.formatter._fmt
     assert '%(funcName)s' in self.handler.formatter._fmt
示例#9
0
 def test_with_tty_verbose(self, logging_handler):
     setup_console_handler(logging_handler, True)
     assert type(logging_handler.formatter) == ConsoleWarningFormatter
     assert '%(name)s' in logging_handler.formatter._fmt
     assert '%(funcName)s' in logging_handler.formatter._fmt
示例#10
0
 def test_without_console_formatter(self, logging_handler):
     setup_console_handler(logging_handler,
                           False,
                           use_console_formatter=False)
     assert type(logging_handler.formatter) == logging.Formatter