diff --git a/buildtest/cli/buildspec.py b/buildtest/cli/buildspec.py index f210b4865..bb60c7175 100644 --- a/buildtest/cli/buildspec.py +++ b/buildtest/cli/buildspec.py @@ -592,10 +592,10 @@ def print_buildspecfiles(self, terse=None, header=None): if self.terse: if not self.header: - print("buildspec") + console.print("buildspec", style=self.color) for buildspec in self.cache["buildspecs"].keys(): - print(buildspec) + console.print(f"[{self.color}]{buildspec}") return @@ -623,10 +623,10 @@ def print_tags(self): # if --terse option specified print list of all tags in machine readable format if self.terse: if not self.header: - print("tag") + console.print("tag", style=self.color) for tag in self.cache["unique_tags"]: - print(tag) + console.print(f"[{self.color}]{tag}") return @@ -652,10 +652,10 @@ def print_executors(self): if self.terse: if not self.header: - print("executor") + console.print("executor", style=self.color) for executor in self.cache["unique_executors"]: - print(executor) + console.print(f"[{self.color}]{executor}") return @@ -681,13 +681,15 @@ def print_by_executors(self): if self.terse: if not self.header: - print("executor|name|description") + console.print("executor|name|description", style=self.color) for executor_name in self.cache["executor"].keys(): for test_name, description in self.cache["executor"][ executor_name ].items(): - print(f"{executor_name}|{test_name}|{description}") + console.print( + f"[{self.color}]{executor_name}|{test_name}|{description}" + ) return table = Table(title="Tests by Executors", header_style="blue", show_lines=True) @@ -712,12 +714,11 @@ def print_by_tags(self): if self.terse: if not self.header: - print("tags|name|description") + console.print("tags|name|description", style=self.color) for tagname in self.cache["tags"].keys(): for test_name, description in self.cache["tags"][tagname].items(): - - print(f"{tagname}|{test_name}|{description}") + console.print(f"[{self.color}]{tagname}|{test_name}|{description}") return table = Table(title="Tests by Tags", header_style="blue", show_lines=True) @@ -781,7 +782,7 @@ def print_buildspecs(self, terse=None, header=None, quiet=None): # print terse output if not self.header: - print("|".join(self.table.keys())) + console.print("|".join(self.table.keys()), style=self.color) for row in t: @@ -790,7 +791,8 @@ def print_buildspecs(self, terse=None, header=None, quiet=None): # if any entry contains None type we convert to empty string row = ["" if item is None else item for item in row] - console.print("|".join(row)) + join_string = "|".join(row) + console.print(f"[{self.color}]{join_string}") return @@ -805,21 +807,15 @@ def list_maintainers(self): """Return a list of maintainers""" return self.cache["maintainers"] - def print_maintainer(self, color=None): - """This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command. - - Args: - color (bool, optional): Print table output of ``buildtest buildspec maintainers --list`` with selected color - """ - - consoleColor = checkColor(color) + def print_maintainer(self): + """This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command.""" if self.terse: if not self.header: - print("maintainers") + console.print("maintainers", style=self.color) for maintainer in self.cache["maintainers"]: - print(maintainer) + console.print(f"[{self.color}]{maintainer}") return @@ -827,7 +823,7 @@ def print_maintainer(self, color=None): Column("Maintainers", overflow="fold"), header_style="blue", title_style="red", - row_styles=[consoleColor], + row_styles=[self.color], ) for maintainer in self.cache["maintainers"].keys(): @@ -853,21 +849,15 @@ def print_maintainers_find(self, name): for file in self.cache["maintainers"][name]: console.print(file) - def print_maintainers_by_buildspecs(self, color=None): - """This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown`` - - Args: - color (bool, optional): Print table output of ``buildtest buildspec maintainers --breakdown`` with selected color - """ - - consoleColor = checkColor(color) + def print_maintainers_by_buildspecs(self): + """This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown``.""" if self.terse: if not self.header: - print("maintainers|buildspec") + console.print("maintainers|buildspec", style=self.color) for maintainer, buildspecs in self.cache["maintainers"].items(): - print(f"{maintainer}|{':'.join(buildspecs)}") + console.print(f"[{self.color}]{maintainer}|{':'.join(buildspecs)}") return table = Table( @@ -877,7 +867,7 @@ def print_maintainers_by_buildspecs(self, color=None): header_style="blue", style="cyan", title_style="red", - row_styles=[consoleColor], + row_styles=[self.color], show_lines=True, ) @@ -1299,15 +1289,15 @@ def buildspec_maintainers( name (str, optional): List all buildspecs corresponding to maintainer name. This command is specified via ``buildtest buildspec maintainers find `` """ - consoleColor = checkColor(color) - - cache = BuildspecCache(configuration=configuration, terse=terse, header=header) + cache = BuildspecCache( + configuration=configuration, terse=terse, header=header, color=color + ) if list_maintainers: - cache.print_maintainer(color=consoleColor) + cache.print_maintainer() if breakdown: - cache.print_maintainers_by_buildspecs(color=consoleColor) + cache.print_maintainers_by_buildspecs() if name: cache.print_maintainers_find(name=name) diff --git a/buildtest/cli/history.py b/buildtest/cli/history.py index 8d926ae9a..0fa2ff166 100644 --- a/buildtest/cli/history.py +++ b/buildtest/cli/history.py @@ -102,38 +102,20 @@ def list_build_history(no_header=None, terse=None, pager=None, color=None): if terse: + row_entry = [] + + for key in table.keys(): + row_entry.append(table[key]) + + transpose_list = [list(i) for i in zip(*row_entry)] + # We print the table columns if --no-header is not specified if not no_header: - console.print("|".join(table.keys())) + console.print("|".join(table.keys()), style=consoleColor) - for ( - build_id, - hostname, - user, - system, - date, - pass_test, - fail_tests, - total_tests, - pass_rate, - fail_rate, - command, - ) in zip( - table["id"], - table["hostname"], - table["user"], - table["system"], - table["date"], - table["pass_tests"], - table["fail_tests"], - table["total_tests"], - table["pass_rate"], - table["fail_rate"], - table["command"], - ): - console.print( - f"{build_id}|{hostname}|{user}|{date}|{pass_test}|{fail_tests}|{total_tests}|{pass_rate}|{fail_rate}|{command}" - ) + for row in transpose_list: + line = "|".join(row) + console.print(f"[{consoleColor}]{line}") return history_table = Table( diff --git a/buildtest/cli/report.py b/buildtest/cli/report.py index c82fa7793..2c52dbe3f 100644 --- a/buildtest/cli/report.py +++ b/buildtest/cli/report.py @@ -578,32 +578,33 @@ def print_report( """ consoleColor = checkColor(color) if terse: - join_list = [] + row_entry = [] for key in self.display_table.keys(): - join_list.append(self.display_table[key]) + row_entry.append(self.display_table[key]) - t = [list(i) for i in zip(*join_list)] + transpose_list = [list(i) for i in zip(*row_entry)] # limited number of rows to be printed in terse mode if count: - t = t[:count] + transpose_list = transpose_list[:count] if not noheader: - print("|".join(self.display_table.keys())) + console.print("|".join(self.display_table.keys()), style=consoleColor) - for i in t: - print("|".join(i)) + for row in transpose_list: + line = "|".join(row) + console.print(f"[{consoleColor}]{line}") return - join_list = [] + row_entry = [] title = title or f"Report File: {self.reportfile()}" table = Table(title=title, show_lines=True, expand=True) for field in self.display_table.keys(): table.add_column(field, overflow="fold", style=consoleColor) - join_list.append(self.display_table[field]) - transpose_list = [list(i) for i in zip(*join_list)] + row_entry.append(self.display_table[field]) + transpose_list = [list(i) for i in zip(*row_entry)] # limited number of rows to be printed if count: diff --git a/tests/cli/test_buildspec.py b/tests/cli/test_buildspec.py index 008ce548d..b2b9c389c 100644 --- a/tests/cli/test_buildspec.py +++ b/tests/cli/test_buildspec.py @@ -136,7 +136,12 @@ def test_func_buildspec_find(): @pytest.mark.cli def test_buildspec_find_terse(): - cache = BuildspecCache(configuration=configuration, terse=True, header=False) + cache = BuildspecCache( + configuration=configuration, + terse=True, + header=False, + color=Color.default().name, + ) cache.print_buildspecs() cache.print_tags() cache.print_executors() diff --git a/tests/cli/test_history.py b/tests/cli/test_history.py index b4c1dfa96..395d7029e 100644 --- a/tests/cli/test_history.py +++ b/tests/cli/test_history.py @@ -22,8 +22,10 @@ def test_build_history_list(): # test with pager support: buildtest history list --pager list_build_history(terse=False, no_header=False, pager=True) - # test with terse mode: buildtest history list --terse - list_build_history(terse=True, no_header=False, pager=False) + # test with terse mode and with color: buildtest --color history list --terse + list_build_history( + terse=True, no_header=False, pager=False, color=Color.default().name + ) # test with terse and no header: buildtest history list --terse --no-header list_build_history(terse=True, no_header=True, pager=False) diff --git a/tests/cli/test_report.py b/tests/cli/test_report.py index 7afc0ee88..d5d95a001 100644 --- a/tests/cli/test_report.py +++ b/tests/cli/test_report.py @@ -7,6 +7,7 @@ from buildtest.cli.report import Report, report_cmd, report_summary from buildtest.defaults import BUILD_REPORT, BUILDTEST_REPORTS, BUILDTEST_ROOT from buildtest.exceptions import BuildTestError +from rich.color import Color @pytest.mark.cli @@ -19,8 +20,8 @@ def test_report(): result.print_report() - # run 'buildtest report --format name,state,returncode,buildspec --terse' - result.print_report(terse=True) + # run 'buildtest --color report --format name,state,returncode,buildspec --terse' + result.print_report(terse=True, color=Color.default().name) result.print_report(row_count=True)