Commit e3d89bc5 authored by Alexandre Lision's avatar Alexandre Lision Committed by Guillaume Roguez

add distro detection

if no distro is provided with --distribution, try to guess it

Tuleap: #451
Change-Id: Ie8656dcd5a40df6c2c045d0b908b86cd66a10010
parent 6b2ca8bc
......@@ -11,6 +11,7 @@ import os
import subprocess
import sys
import time
import platform
DEBIAN_BASED_DISTROS = [
'Debian',
......@@ -232,14 +233,13 @@ def validate_args(parsed_args):
"""Validate the args values, exit if error is found"""
# Check arg values
supported_distros = ['Ubuntu', 'Debian', 'OSX', 'Fedora']
supported_distros = ['Ubuntu', 'Debian', 'OSX', 'Fedora', 'Automatic']
if parsed_args.distribution not in supported_distros:
print('Distribution not supported.\nChoose one of: %s' \
% ', '.join(supported_distros),
file=sys.stderr)
sys.exit(1)
def parse_args():
ap = argparse.ArgumentParser(description="Ring build tool")
......@@ -260,17 +260,34 @@ def parse_args():
'--stop', action='store_true',
help='Stop the Ring processes')
ap.add_argument('--distribution', default='Ubuntu')
ap.add_argument('--distribution', default='Automatic')
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()
if parsed_args.distribution == 'Automatic':
parsed_args.distribution = choose_distribution()
validate_args(parsed_args)
return parsed_args
def choose_distribution():
system = platform.system().lower()
if system == "linux" or system == "linux2":
with open("/etc/os-release") as f:
for line in f:
k,v = line.split("=")
if k.strip() == 'NAME':
return v.strip()
elif system == "darwin":
return 'OSX'
return 'Unknown'
def main():
parsed_args = parse_args()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment