Add a new subproject 'win-flex-bison-binaries'
[platform/upstream/gstreamer.git] / common.py
1 import argparse
2 import os
3 import shutil
4 import subprocess
5 import shlex
6
7
8 ROOTDIR = os.path.abspath(os.path.dirname(__file__))
9
10
11 class Colors:
12     HEADER = '\033[95m'
13     OKBLUE = '\033[94m'
14     OKGREEN = '\033[92m'
15     WARNING = '\033[93m'
16     FAIL = '\033[91m'
17     ENDC = '\033[0m'
18
19     force_disable = False
20
21     @classmethod
22     def disable(cls):
23         cls.HEADER = ''
24         cls.OKBLUE = ''
25         cls.OKGREEN = ''
26         cls.WARNING = ''
27         cls.FAIL = ''
28         cls.ENDC = ''
29
30     @classmethod
31     def enable(cls):
32         if cls.force_disable:
33             return
34
35         cls.HEADER = '\033[95m'
36         cls.OKBLUE = '\033[94m'
37         cls.OKGREEN = '\033[92m'
38         cls.WARNING = '\033[93m'
39         cls.FAIL = '\033[91m'
40         cls.ENDC = '\033[0m'
41
42
43
44 def git(*args, repository_path='.'):
45     return subprocess.check_output(["git"] + list(args), cwd=repository_path,
46                                    stderr=subprocess.STDOUT).decode()
47
48 def accept_command(commands):
49     """Search @commands and returns the first found absolute path."""
50     for command in commands:
51         command = shutil.which(command)
52         if command:
53             return command
54
55     return None
56
57 def get_meson():
58     meson = os.path.join(ROOTDIR, 'meson', 'meson.py')
59     if os.path.exists(meson):
60         return meson
61
62     mesonintrospect = os.environ.get('MESONINTROSPECT', '')
63     for comp in shlex.split (mesonintrospect):
64         # mesonintrospect might look like "/usr/bin/python /somewhere/meson introspect",
65         # let's not get tricked
66         if 'python' in os.path.basename (comp):
67             continue
68         if os.path.exists (comp):
69             mesondir = os.path.dirname(comp)
70             if mesonintrospect.endswith('.py'):
71                 meson = os.path.join(mesondir, 'meson.py')
72             else:
73                 meson = os.path.join(mesondir, 'meson')
74             if os.path.exists (meson):
75                 return meson
76
77     meson = accept_command(["meson.py", "meson"])
78
79     return meson