def apply_colour_choice(self, requested): """Heuristics to work out whether the user wants colour output, from a --color=yes|no|auto option. This alters the ANSI 16 bit colour "constants" in the colour module to be either real colours or empty strings. """ requested = requested.lower() if requested == 'no': colour.switch_colour_off() elif requested == 'yes': colour.switch_colour_on() elif requested == 'auto': if (hasattr(self.outf, 'isatty') and self.outf.isatty()): colour.switch_colour_on() else: colour.switch_colour_off() else: raise CommandError("Unknown --color option: %s " "please choose from yes, no, auto")
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import subprocess import os import sys from collections import Counter from samba.colour import c_RED, c_GREEN, c_DARK_YELLOW, switch_colour_off import re import unicodedata as u from samba.tests import TestCase if not sys.stdout.isatty(): switch_colour_off() def _find_root(): try: p = subprocess.run(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) except subprocess.SubprocessError as e: print(c_RED(f"Error running git (is this a git tree?): {e}")) print("This test is only useful in a git working tree") sys.exit(1) root = p.stdout.decode().strip()