msys2: Fix special lib names regexes and add some necessary ones
[platform/upstream/gstreamer.git] / common.py
1 import argparse
2 import os
3 import shutil
4 import subprocess
5
6
7 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
8
9
10 class Colors:
11     HEADER = '\033[95m'
12     OKBLUE = '\033[94m'
13     OKGREEN = '\033[92m'
14     WARNING = '\033[93m'
15     FAIL = '\033[91m'
16     ENDC = '\033[0m'
17
18     force_disable = False
19
20     @classmethod
21     def disable(cls):
22         cls.HEADER = ''
23         cls.OKBLUE = ''
24         cls.OKGREEN = ''
25         cls.WARNING = ''
26         cls.FAIL = ''
27         cls.ENDC = ''
28
29     @classmethod
30     def enable(cls):
31         if cls.force_disable:
32             return
33
34         cls.HEADER = '\033[95m'
35         cls.OKBLUE = '\033[94m'
36         cls.OKGREEN = '\033[92m'
37         cls.WARNING = '\033[93m'
38         cls.FAIL = '\033[91m'
39         cls.ENDC = '\033[0m'
40
41
42
43 def git(*args, repository_path='.'):
44     return subprocess.check_output(["git"] + list(args), cwd=repository_path,
45                                    stderr=subprocess.STDOUT).decode()
46
47 def accept_command(commands):
48     """Search @commands and returns the first found absolute path."""
49     for command in commands:
50         command = shutil.which(command)
51         if command:
52             return command
53
54     return None
55
56 def get_meson():
57     meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
58     if os.path.exists(meson):
59         mesonconf = os.path.join(ROOTDIR, 'meson', 'mesonconf.py')
60         mesonintrospect = os.path.join(ROOTDIR, 'meson', 'mesonintrospect.py')
61         return meson, mesonconf, mesonintrospect
62
63     return accept_command(["meson.py", "meson"]), accept_command(["mesonconf.py", "mesonconf"]), \
64         accept_command(["mesonintrospect.py", "mesonintrospect"])