10 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
15 from ctypes import wintypes
16 _GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
17 _GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]
18 _GetShortPathNameW.restype = wintypes.DWORD
20 def win32_get_short_path_name(long_name):
22 Gets the short path name of a given long path.
23 http://stackoverflow.com/a/23598461/200291
27 output_buf = ctypes.create_unicode_buffer(output_buf_size)
28 needed = _GetShortPathNameW(long_name, output_buf, output_buf_size)
29 if output_buf_size >= needed:
30 return output_buf.value
32 output_buf_size = needed
45 from ctypes import windll, byref
46 from ctypes.wintypes import DWORD
48 kernel = windll.kernel32
49 stdout = kernel.GetStdHandle(-11)
51 if not kernel.GetConsoleMode(stdout, byref(mode)):
53 # Try setting ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
54 # If that fails (returns 0), we disable colors
55 return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
59 if not os.isatty(sys.stdout.fileno()):
61 if platform.system().lower() == 'windows':
62 return cls._windows_ansi()
63 return os.environ.get('TERM') != 'dumb'
79 cls.HEADER = '\033[95m'
80 cls.OKBLUE = '\033[94m'
81 cls.OKGREEN = '\033[92m'
82 cls.WARNING = '\033[93m'
88 def git(*args, repository_path='.'):
89 return subprocess.check_output(["git"] + list(args), cwd=repository_path,
90 stdin=subprocess.DEVNULL,
91 stderr=subprocess.STDOUT).decode()
93 def accept_command(commands):
94 """Search @commands and returns the first found absolute path."""
95 for command in commands:
96 command = shutil.which(command)
102 meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
103 if os.path.exists(meson):
104 return [sys.executable, meson]
106 mesonintrospect = os.environ.get('MESONINTROSPECT', '')
107 for comp in shlex.split (mesonintrospect):
108 # mesonintrospect might look like "/usr/bin/python /somewhere/meson introspect",
109 # let's not get tricked
110 if 'python' in os.path.basename (comp):
112 if os.path.exists(comp):
113 if comp.endswith('.py'):
114 return [sys.executable, comp]
118 meson = accept_command(['meson.py'])
120 return [sys.executable, meson]
121 meson = accept_command(['meson'])
124 raise RuntimeError('Could not find Meson')