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:
parent
6bb30e3148
commit
d51311b7f7
@ -12,7 +12,19 @@ from bench.utils import exec_cmd, get_bench_name, get_cmd_output
|
||||
|
||||
def is_sudoers_set():
|
||||
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):
|
||||
|
@ -511,6 +511,7 @@ def check_git_for_shallow_clone():
|
||||
|
||||
|
||||
def get_cmd_output(cmd, cwd='.', _raise=True):
|
||||
output = ""
|
||||
try:
|
||||
output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE).strip()
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
Loading…
Reference in New Issue
Block a user