Skip to content

Commit

Permalink
Remove try catch for CalledProcessError
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Kaiser-Yang committed Sep 20, 2024
1 parent 3a7fdf6 commit 7c475d2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down

0 comments on commit 7c475d2

Please sign in to comment.