Exemplo n.º 1
0
def _eject_confirmation_message():
    info = text.line_wrap(CONFIG.SUPPORT_EJECT_INFO_MESSAGE)
    support_warning = text.line_wrap(
        text.bold('This will opt you out from any obligation for Alces Flight '
                  "Ltd to provide you with support for your Flight {}.".format(
                      config_utils.appliance_name())))
    continue_prompt = text.info('Continue?')

    return text.join_lines(info, support_warning, continue_prompt)
Exemplo n.º 2
0
def _handle_new_temporary_password(login, options, result):
    # Details of user will be output in similar format to find output.
    item_dicts = ipa_utils.parse_find_output(result)
    user_dict = item_dicts[0]  # First and only item.

    if 'Random password' not in user_dict:
        # A new temporary password has not been generated; nothing to handle.
        return

    temporary_password = user_dict['Random password'][0]

    if utils.currently_importing():
        utils.set_imported_user_password(login, temporary_password)
    else:
        message = 'Generated temporary password for user {}: {}'.format(
            login, text.bold(temporary_password)
        )
        click.echo(message)
def list_displayer(headers, data):
    # There should only be exactly one item in the data, and we only want to
    # display that.
    single_item = data[0]

    longest_header_length = len(max(headers, key=len))

    def padding_for(header):
        minimum_gap = 1
        padding_amount = longest_header_length - len(header) + minimum_gap
        return padding_amount * ' '

    def pad_value(header, value):
        padding = padding_for(header)

        header_size = len(header) + 1
        header_offset = header_size * ' '

        value_lines = value.split('\n')

        # Values can be multi-line; the first part just needs to be padded
        # appropriately from the header, but any additional lines need
        # additional padding to line up below this.
        additional_value_lines = len(value_lines) - 1
        additional_line_paddings = \
            [header_offset + padding] * additional_value_lines
        value_line_paddings = [padding] + additional_line_paddings

        padded_value_lines = \
            [''.join(parts) for parts in zip(value_line_paddings, value_lines)]
        return text.join_lines(*padded_value_lines)

    lines = []
    for header, value in zip(headers, single_item):
        line = text.bold(header) + ':' + pad_value(header, value)
        lines.append(line)

    display = text.join_lines(*lines)
    click.echo(display)
def click_run(cli, args, **kwargs):
    runner = CliRunner()
    result = runner.invoke(cli, args, catch_exceptions=False, **kwargs)
    print(text.bold('Command output:'), result.output)
    return result