diff --git a/scripts/code.py b/scripts/code.py index 48e509be..ad9c281f 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -535,6 +535,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -633,7 +637,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -642,6 +649,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -666,24 +674,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -804,7 +814,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -822,8 +832,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1001,10 +1011,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1041,6 +1047,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '--everything', action='store_true', diff --git a/scripts/cov.py b/scripts/cov.py index 8bcc4e00..027e7913 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -396,6 +396,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -494,7 +498,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -503,6 +510,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -527,24 +535,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -665,7 +675,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -683,8 +693,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -964,10 +974,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1004,6 +1010,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '-F', '--source', dest='sources', diff --git a/scripts/csv.py b/scripts/csv.py index a540ec3a..f4e3a06c 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1486,6 +1486,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -1584,7 +1588,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -1593,6 +1600,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -1617,24 +1625,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -1755,7 +1765,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -1773,8 +1783,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1956,10 +1966,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -2021,6 +2027,26 @@ if __name__ == "__main__": const=(None, None), help="Sort by this field, but backwards. Can include an expression " "of the form field=expr.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") sys.exit(main(**{k: v for k, v in vars(parser.parse_intermixed_args()).items() if v is not None})) diff --git a/scripts/ctx.py b/scripts/ctx.py index e5ba9f1d..b2d471c4 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -735,6 +735,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -833,7 +837,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -842,6 +849,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -866,24 +874,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -1004,7 +1014,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -1022,8 +1032,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1209,10 +1219,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1249,6 +1255,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '--everything', action='store_true', diff --git a/scripts/data.py b/scripts/data.py index d7673c4d..ef5a95de 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -535,6 +535,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -633,7 +637,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -642,6 +649,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -666,24 +674,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -804,7 +814,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -822,8 +832,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -998,10 +1008,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1038,6 +1044,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '--everything', action='store_true', diff --git a/scripts/perf.py b/scripts/perf.py index 726f6406..4d2ec758 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -850,6 +850,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -948,7 +952,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -957,6 +964,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -981,24 +989,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -1119,7 +1129,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -1137,8 +1147,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1461,10 +1471,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1501,6 +1507,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '-F', '--source', dest='sources', diff --git a/scripts/perfbd.py b/scripts/perfbd.py index c8dfbd4a..c6f20407 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -820,6 +820,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -918,7 +922,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -927,6 +934,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -951,24 +959,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -1089,7 +1099,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -1107,8 +1117,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1463,10 +1473,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1503,6 +1509,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '-F', '--source', dest='sources', diff --git a/scripts/stack.py b/scripts/stack.py index 518e391f..bfe63a04 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -484,6 +484,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -582,7 +586,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -591,6 +598,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -615,24 +623,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -753,7 +763,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -771,8 +781,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -961,10 +971,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1001,6 +1007,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '--everything', action='store_true', diff --git a/scripts/structs.py b/scripts/structs.py index fd9b4ab0..15c7c434 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -553,6 +553,10 @@ def table(Result, results, diff_results=None, *, percent=None, all=False, compare=None, + no_header=False, + small_header=False, + no_total=False, + small_table=False, summary=False, depth=1, hot=None, @@ -651,7 +655,10 @@ def table(Result, results, diff_results=None, *, if compare: names.sort( key=lambda n: ( + # move compare entry to the top, note this can be + # overridden by explicitly sorting by fields table.get(n) == compare_result, + # sort by ratio if comparing tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -660,6 +667,7 @@ def table(Result, results, diff_results=None, *, reverse=True) if diff or percent: names.sort( + # sort by ratio if diffing key=lambda n: tuple( types[k].ratio( getattr(table.get(n), k, None), @@ -684,24 +692,26 @@ def table(Result, results, diff_results=None, *, lines = [] # header - header = ['%s%s' % ( - ','.join(by), - ' (%d added, %d removed)' % ( - sum(1 for n in table if n not in diff_table), - sum(1 for n in diff_table if n not in table)) - if diff else '') - if not summary else ''] - if not diff: - for k in fields: - header.append(k) - else: - for k in fields: - header.append('o'+k) - for k in fields: - header.append('n'+k) - for k in fields: - header.append('d'+k) - lines.append(header) + if not no_header: + header = ['%s%s' % ( + ','.join(by), + ' (%d added, %d removed)' % ( + sum(1 for n in table if n not in diff_table), + sum(1 for n in diff_table if n not in table)) + if diff else '') + if not small_header and not small_table and not summary + else ''] + if not diff: + for k in fields: + header.append(k) + else: + for k in fields: + header.append('o'+k) + for k in fields: + header.append('n'+k) + for k in fields: + header.append('d'+k) + lines.append(header) # entry helper def table_entry(name, r, diff_r=None): @@ -822,7 +832,7 @@ def table(Result, results, diff_results=None, *, prefixes[2+is_last] + " ")) # entries - if (not summary) or compare: + if not summary: for name in names: r = table.get(name) if diff_results is None: @@ -840,8 +850,8 @@ def table(Result, results, diff_results=None, *, "| ", " ")) - # total, unless we're comparing - if not (compare and not percent and not diff): + # total + if not no_total and not (small_table and not summary): r = next(iter(fold(Result, results, by=[])), None) if diff_results is None: diff_r = None @@ -1027,10 +1037,6 @@ if __name__ == "__main__": '-c', '--compare', type=lambda x: tuple(v.strip() for v in x.split(',')), help="Compare results to the row matching this by pattern.") - parser.add_argument( - '-Y', '--summary', - action='store_true', - help="Only show the total.") parser.add_argument( '-b', '--by', action='append', @@ -1067,6 +1073,26 @@ if __name__ == "__main__": nargs='?', action=AppendSort, help="Sort by this field, but backwards.") + parser.add_argument( + '--no-header', + action='store_true', + help="Don't show the header.") + parser.add_argument( + '--small-header', + action='store_true', + help="Don't show by field names.") + parser.add_argument( + '--no-total', + action='store_true', + help="Don't show the total.") + parser.add_argument( + '-Q', '--small-table', + action='store_true', + help="Equivalent to --small-header + --no-total.") + parser.add_argument( + '-Y', '--summary', + action='store_true', + help="Only show the total.") parser.add_argument( '--everything', action='store_true',