From 4014f7349dde39ec743cab66acb9f55257c5dec8 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 3 Aug 2022 16:04:21 +0530 Subject: [PATCH] refactor: Exceptions, variables with pylint --- bench/patches/v5/fix_user_permissions.py | 1 + bench/utils/__init__.py | 9 +++++---- bench/utils/bench.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bench/patches/v5/fix_user_permissions.py b/bench/patches/v5/fix_user_permissions.py index c780bbc0..917d5486 100644 --- a/bench/patches/v5/fix_user_permissions.py +++ b/bench/patches/v5/fix_user_permissions.py @@ -13,6 +13,7 @@ from bench.utils import exec_cmd, get_bench_name, get_cmd_output def is_sudoers_set(): """Check if bench sudoers is set""" cmd = ["sudo", "-n", "bench"] + bench_warn = False with open(os.devnull, "wb") as f: return_code_check = not subprocess.call(cmd, stdout=f) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 35f1bd79..a25e9220 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -63,9 +63,10 @@ def is_valid_frappe_branch(frappe_path: str, frappe_branch: str): :type frappe_branch: str :raises InvalidRemoteException: branch for this repo doesn't exist """ - import git + from git.cmd import Git + from git.exc import GitCommandError - g = git.cmd.Git() + g = Git() if frappe_branch: try: @@ -74,8 +75,8 @@ def is_valid_frappe_branch(frappe_path: str, frappe_branch: str): raise InvalidRemoteException( f"Invalid branch or tag: {frappe_branch} for the remote {frappe_path}" ) - except git.exc.GitCommandError: - raise InvalidRemoteException(f"Invalid frappe path: {frappe_path}") + except GitCommandError as e: + raise InvalidRemoteException(f"Invalid frappe path: {frappe_path}") from e def log(message, level=0, no_log=False): diff --git a/bench/utils/bench.py b/bench/utils/bench.py index b6afd1c0..5467256a 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -280,7 +280,7 @@ def restart_supervisor_processes(bench_path=".", web_workers=False): sudo = "" try: supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path) - except Exception as e: + except subprocess.CalledProcessError as e: if e.returncode == 127: log("restart failed: Couldn't find supervisorctl in PATH", level=3) return