当前位置: 首页>>代码示例>>Python>>正文


Python AsciiTable.column_max_width方法代码示例

本文整理汇总了Python中terminaltables.AsciiTable.column_max_width方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiTable.column_max_width方法的具体用法?Python AsciiTable.column_max_width怎么用?Python AsciiTable.column_max_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在terminaltables.AsciiTable的用法示例。


在下文中一共展示了AsciiTable.column_max_width方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: table

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
def table(header, rows):
    if not HAVE_TERMTAB:
        print_error("Missing dependency, install terminaltables (`pip install terminaltables`)")
        return

    # TODO: Refactor this function, it is some serious ugly code.

    content = [header] + rows
    # Make sure everything is string
    try:
        content = [[a.replace('\t', '  ') for a in list(map(unicode, l))] for l in content]
    except:
        # Python3 way of doing it:
        content = [[a.replace('\t', '  ') for a in list(map(str, l))] for l in content]
    t = AsciiTable(content)
    if not t.ok:
        longest_col = t.column_widths.index(max(t.column_widths))
        max_length_col = t.column_max_width(longest_col)
        if max_length_col > 0:
            for i, content in enumerate(t.table_data):
                if len(content[longest_col]) > max_length_col:
                    temp = ''
                    for l in content[longest_col].splitlines():
                        if len(l) > max_length_col:
                            temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
                        else:
                            temp += l + '\n'
                        content[longest_col] = temp.strip()
                t.table_data[i] = content

    return t.table
开发者ID:chubbymaggie,项目名称:viper,代码行数:33,代码来源:out.py

示例2: output

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
def output(buf, dowrap=False):
    bbuf = [["Bot", "Pack#", "Size", "File"]] + buf
    t = AsciiTable(bbuf)
    t.inner_column_border = False
    t.outer_border = False
    if dowrap and sys.stdout.isatty():
        mw = t.column_max_width(3)
        for e in bbuf:
            if len(e[3])>mw:
                e[3] = "\n".join(wrap(e[3], mw))
    print(t.table)
    sys.stdout.flush()
开发者ID:2ion,项目名称:nibl,代码行数:14,代码来源:nibl.py

示例3: print_overview_errors

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
def print_overview_errors(errors):
    print("Errors: %s" % len(errors))

    for error in errors:
        table_data = [
            ['Feature', 'Step', 'Line', 'Error message'],
            [error.filename, error.name, str(error.line), '']
        ]
        table = AsciiTable(table_data)
        error_message_max_width = table.column_max_width(3)
        w = textwrap.TextWrapper(width=error_message_max_width, break_long_words=False,replace_whitespace=False)
        wrapped_string = '\n'.join(w.wrap(error.error_message))
        print(wrapped_string)
        table.table_data[1][3] = wrapped_string
        print(table.table)
开发者ID:eoaksnes,项目名称:introduction-to-elasticsearch,代码行数:17,代码来源:results.py

示例4: PrintThing

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
def PrintThing(ret_cmd):
	if not options.printer:
		print "++++++++++++++++++++++++++++++"
		print "Command ID : "+str(ret_cmd[0])
		print "Command    : "+str(ret_cmd[1])+'\n'
		print "Comment    : "+str(ret_cmd[2])
		print "Tags       : "+str(ret_cmd[5])
		print "Date Added : "+str(ret_cmd[3])
		print "Added By   : "+str(ret_cmd[4])
		print "References\n__________\n"+str(ret_cmd[6].replace(',', '\n'))
		print "++++++++++++++++++++++++++++++\n"
	elif options.printer is 'p':
		print "++++++++++++++++++++++++++++++"
		print str(ret_cmd[1])+'\n'
		print str(ret_cmd[2])
		print "++++++++++++++++++++++++++++++\n"
	elif options.printer is 'd':
		print str(ret_cmd[1])
		print str(ret_cmd[2])
		print str(ret_cmd[4])
		print 'EOC'
		print str(ret_cmd[5].replace(',', '\n'))
		print 'EOT'
		print str(ret_cmd[6].replace(',', '\n'))
		print 'EOR'
	elif options.printer is 'w':
		print "= "+str(ret_cmd[2])+" = "
		print " "+str(ret_cmd[1])
		print str(ret_cmd[5].replace(',', ', '))
		print str(ret_cmd[6].replace(',', '\n'))
	elif options.printer is 'P':
		table_data = [\
			["Added By " + str(ret_cmd[4]), "Cmd ID : " + str(ret_cmd[0])],
			["Command ", str(ret_cmd[1])],
			["Comment  ", str(ret_cmd[2])],
			["Tags  ", str(ret_cmd[5]).replace(',', '\n')],
			["Date added", str(ret_cmd[3])],
			["References", str(ret_cmd[6]).replace(',', '\n')]\
			]
		table = AsciiTable(table_data)
		max_width = table.column_max_width(1)
		wrapped_string = '\n'.join(wrap(str(ret_cmd[1]), max_width))+"\n"
		table.table_data[1][1] = wrapped_string
		print table.table
	else:
		err("Please seek help")
开发者ID:silverlak3,项目名称:rtfm,代码行数:48,代码来源:rtfm.py

示例5: table

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
def table(header, rows):
    if not HAVE_TERMTAB:
        print_error("Missing dependency, install terminaltables (`pip install terminaltables`)")
        return

    # TODO: Refactor this function, it is some serious ugly code.

    content = []
    for l in [header] + rows:
        to_append = []
        for a in l:
            if isinstance(a, bytes):
                if sys.version_info < (3, 4):
                    a = a.decode('utf-8', 'ignore')
                else:
                    a = a.decode('utf-8', 'backslashreplace')
            if not isinstance(a, six.text_type):
                a = six.text_type(a)
            to_append.append(a.replace('\t', '  ').replace('\v', '\\v'))
        content.append(to_append)
    t = AsciiTable(content)
    if not t.ok:
        t.inner_row_border = True
        longest_col = t.column_widths.index(max(t.column_widths))
        max_length_col = t.column_max_width(longest_col)
        if max_length_col > 0:
            for i, content in enumerate(t.table_data):
                if len(content[longest_col]) > max_length_col:
                    temp = ''
                    for l in content[longest_col].splitlines():
                        if len(l) > max_length_col:
                            temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
                        else:
                            temp += l + '\n'
                        content[longest_col] = temp.strip()
                t.table_data[i] = content

    return t.table
开发者ID:kevthehermit,项目名称:viper,代码行数:40,代码来源:out.py

示例6: printable_summary

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]

#.........这里部分代码省略.........
    number_of_tests_failed:  Number of tests failed.
    exit_code:               Build exit code: 0 or 1.

    Returns
    -------
    Formatted build summary string.
    """

    header = """
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +                                                                         +
    +        N E S T   T r a v i s   C I   B u i l d   S u m m a r y          +
    +                                                                         +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    \n\n"""

    build_summary = header

    if get_num_msgs(summary_vera) > 0 or \
       get_num_msgs(summary_cppcheck) > 0 or \
       get_num_msgs(summary_format) > 0 or \
       get_num_msgs(summary_pep8) > 0:

        build_summary += '  S T A T I C   C O D E   A N A L Y S I S\n'

        # Create formatted per-file-tables of VERA++, Cppcheck, clang-format
        # and PEP8 messages.
        build_summary += code_analysis_per_file_tables(summary_vera,
                                                       summary_cppcheck,
                                                       summary_format,
                                                       summary_pep8)

    if number_of_warnings > 0:
        build_summary += '\n  W A R N I N G S\n'
        build_summary += warnings_table(summary_warnings)

    if number_of_errors > 0:
        build_summary += '\n  E R R O R S\n'
        build_summary += errors_table(summary_errors)

    build_summary += '\n\n  B U I L D   R E P O R T\n'

    summary_table = [
        ['Changed Files :', ''],
        ['', 'No files have been changed.'],
        ['Static Code Analysis :', ''],
        ['VERA++',
         convert_summary_to_status_string(summary_vera, ignore_vera) +
         '\n' + '\nNumber of messages (MSGBLD0135): ' +
         str(get_num_msgs(summary_vera))],
        ['Cppcheck',
         convert_summary_to_status_string(summary_cppcheck, ignore_cppcheck) +
         '\n' + '\nNumber of messages (MSGBLD0155): ' +
         str(get_num_msgs(summary_cppcheck))],
        ['clang-format',
         convert_summary_to_status_string(summary_format, ignore_format) +
         '\n' + '\nNumber of messages (MSGBLD0175): ' +
         str(get_num_msgs(summary_format))],
        ['PEP8',
         convert_summary_to_status_string(summary_pep8, ignore_pep8) +
         '\n' + '\nNumber of messages (MSGBLD0195): ' +
         str(get_num_msgs(summary_pep8))],
        ['NEST Build :', ''],
        ['CMake configure',
         convert_bool_value_to_status_string(status_cmake_configure)],
        ['Make', convert_bool_value_to_status_string(status_make) + '\n' +
         '\nErrors  : ' + str(number_of_errors) +
         '\nWarnings: ' + str(number_of_warnings)],
        ['Make install',
         convert_bool_value_to_status_string(status_make_install)],
        ['Make installcheck',
         convert_bool_value_to_status_string(status_tests) + '\n' +
         '\nTotal number of tests : ' + str(number_of_tests_total) +
         '\nNumber of tests failed: ' + str(number_of_tests_failed)],
        ['Artifacts :', ''],
        ['Amazon S3 upload',
         convert_bool_value_to_yes_no_string(status_amazon_s3_upload)]
    ]
    table = AsciiTable(summary_table)
    table.inner_row_border = True
    max_width = table.column_max_width(1)

    # Bypass Travis issue:  ValueError: invalid width -29 (must be > 0)
    #                       (in the wrap() below max_width must be > 0)
    # The calculation of column_max_width is based on the returned terminal
    # width which sometimes seems to be zero resulting in a negative value.
    if max_width < 0:
        max_width = 70

    table.table_data[1][1] = '\n'.join(wrap(', '.join(list_of_changed_files),
                                            max_width))

    build_summary += table.table + '\n'

    if exit_code == 0:
        build_summary += '\nBUILD TERMINATED SUCCESSFULLY'
    else:
        build_summary += '\nBUILD FAILED'

    return build_summary
开发者ID:apeyser,项目名称:nest-simulator,代码行数:104,代码来源:parse_travis_log.py

示例7: str

# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import column_max_width [as 别名]
                                    printarray3.append([curr_queue, "Stuck or idle, restarting in " + str(abs(args.treshold - (int(time.time()) - no_info_modules[curr_queue]))) + "s"])
                                else:
                                    printarray3.append([curr_queue, "Stuck or idle, restarting disabled"])

                ## FIXME To add:
                ## Button KILL Process using  Curses

                printarray1.sort(key=lambda x: x[0][9:], reverse=False)
                printarray2.sort(key=lambda x: x[0][9:], reverse=False)
                printarray1.insert(0,["Queue", "PID", "Amount", "Paste start time", "Processing time for current paste (H:M:S)", "Paste hash"])
                printarray2.insert(0,["Queue", "PID","Amount", "Paste start time", "Time since idle (H:M:S)", "Last paste hash"])
                printarray3.insert(0,["Queue", "State"])

                os.system('clear')
                t1 = AsciiTable(printarray1, title="Working queues")
                t1.column_max_width(1)
                if not t1.ok:
                        longest_col = t1.column_widths.index(max(t1.column_widths))
                        max_length_col = t1.column_max_width(longest_col)
                        if max_length_col > 0:
                            for i, content in enumerate(t1.table_data):
                                if len(content[longest_col]) > max_length_col:
                                    temp = ''
                                    for l in content[longest_col].splitlines():
                                        if len(l) > max_length_col:
                                            temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
                                        else:
                                            temp += l + '\n'
                                        content[longest_col] = temp.strip()
                                t1.table_data[i] = content
开发者ID:CIRCL,项目名称:AIL-framework,代码行数:32,代码来源:ModuleInformation.py


注:本文中的terminaltables.AsciiTable.column_max_width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。