config: support major distro variants

Signed-off-by: Cedric Hombourger <Cedric_Hombourger@mentor.com>
This commit is contained in:
Cedric Hombourger 2017-11-08 10:08:59 +01:00 committed by Daniel Wagner
parent 8119dff5f0
commit 06b05a35b6

View File

@ -28,11 +28,18 @@ import logging
import pprint import pprint
try: try:
from distro import id as get_distro_id import distro
def get_distro_id_base():
"""
Returns a compatible distro id.
"""
return distro.like() or distro.id()
except ImportError: except ImportError:
import platform import platform
def get_distro_id(): def get_distro_id_base():
""" """
Wrapper around platform.dist to simulate distro.id Wrapper around platform.dist to simulate distro.id
platform.dist is deprecated and will be removed in python 3.7 platform.dist is deprecated and will be removed in python 3.7
@ -119,17 +126,18 @@ class Config:
Sets the environment variables for process that are Sets the environment variables for process that are
started by kas. started by kas.
""" """
distro_id = get_distro_id() distro_base = get_distro_id_base().lower()
if distro_id.lower() in ['fedora', 'suse', 'opensuse']: if distro_base in ['fedora', 'suse', 'opensuse']:
self.environ = {'LC_ALL': 'en_US.utf8', self.environ = {'LC_ALL': 'en_US.utf8',
'LANG': 'en_US.utf8', 'LANG': 'en_US.utf8',
'LANGUAGE': 'en_US'} 'LANGUAGE': 'en_US'}
elif distro_id.lower() in ['debian', 'ubuntu']: elif distro_base in ['debian', 'ubuntu']:
self.environ = {'LC_ALL': 'en_US.UTF-8', self.environ = {'LC_ALL': 'en_US.UTF-8',
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
'LANGUAGE': 'en_US:en'} 'LANGUAGE': 'en_US:en'}
else: else:
logging.warning('kas: Unsupported distro. No default locales set.') logging.warning('kas: "%s" is not a supported distro. '
'No default locales set.', distro_base)
self.environ = {} self.environ = {}
def get_repo_ref_dir(self): def get_repo_ref_dir(self):