From d6902573789d6bc558457c1302ad211a2a433d33 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 28 Mar 2018 10:26:56 -0400 Subject: [PATCH] fixed encodings --- bench/utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 497bbb3f..029e9ec2 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -306,9 +306,10 @@ def setup_sudoers(user): 'nginx': find_executable('nginx'), 'bench': find_executable('bench') }) + frappe_sudoers = safe_decode(frappe_sudoers) with open(sudoers_file, 'w') as f: - f.write(frappe_sudoers.encode('utf-8')) + f.write(frappe_sudoers) os.chmod(sudoers_file, 0o440) @@ -388,6 +389,14 @@ def get_cmd_output(cmd, cwd='.'): print(e.output) raise +def safe_encode(what, encoding = 'utf-8'): + try: + what = what.encode(encoding) + except Exception: + pass + + return what + def restart_supervisor_processes(bench_path='.', web_workers=False): from .config.common_site_config import get_config conf = get_config(bench_path=bench_path) @@ -399,7 +408,8 @@ def restart_supervisor_processes(bench_path='.', web_workers=False): else: supervisor_status = subprocess.check_output(['sudo', 'supervisorctl', 'status'], cwd=bench_path) - + supervisor_status = safe_decode(supervisor_status) + if web_workers and '{bench_name}-web:'.format(bench_name=bench_name) in supervisor_status: group = '{bench_name}-web: '.format(bench_name=bench_name)