make-ring.py 16.4 KB
Newer Older
aviau's avatar
aviau committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env python3
#
# This is the Ring build helper, it can do these things:
#  - Build Ring
#  - Install Ring
#  - Run Ring
#

import argparse
import os
import subprocess
import sys
import time
Alexandre Lision's avatar
Alexandre Lision committed
14
import platform
Alexandre Lision's avatar
Alexandre Lision committed
15
import multiprocessing
Alexandre Lision's avatar
Alexandre Lision committed
16
import shutil
aviau's avatar
aviau committed
17

18 19 20
IOS_DISTRIBUTION_NAME="ios"
OSX_DISTRIBUTION_NAME="osx"
ANDROID_DISTRIBUTION_NAME="android"
21

Alexandre Lision's avatar
Alexandre Lision committed
22
APT_BASED_DISTROS = [
23 24 25 26
    'debian',
    'ubuntu',
    'linuxmint',
    'raspbian',
aviau's avatar
aviau committed
27 28
]

Alexandre Lision's avatar
Alexandre Lision committed
29
DNF_BASED_DISTROS = [
30
    'fedora',
Alexandre Lision's avatar
Alexandre Lision committed
31 32
]

Simon Zeni's avatar
Simon Zeni committed
33
PACMAN_BASED_DISTROS = [
34
    'arch',
Simon Zeni's avatar
Simon Zeni committed
35 36
]

Alexandre Lision's avatar
Alexandre Lision committed
37
ZYPPER_BASED_DISTROS = [
38
    'opensuse',
39 40
]

aviau's avatar
aviau committed
41 42
APT_INSTALL_SCRIPT = [
    'apt-get update',
43
    'apt-get install -y %(packages)s'
aviau's avatar
aviau committed
44 45
]

46 47 48 49
BREW_UNLINK_SCRIPT = [
    'brew unlink %(packages)s'
]

Alexandre Lision's avatar
Alexandre Lision committed
50 51 52
BREW_INSTALL_SCRIPT = [
    'brew update',
    'brew install -y %(packages)s',
53
    'brew link --force --overwrite %(packages)s'
Alexandre Lision's avatar
Alexandre Lision committed
54
]
Simon Zeni's avatar
Simon Zeni committed
55

Alexandre Lision's avatar
Alexandre Lision committed
56
RPM_INSTALL_SCRIPT = [
57 58
    'dnf update',
    'dnf install -y %(packages)s'
Alexandre Lision's avatar
Alexandre Lision committed
59 60
]

Simon Zeni's avatar
Simon Zeni committed
61
PACMAN_INSTALL_SCRIPT = [
62 63
    'pacman -Sy',
    'pacman -S %(packages)s'
Simon Zeni's avatar
Simon Zeni committed
64 65
]

66
ZYPPER_INSTALL_SCRIPT = [
67 68
    'zypper update',
    'zypper install -y %(packages)s'
69 70
]

Alexandre Lision's avatar
Alexandre Lision committed
71
ZYPPER_DEPENDENCIES = [
72
# build system
Philippe Gorley's avatar
Philippe Gorley committed
73 74 75
    'autoconf', 'autoconf-archive', 'automake', 'cmake', 'patch', 'gcc-c++', 'libtool', 'which',
# contrib dependencies
    'curl', 'gzip', 'bzip2',
76 77
# daemon
    'speexdsp-devel', 'speex-devel', 'libdbus-c++-devel', 'jsoncpp-devel', 'yaml-cpp-devel',
Philippe Gorley's avatar
Philippe Gorley committed
78 79 80 81
    'libupnp-devel', 'yasm', 'libuuid-devel', 'libnettle-devel', 'libopus-devel',
    'libgnutls-devel', 'msgpack-devel', 'libavcodec-devel', 'libavdevice-devel', 'pcre-devel',
    'alsa-devel', 'libpulse-devel', 'libudev-devel', 'libva-devel', 'libvdpau-devel',
    'libopenssl-devel',
82 83 84 85
# lrc
    'libQt5Core-devel', 'libQt5DBus-devel', 'libqt5-linguist-devel',
# gnome client
    'gtk3-devel', 'clutter-gtk-devel', 'qrencode-devel', 'evolution-data-server-devel',
86
    'gettext-tools', 'libnotify-devel', 'libappindicator3-devel', 'webkit2gtk3-devel',
87
    'NetworkManager-devel', 'libcanberra-gtk3-devel'
88 89
]

90 91 92
MINGW64_FEDORA_DEPENDENCIES = [
    'mingw64-binutils', 'mingw64-gcc', 'mingw64-headers', 'mingw64-crt', 'mingw64-gcc-c++',
    'mingw64-pkg-config', 'yasm', 'gettext-devel', 'cmake', 'patch', 'libtool', 'automake',
93
    'autoconf', 'autoconf-archive', 'make', 'xz', 'bzip2', 'which', 'mingw64-qt5-qtbase',
94 95
    'mingw64-qt5-qttools', 'mingw64-qt5-qtsvg', 'mingw64-qt5-qtwinextras', 'mingw64-libidn',
    'mingw64-xz-libs','msgpack-devel'
96 97 98 99 100
]

MINGW32_FEDORA_DEPENDENCIES = [
    'mingw32-binutils', 'mingw32-gcc', 'mingw32-headers', 'mingw32-crt', 'mingw32-gcc-c++',
    'mingw32-pkg-config', 'yasm', 'gettext-devel', 'cmake', 'patch', 'libtool', 'automake',
101
    'autoconf', 'autoconf-archive', 'make', 'xz', 'bzip2', 'which', 'mingw32-qt5-qtbase',
102 103
    'mingw32-qt5-qttools', 'mingw32-qt5-qtsvg', 'mingw32-qt5-qtwinextras', 'mingw32-libidn',
    'mingw32-xz-libs', 'msgpack-devel'
104 105
]

Alexandre Lision's avatar
Alexandre Lision committed
106
DNF_DEPENDENCIES = [
107
    'autoconf', 'autoconf-archive', 'automake', 'cmake', 'speexdsp-devel', 'pulseaudio-libs-devel',
108
    'libtool', 'dbus-devel', 'expat-devel', 'pcre-devel',
Alexandre Lision's avatar
Alexandre Lision committed
109
    'yaml-cpp-devel', 'boost-devel', 'dbus-c++-devel', 'dbus-devel',
110
    'libXext-devel', 'libXfixes-devel', 'yasm',
111
    'speex-devel', 'chrpath', 'check', 'astyle', 'uuid-c++-devel', 'gettext-devel',
Alexandre Lision's avatar
Alexandre Lision committed
112 113
    'gcc-c++', 'which', 'alsa-lib-devel', 'systemd-devel', 'libuuid-devel',
    'uuid-devel', 'gnutls-devel', 'nettle-devel', 'opus-devel', 'speexdsp-devel',
Stepan Salenikovich's avatar
Stepan Salenikovich committed
114 115
    'yaml-cpp-devel', 'qt5-qtbase-devel', 'swig', 'qrencode-devel', 'jsoncpp-devel',
    'gtk3-devel', 'clutter-devel', 'clutter-gtk-devel', 'evolution-data-server-devel',
116
    'libnotify-devel', 'libappindicator-gtk3-devel', 'patch', 'libva-devel', 'openssl-devel',
117
    'webkitgtk4-devel', 'NetworkManager-libnm-devel', 'libvdpau-devel', 'msgpack-devel', 'libcanberra-devel'
Alexandre Lision's avatar
Alexandre Lision committed
118
]
Alexandre Lision's avatar
Alexandre Lision committed
119

Alexandre Lision's avatar
Alexandre Lision committed
120
APT_DEPENDENCIES = [
121 122
    'autoconf', 'autoconf-archive', 'autopoint', 'automake', 'cmake', 'dbus', 'doxygen', 'g++',
    'gettext', 'gnome-icon-theme-symbolic', 'libasound2-dev', 'libavcodec-dev',
123
    'libavdevice-dev', 'libavformat-dev', 'libboost-dev',
aviau's avatar
aviau committed
124
    'libclutter-gtk-1.0-dev', 'libcppunit-dev', 'libdbus-1-dev',
125
    'libdbus-c++-dev', 'libebook1.2-dev', 'libexpat1-dev', 'libgnutls28-dev',
Philippe Gorley's avatar
Philippe Gorley committed
126
    'libgtk-3-dev', 'libjack-dev', 'libnotify-dev',
127
    'libopus-dev', 'libpcre3-dev', 'libpulse-dev', 'libssl-dev',
128
    'libspeex-dev', 'libspeexdsp-dev', 'libswscale-dev', 'libtool',
129
    'libudev-dev', 'libupnp-dev', 'libyaml-cpp-dev', 'qtbase5-dev', 'libqt5sql5-sqlite', 'sip-tester', 'swig',
130
    'uuid-dev', 'yasm', 'libqrencode-dev', 'libjsoncpp-dev', 'libappindicator3-dev',
131
    'libva-dev', 'libwebkit2gtk-4.0-dev', 'libnm-dev', 'libvdpau-dev', 'libmsgpack-dev', 'libcanberra-gtk3-dev'
aviau's avatar
aviau committed
132 133
]

Alexandre Lision's avatar
Alexandre Lision committed
134
PACMAN_DEPENDENCIES = [
135
    'autoconf', 'autoconf-archive', 'gettext', 'cmake', 'dbus', 'doxygen', 'gcc', 'gnome-icon-theme-symbolic',
Simon Zeni's avatar
Simon Zeni committed
136
    'ffmpeg', 'boost', 'clutter-gtk', 'cppunit', 'libdbus', 'dbus-c++', 'libe-book',
Philippe Gorley's avatar
Philippe Gorley committed
137
    'expat', 'gtk3', 'jack', 'libnotify', 'opus', 'pcre', 'libpulse',
138
    'speex', 'speexdsp', 'libtool', 'libupnp', 'yaml-cpp', 'qt5-base',
Simon Zeni's avatar
Simon Zeni committed
139
    'swig', 'yasm', 'qrencode', 'evolution-data-server', 'make', 'patch', 'pkg-config',
140
    'automake', 'libva', 'webkit2gtk', 'libnm', 'libvdpau', 'libcanbera', 'openssl'
Simon Zeni's avatar
Simon Zeni committed
141 142
]

Alexandre Lision's avatar
Alexandre Lision committed
143
OSX_DEPENDENCIES = [
144
    'autoconf', 'cmake', 'gettext', 'pkg-config', 'qt5',
Alexandre Lision's avatar
Alexandre Lision committed
145 146 147
    'libtool', 'yasm', 'automake'
]

148 149
OSX_DEPENDENCIES_UNLINK = [
    'autoconf*', 'cmake*', 'gettext*', 'pkg-config*', 'qt*', 'qt@5.*',
Andreas Traczyk's avatar
Andreas Traczyk committed
150
    'libtool*', 'yasm*', 'automake*', 'gnutls*', 'nettle*', 'msgpack*'
151 152
]

153
IOS_DEPENDENCIES = [
154
    'autoconf', 'automake', 'cmake', 'yasm', 'libtool',
155 156 157
    'pkg-config', 'gettext', 'swiftlint', 'swiftgen'
]

158 159 160 161 162
IOS_DEPENDENCIES_UNLINK = [
    'autoconf*', 'automake*', 'cmake*', 'yasm*', 'libtool*',
    'pkg-config*', 'gettext*', 'swiftlint*', 'swiftgen*'
]

aviau's avatar
aviau committed
163 164
UNINSTALL_SCRIPT = [
    'make -C daemon uninstall',
165 166 167 168
    'rm -rf ./lrc/build-global/',
    'rm -rf ./lrc/build-local/',
    'rm -rf ./client-gnome/build-global',
    'rm -rf ./client-gnome/build-local',
aviau's avatar
aviau committed
169 170
]

Alexandre Lision's avatar
Alexandre Lision committed
171 172 173 174 175
OSX_UNINSTALL_SCRIPT = [
    'make -C daemon uninstall',
    'rm -rf install/client-macosx',
]

aviau's avatar
aviau committed
176 177 178 179 180 181 182
STOP_SCRIPT = [
    'xargs kill < daemon.pid',
    'xargs kill < gnome-ring.pid',
]


def run_dependencies(args):
183
    if args.distribution in APT_BASED_DISTROS:
aviau's avatar
aviau committed
184
        execute_script(APT_INSTALL_SCRIPT,
Alexandre Lision's avatar
Alexandre Lision committed
185
            {"packages": ' '.join(APT_DEPENDENCIES)}
aviau's avatar
aviau committed
186
        )
187
    elif args.distribution in DNF_BASED_DISTROS:
Alexandre Lision's avatar
Alexandre Lision committed
188 189
        execute_script(
            RPM_INSTALL_SCRIPT,
Alexandre Lision's avatar
Alexandre Lision committed
190
            {"packages": ' '.join(DNF_DEPENDENCIES)}
Alexandre Lision's avatar
Alexandre Lision committed
191
        )
192 193 194 195 196 197 198 199 200 201
    elif args.distribution == "mingw32":
        execute_script(
            RPM_INSTALL_SCRIPT,
            {"packages": ' '.join(MINGW32_FEDORA_DEPENDENCIES)}
        )
    elif args.distribution == "mingw64":
        execute_script(
            RPM_INSTALL_SCRIPT,
            {"packages": ' '.join(MINGW64_FEDORA_DEPENDENCIES)}
        )
202
    elif args.distribution in PACMAN_BASED_DISTROS:
Simon Zeni's avatar
Simon Zeni committed
203 204
        execute_script(
            PACMAN_INSTALL_SCRIPT,
Alexandre Lision's avatar
Alexandre Lision committed
205
            {"packages": ' '.join(PACMAN_DEPENDENCIES)}
Simon Zeni's avatar
Simon Zeni committed
206 207
        )

208
    elif args.distribution in ZYPPER_BASED_DISTROS:
209 210
        execute_script(
            ZYPPER_INSTALL_SCRIPT,
Alexandre Lision's avatar
Alexandre Lision committed
211
            {"packages": ' '.join(ZYPPER_DEPENDENCIES)}
212 213
        )

214
    elif args.distribution == OSX_DISTRIBUTION_NAME:
215 216
        execute_script(
            BREW_UNLINK_SCRIPT,
Andreas Traczyk's avatar
Andreas Traczyk committed
217 218
            {"packages": ' '.join(OSX_DEPENDENCIES_UNLINK)},
            False
219
        )
Alexandre Lision's avatar
Alexandre Lision committed
220 221
        execute_script(
            BREW_INSTALL_SCRIPT,
222 223
            {"packages": ' '.join(OSX_DEPENDENCIES)},
            False
Alexandre Lision's avatar
Alexandre Lision committed
224 225
        )

226
    elif args.distribution == IOS_DISTRIBUTION_NAME:
227 228
        execute_script(
            BREW_UNLINK_SCRIPT,
Andreas Traczyk's avatar
Andreas Traczyk committed
229 230
            {"packages": ' '.join(IOS_DEPENDENCIES_UNLINK)},
            False
231
        )
232 233
        execute_script(
            BREW_INSTALL_SCRIPT,
234 235
            {"packages": ' '.join(IOS_DEPENDENCIES)},
            False
236 237
        )

238
    elif args.distribution == ANDROID_DISTRIBUTION_NAME:
Romain Bertozzi's avatar
Romain Bertozzi committed
239 240 241
        print("The Android version does not need more dependencies.\nPlease continue with the --install instruction.")
        sys.exit(1)

aviau's avatar
aviau committed
242 243 244 245
    else:
        print("Not yet implemented for current distribution (%s)" % args.distribution)
        sys.exit(1)

Alexandre Lision's avatar
Alexandre Lision committed
246
def run_init():
247 248 249 250 251 252 253
    # Extract modules path from '.gitmodules' file
    module_names = []
    with open('.gitmodules') as fd:
        for line in fd.readlines():
            if line.startswith('[submodule "'):
                module_names.append(line[line.find('"')+1:line.rfind('"')])

Alexandre Lision's avatar
Alexandre Lision committed
254 255
    os.system("git submodule update --init")
    os.system("git submodule foreach 'git checkout master && git pull'")
256 257
    for name in module_names:
        copy_file("./scripts/commit-msg", ".git/modules/"+name+"/hooks")
Alexandre Lision's avatar
Alexandre Lision committed
258 259 260 261 262 263 264 265 266 267 268

def copy_file(src, dest):
    print("Copying:" + src + " to " + dest)
    try:
        shutil.copy2(src, dest)
    # eg. src and dest are the same file
    except shutil.Error as e:
        print('Error: %s' % e)
    # eg. source or destination doesn't exist
    except IOError as e:
        print('Error: %s' % e.strerror)
aviau's avatar
aviau committed
269 270

def run_install(args):
Alexandre Lision's avatar
Alexandre Lision committed
271
    install_args = ' -p ' + str(multiprocessing.cpu_count())
aviau's avatar
aviau committed
272 273 274 275
    if args.static:
        install_args += ' -s'
    if args.global_install:
        install_args += ' -g'
276
    if args.distribution == OSX_DISTRIBUTION_NAME:
277
        proc= subprocess.Popen("brew --prefix qt5", shell=True, stdout=subprocess.PIPE)
Alexandre Lision's avatar
Alexandre Lision committed
278 279
        qt5dir = proc.stdout.read()
        os.environ['CMAKE_PREFIX_PATH'] = str(qt5dir.decode('ascii'))
Alexandre Lision's avatar
Alexandre Lision committed
280 281
        install_args += " -c client-macosx"
        execute_script(["CONFIGURE_FLAGS='--without-dbus' ./scripts/install.sh " + install_args])
282 283 284
    elif args.distribution == IOS_DISTRIBUTION_NAME:
        os.chdir("./client-ios")
        execute_script(["./compile-ios.sh"])
285
    elif args.distribution == ANDROID_DISTRIBUTION_NAME:
Romain Bertozzi's avatar
Romain Bertozzi committed
286 287
        os.chdir("./client-android")
        execute_script(["./compile.sh"])
288 289 290 291 292 293 294 295 296 297
    elif args.distribution == 'mingw32':
        os.environ['CMAKE_PREFIX_PATH'] = '/usr/i686-w64-mingw32/sys-root/mingw/lib/cmake'
        os.environ['QTDIR'] = '/usr/i686-w64-mingw32/sys-root/mingw/lib/qt5/'
        os.environ['PATH'] = '/usr/i686-w64-mingw32/bin/qt5/:' + os.environ['PATH']
        execute_script(["./scripts/win_compile.sh"])
    elif args.distribution == 'mingw64':
        os.environ['CMAKE_PREFIX_PATH'] = '/usr/x86_64-w64-mingw32/sys-root/mingw/lib/cmake'
        os.environ['QTDIR'] = '/usr/x86_64-w64-mingw32/sys-root/mingw/lib/qt5/'
        os.environ['PATH'] = '/usr/x86_64-w64-mingw32/bin/qt5/:' + os.environ['PATH']
        execute_script(["./scripts/win_compile.sh --arch=64"])
Alexandre Lision's avatar
Alexandre Lision committed
298
    else:
299
        if args.distribution in ZYPPER_BASED_DISTROS:
300
            os.environ['JSONCPP_LIBS'] = "-ljsoncpp" #fix jsoncpp pkg-config bug, remove when jsoncpp package bumped
301
        install_args += ' -c client-gnome'
Alexandre Lision's avatar
Alexandre Lision committed
302
        execute_script(["./scripts/install.sh " + install_args])
aviau's avatar
aviau committed
303 304 305


def run_uninstall(args):
306
    if args.distribution == OSX_DISTRIBUTION_NAME:
Alexandre Lision's avatar
Alexandre Lision committed
307 308 309
        execute_script(OSX_UNINSTALL_SCRIPT)
    else:
        execute_script(UNINSTALL_SCRIPT)
aviau's avatar
aviau committed
310 311 312


def run_run(args):
313
    if args.distribution == OSX_DISTRIBUTION_NAME:
Alexandre Lision's avatar
Alexandre Lision committed
314 315 316
        subprocess.Popen(["install/client-macosx/Ring.app/Contents/MacOS/Ring"])
        return True

aviau's avatar
aviau committed
317 318 319 320 321 322 323
    run_env = os.environ
    run_env['LD_LIBRARY_PATH'] = run_env.get('LD_LIBRARY_PATH', '') + ":install/lrc/lib"

    try:
        dring_log = open("daemon.log", 'a')
        dring_log.write('=== Starting daemon (%s) ===' % time.strftime("%d/%m/%Y %H:%M:%S"))
        dring_process = subprocess.Popen(
324
            ["./install/daemon/lib/ring/dring", "-c", "-d"],
aviau's avatar
aviau committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
            stdout=dring_log,
            stderr=dring_log
        )

        with open('daemon.pid', 'w') as f:
            f.write(str(dring_process.pid)+'\n')

        client_log = open("gnome-ring.log", 'a')
        client_log.write('=== Starting client (%s) ===' % time.strftime("%d/%m/%Y %H:%M:%S"))
        client_process = subprocess.Popen(
            ["./install/client-gnome/bin/gnome-ring", "-d"],
            stdout=client_log,
            stderr=client_log,
            env=run_env
        )

        with open('gnome-ring.pid', 'w') as f:
            f.write(str(client_process.pid)+'\n')

        if args.debug:
            subprocess.call(
346
                ['gdb','-x', 'gdb.gdb', './install/daemon/lib/ring/dring'],
aviau's avatar
aviau committed
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
            )

        if args.background == False:
            dring_process.wait()
            client_process.wait()

    except KeyboardInterrupt:
        print("\nCaught KeyboardInterrupt...")

    finally:
        if args.background == False:
            try:
                # Only kill the processes if they are running, as they could
                # have been closed by the user.
                print("Killing processes...")
                dring_log.close()
                if dring_process.poll() is None:
                    dring_process.kill()
                client_log.close()
                if client_process.poll() is None:
                    client_process.kill()
            except UnboundLocalError:
                # Its okay! We crashed before we could start a process or open a
                # file. All that matters is that we close files and kill processes
                # in the right order.
                pass
Alexandre Lision's avatar
Alexandre Lision committed
373
    return True
aviau's avatar
aviau committed
374 375 376 377 378


def run_stop(args):
    execute_script(STOP_SCRIPT)

Andreas Traczyk's avatar
Andreas Traczyk committed
379
def execute_script(script, settings=None, fail=True):
aviau's avatar
aviau committed
380 381 382 383 384
    if settings == None:
        settings = {}
    for line in script:
        line = line % settings
        rv = os.system(line)
Andreas Traczyk's avatar
Andreas Traczyk committed
385
        if rv != 0 and fail == True:
386 387
            print('Error executing script! Exit code: %s' % rv, file=sys.stderr)
            sys.exit(1)
aviau's avatar
aviau committed
388 389 390 391 392

def validate_args(parsed_args):
    """Validate the args values, exit if error is found"""

    # Check arg values
393
    supported_distros = [ANDROID_DISTRIBUTION_NAME, OSX_DISTRIBUTION_NAME, IOS_DISTRIBUTION_NAME] + APT_BASED_DISTROS + DNF_BASED_DISTROS + PACMAN_BASED_DISTROS + ZYPPER_BASED_DISTROS + ['mingw32','mingw64']
Simon Zeni's avatar
Simon Zeni committed
394

aviau's avatar
aviau committed
395
    if parsed_args.distribution not in supported_distros:
396
        print('Distribution \''+parsed_args.distribution+'\' not supported.\nChoose one of: %s' \
aviau's avatar
aviau committed
397 398 399 400 401 402 403 404
                  % ', '.join(supported_distros),
            file=sys.stderr)
        sys.exit(1)

def parse_args():
    ap = argparse.ArgumentParser(description="Ring build tool")

    ga = ap.add_mutually_exclusive_group(required=True)
Alexandre Lision's avatar
Alexandre Lision committed
405 406 407
    ga.add_argument(
        '--init', action='store_true',
        help='Init Ring repository')
aviau's avatar
aviau committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
    ga.add_argument(
        '--dependencies', action='store_true',
        help='Install ring build dependencies')
    ga.add_argument(
        '--install', action='store_true',
        help='Build and install Ring')
    ga.add_argument(
        '--uninstall', action='store_true',
        help='Uninstall Ring')
    ga.add_argument(
        '--run', action='store_true',
         help='Run the Ring daemon and client')
    ga.add_argument(
        '--stop', action='store_true',
        help='Stop the Ring processes')

424
    ap.add_argument('--distribution')
aviau's avatar
aviau committed
425 426 427 428 429 430
    ap.add_argument('--static', default=False, action='store_true')
    ap.add_argument('--global-install', default=False, action='store_true')
    ap.add_argument('--debug', default=False, action='store_true')
    ap.add_argument('--background', default=False, action='store_true')

    parsed_args = ap.parse_args()
Alexandre Lision's avatar
Alexandre Lision committed
431

432 433 434
    if (parsed_args.distribution is not None):
        parsed_args.distribution = parsed_args.distribution.lower()
    else:
Alexandre Lision's avatar
Alexandre Lision committed
435 436
        parsed_args.distribution = choose_distribution()

437
    if parsed_args.distribution in ['mingw32', 'mingw64']:
438
        if choose_distribution() != "fedora":
439 440 441
            print('Windows version must be built on a Fedora distribution (>=23)')
            sys.exit(1)

aviau's avatar
aviau committed
442 443 444 445
    validate_args(parsed_args)

    return parsed_args

Alexandre Lision's avatar
Alexandre Lision committed
446 447 448
def choose_distribution():
    system = platform.system().lower()
    if system == "linux" or system == "linux2":
VietKen's avatar
VietKen committed
449
        if os.path.isfile("/etc/arch-release"):
450
            return "arch"
Alexandre Lision's avatar
Alexandre Lision committed
451 452 453
        with open("/etc/os-release") as f:
            for line in f:
                k,v = line.split("=")
454
                if k.strip() == 'ID':
455
                    return v.strip().replace('"','').split(' ')[0]
Alexandre Lision's avatar
Alexandre Lision committed
456
    elif system == "darwin":
457
        return OSX_DISTRIBUTION_NAME
Alexandre Lision's avatar
Alexandre Lision committed
458 459 460

    return 'Unknown'

aviau's avatar
aviau committed
461 462 463 464 465 466 467

def main():
    parsed_args = parse_args()

    if parsed_args.dependencies:
        run_dependencies(parsed_args)

Alexandre Lision's avatar
Alexandre Lision committed
468 469 470
    elif parsed_args.init:
        run_init()

aviau's avatar
aviau committed
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
    elif parsed_args.install:
        run_install(parsed_args)

    elif parsed_args.uninstall:
        run_uninstall(parsed_args)

    elif parsed_args.run:
        run_run(parsed_args)

    elif parsed_args.stop:
        run_stop(parsed_args)


if __name__ == "__main__":
    main()