From e9462bb7ae95162b83292738a0216c8a5e3b0b9d Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Tue, 13 Nov 2018 12:47:05 -0800 Subject: [PATCH] Do not use deprecated platform module Since bootstrap.py needs to restrict itself to stdlib python, we read from /etc/os-release than trying to install the distro package. --- bootstrap/bootstrap.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py index 78fe7fe..69ddcf7 100644 --- a/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap.py @@ -16,18 +16,33 @@ import os import subprocess import sys import logging -import platform -# Support only Ubuntu 18.04+ -distro, version, _ = platform.linux_distribution() -if distro != 'Ubuntu': - print('The Littlest JupyterHub currently supports Ubuntu Linux only') - sys.exit(1) -elif float(version) < 18.04: - print('The Littlest JupyterHub requires Ubuntu 18.04 or higher') - sys.exit(1) + +def get_os_release_variable(key): + """ + Return value for key from /etc/os-release + + /etc/os-release is a bash file, so should use bash to parse it. + + Returns empty string if key is not found. + """ + return subprocess.check_output([ + '/bin/bash', '-c', + "source /etc/os-release && echo $\{{key}\}".format(key=key) + ]).split() def main(): + + # Support only Ubuntu 18.04+ + distro = get_os_release_variable('ID') + version = float(get_os_release_variable('VERSION_ID')) + if distro != 'ubuntu': + print('The Littlest JupyterHub currently supports Ubuntu Linux only') + sys.exit(1) + elif float(version) < 18.04: + print('The Littlest JupyterHub requires Ubuntu 18.04 or higher') + sys.exit(1) + install_prefix = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh') hub_prefix = os.path.join(install_prefix, 'hub')