Merge pull request #519 from FadeMind/cross-sudo

cross-compatible sudo FIXED CI
This commit is contained in:
Steven Black 2018-03-03 15:13:16 -05:00 committed by GitHub
commit 2bd48fb7ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,7 +38,7 @@ else: # Python 2
raw_input = raw_input # noqa
# Syntactic sugar for "sudo" command in UNIX / Linux
SUDO = "/usr/bin/sudo"
SUDO = ["/usr/bin/env", "sudo"]
# Project Settings
@ -1018,7 +1018,7 @@ def move_hosts_file_into_place(final_file):
if os.name == "posix":
print("Moving the file requires administrative privileges. "
"You might need to enter your password.")
if subprocess.call([SUDO, "cp", filename, "/etc/hosts"]):
if subprocess.call(SUDO + ["cp", filename, "/etc/hosts"]):
print_failure("Moving the file failed.")
elif os.name == "nt":
print("Automatically moving the hosts file "
@ -1039,7 +1039,7 @@ def flush_dns_cache():
dns_cache_found = False
if platform.system() == "Darwin":
if subprocess.call([SUDO, "killall", "-HUP", "mDNSResponder"]):
if subprocess.call(SUDO + ["killall", "-HUP", "mDNSResponder"]):
print_failure("Flushing the DNS cache failed.")
elif os.name == "nt":
print("Automatically flushing the DNS cache is not yet supported.")
@ -1055,7 +1055,7 @@ def flush_dns_cache():
if os.path.isfile(nscd_cache):
dns_cache_found = True
if subprocess.call([SUDO, nscd_cache, "restart"]):
if subprocess.call(SUDO + [nscd_cache, "restart"]):
print_failure(nscd_msg.format(result="failed"))
else:
print_success(nscd_msg.format(result="succeeded"))
@ -1076,7 +1076,7 @@ def flush_dns_cache():
if os.path.isfile(service_file):
dns_cache_found = True
if subprocess.call([SUDO, systemctl, "restart", service]):
if subprocess.call(SUDO + [systemctl, "restart", service]):
print_failure(service_msg.format(result="failed"))
else:
print_success(service_msg.format(result="succeeded"))
@ -1088,7 +1088,7 @@ def flush_dns_cache():
if os.path.isfile(dns_clean_file):
dns_cache_found = True
if subprocess.call([SUDO, dns_clean_file, "start"]):
if subprocess.call(SUDO + [dns_clean_file, "start"]):
print_failure(dns_clean_msg.format(result="failed"))
else:
print_success(dns_clean_msg.format(result="succeeded"))