From 5adaa2edf83fef28b57d383ab6264737077a2d25 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 7 Feb 2016 19:09:53 +0000 Subject: [PATCH] Cleanup python code --- INSTALL_ALL_THE_THINGS | 4 +--- wscript | 18 ++++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/INSTALL_ALL_THE_THINGS b/INSTALL_ALL_THE_THINGS index 716abab..27e885f 100755 --- a/INSTALL_ALL_THE_THINGS +++ b/INSTALL_ALL_THE_THINGS @@ -14,9 +14,7 @@ def get_functions(): if __name__ == '__main__': if os.geteuid() != 0: - print("Not running as root. Elevating...") - args = ['sudo', sys.executable] + sys.argv + [os.environ] - os.execlpe('sudo', *args) + print("Please run as root!") elif input("Are you sure you want to install (allthethings)? [Y/N]: ").lower() == 'y': os.system('./install-waf.sh') waf_scripts = [] diff --git a/wscript b/wscript index 9640f45..f9a1c79 100644 --- a/wscript +++ b/wscript @@ -3,6 +3,9 @@ import json, os, shutil DIR = os.getcwd() +def get_json(path): + return json.load(open(DIR + path)) + def update_and_upgrade(ctx): os.system('apt-get update -y') os.system('apt-get upgrade -y') @@ -10,14 +13,12 @@ def update_and_upgrade(ctx): def apt_install_core(ctx): - packages = json.load(open(DIR + '/apt/apt-installs-core.json')) - for package in packages: + for package in get_json('/apt/apt-installs-core.json'): os.system("apt-get install {} -y".format(package)) def add_apt_keys(ctx): - keys = json.load(open(DIR + '/apt/apt-keys.json')) - for key in keys: + for key in get_json('/apt/apt-keys.json'): os.system("wget -O - {} | apt-key add -".format(key)) @@ -26,14 +27,12 @@ def add_apt_sources(ctx): def add_apt_repos(ctx): - repos = json.load(open(DIR + '/apt/apt-repos.json')) - for repo in repos: + for repo in get_json('/apt/apt-repos.json'): os.system("add-apt-repository {} -y".format(repo)) def apt_install_extras(ctx): - packages = json.load(open(DIR + '/apt/apt-installs-extra.json')) - for package in packages: + for package in get_json('/apt/apt-installs-extra.json'): os.system("apt-get install {} -y".format(package)) @@ -42,8 +41,7 @@ def run_custom_installs(ctx): def install_atom_packages(ctx): - packages = json.load(open(DIR + '/atom/packages.json')) - packages = " ".join(packages) + packages = " ".join(get_json('/atom/packages.json')) os.system("apm install {}".format(packages))