2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 09:02:10 +00:00

fix: better exception handling for checking sudoers set

This commit is contained in:
Gavin D'souza 2020-03-19 18:52:49 +05:30
parent 6bb30e3148
commit d51311b7f7
2 changed files with 14 additions and 1 deletions

View File

@ -12,7 +12,19 @@ from bench.utils import exec_cmd, get_bench_name, get_cmd_output
def is_sudoers_set(): def is_sudoers_set():
cmd = ["sudo", "-n", "bench"] cmd = ["sudo", "-n", "bench"]
return (not subprocess.call(cmd)) or (change_uid_msg in get_cmd_output(cmd, _raise=False))
with open(os.devnull, "wb") as f:
return_code_check = not subprocess.call(cmd, stdout=f)
if return_code_check:
try:
bench_warn = change_uid_msg in get_cmd_output(cmd, _raise=False)
except Exception:
bench_warn = False
finally:
return_code_check = return_code_check and bench_warn
return return_code_check
def is_production_set(bench_path): def is_production_set(bench_path):

View File

@ -511,6 +511,7 @@ def check_git_for_shallow_clone():
def get_cmd_output(cmd, cwd='.', _raise=True): def get_cmd_output(cmd, cwd='.', _raise=True):
output = ""
try: try:
output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE).strip() output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE).strip()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e: