From cd0773605c8b91527c039945481856645463c064 Mon Sep 17 00:00:00 2001 From: faraco Date: Sat, 21 Oct 2017 23:06:28 +0800 Subject: [PATCH] - use python built in methods - eliminate the usage of wget for manual install for systems that doesn't have wget preinstalled. - works with Python 2 and 3 --- download-xflux.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/download-xflux.py b/download-xflux.py index 352441a..7f3fc2b 100644 --- a/download-xflux.py +++ b/download-xflux.py @@ -1,5 +1,11 @@ -from sys import maxsize -import os +from sys import maxsize, version_info + +if version_info[0] == 3: + from urllib.request import urlretrieve +else: + from urllib import urlretrieve + +import tarfile # There is similar code in ./debian/postinst. If you are changing this # you probably want to change that too. @@ -12,8 +18,17 @@ def download_xflux(): print("Downloading 64-bit xflux ...") url = "https://justgetflux.com/linux/xflux64.tgz" tarchive = "/tmp/xflux.tgz" - os.system("wget '%s' -O'%s'" % (url, tarchive)) - os.system("tar -xvf '%s'" % tarchive) + + # use python's builtins methods to eliminate external program + # dependencies for manual install + # in case internet connection isn't available to download wget + # & not every linux system (minimal) has wget (nor curl) preinstalled. + urlretrieve(url, tarchive) + + print("Extracting {} ...".format(tarchive)) + tar = tarfile.open(tarchive) + tar.extractall() + tar.close() if __name__ == '__main__': download_xflux()