From 33ba41bbeacaea3ecde4f6e79990ce309a8e97f9 Mon Sep 17 00:00:00 2001 From: FadeMind Date: Tue, 27 Feb 2018 19:26:40 +0100 Subject: [PATCH 1/2] updateHostsFile.py: cross-compatible sudo --- updateHostsFile.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index ad77cc823..2b9cc5cbf 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -35,7 +35,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 @@ -1015,7 +1015,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 " @@ -1036,7 +1036,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.") @@ -1052,7 +1052,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")) @@ -1073,7 +1073,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")) @@ -1085,7 +1085,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")) From ee411d82c9c00fffcc22a4c8a7496dd6304aaf3b Mon Sep 17 00:00:00 2001 From: FadeMind Date: Sat, 3 Mar 2018 15:30:49 +0100 Subject: [PATCH 2/2] updateHostsFile.py: DEL whitespace after '[' https://travis-ci.org/StevenBlack/hosts/jobs/346915934#L606-L609 --- updateHostsFile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 2b9cc5cbf..ce838d84d 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1052,7 +1052,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")) @@ -1073,7 +1073,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")) @@ -1085,7 +1085,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"))