From 7c475d2b682ef9ced3572ad6cac47849cae87071 Mon Sep 17 00:00:00 2001 From: Kaiser-Yang <624626089@qq.com> Date: Fri, 20 Sep 2024 16:20:37 +0800 Subject: [PATCH] Remove try catch for CalledProcessError In the `subprocess.run` only when `check=True` will cause the `CalledProcessError` to be raised. So we don't need to catch it when we are not using `check=True`. --- script/deploy_helper.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/script/deploy_helper.py b/script/deploy_helper.py index 391c101..828755b 100644 --- a/script/deploy_helper.py +++ b/script/deploy_helper.py @@ -378,13 +378,10 @@ def deploy_on_ubuntu(config): create_or_update_user(config.serviceUser, config.serviceUserPassword) # let the service user can use git command as the git user without password sudoers_entry = f"{config.serviceUser} ALL=(git) NOPASSWD: /usr/bin/git" - try: - res = subprocess.run(f"echo '{sudoers_entry}' | {sudo_cmd} tee /etc/sudoers.d/{config.serviceUser}", shell=True); - command_checker(res.returncode, f"Failed to create /etc/sudoers.d/{config.serviceUser}") - res = subprocess.run(f"{sudo_cmd} chmod 440 /etc/sudoers.d/{config.serviceUser}", shell=True) - command_checker(res.returncode, f"Failed to chmod 440 /etc/sudoers.d/{config.serviceUser}") - except subprocess.CalledProcessError as e: - command_checker(1, f"Error: {e}") + res = subprocess.run(f"echo '{sudoers_entry}' | {sudo_cmd} tee /etc/sudoers.d/{config.serviceUser}", shell=True); + command_checker(res.returncode, f"Failed to create /etc/sudoers.d/{config.serviceUser}") + res = subprocess.run(f"{sudo_cmd} chmod 440 /etc/sudoers.d/{config.serviceUser}", shell=True) + command_checker(res.returncode, f"Failed to chmod 440 /etc/sudoers.d/{config.serviceUser}") if config.deploy: if not os.path.exists(os.path.dirname(config.serviceStartJarFile)):