10 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
24 from ctypes import windll, byref
25 from ctypes.wintypes import DWORD
27 kernel = windll.kernel32
28 stdout = kernel.GetStdHandle(-11)
30 if not kernel.GetConsoleMode(stdout, byref(mode)):
32 # Try setting ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
33 # If that fails (returns 0), we disable colors
34 return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
38 if not os.isatty(sys.stdout.fileno()):
40 if platform.system().lower() == 'windows':
41 return cls._windows_ansi()
42 return os.environ.get('TERM') != 'dumb'
58 cls.HEADER = '\033[95m'
59 cls.OKBLUE = '\033[94m'
60 cls.OKGREEN = '\033[92m'
61 cls.WARNING = '\033[93m'
67 def git(*args, repository_path='.'):
68 return subprocess.check_output(["git"] + list(args), cwd=repository_path,
69 stdin=subprocess.DEVNULL,
70 stderr=subprocess.STDOUT).decode()
72 def accept_command(commands):
73 """Search @commands and returns the first found absolute path."""
74 for command in commands:
75 command = shutil.which(command)
81 meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
82 if os.path.exists(meson):
83 return [sys.executable, meson]
85 mesonintrospect = os.environ.get('MESONINTROSPECT', '')
86 for comp in shlex.split (mesonintrospect):
87 # mesonintrospect might look like "/usr/bin/python /somewhere/meson introspect",
88 # let's not get tricked
89 if 'python' in os.path.basename (comp):
91 if os.path.exists(comp):
92 if comp.endswith('.py'):
93 return [sys.executable, comp]
97 meson = accept_command(['meson.py'])
99 return [sys.executable, meson]
100 meson = accept_command(['meson'])
103 raise RuntimeError('Could not find Meson')