From f9521efc50827aa6e72624e55b28164a15791583 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sat, 15 Feb 2020 11:05:30 +0530 Subject: [PATCH] chore: removed unused and optimized imports --- bench/commands/config.py | 1 - bench/commands/git.py | 1 - bench/commands/install.py | 7 +------ bench/commands/setup.py | 15 ++++++++------- bench/utils.py | 4 ---- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/bench/commands/config.py b/bench/commands/config.py index bf912ed1..1dc33a39 100644 --- a/bench/commands/config.py +++ b/bench/commands/config.py @@ -1,6 +1,5 @@ # imports - standard imports import ast -import json # imports - module imports from bench.config.common_site_config import update_config, get_config, put_config diff --git a/bench/commands/git.py b/bench/commands/git.py index cc9812ab..8b52661b 100644 --- a/bench/commands/git.py +++ b/bench/commands/git.py @@ -1,6 +1,5 @@ # imports - standard imports import os -import re import subprocess # imports - module imports diff --git a/bench/commands/install.py b/bench/commands/install.py index acca340a..b760719c 100644 --- a/bench/commands/install.py +++ b/bench/commands/install.py @@ -1,10 +1,5 @@ -# imports - standard imports -import os -import sys -import json - # imports - module imports -from bench.utils import run_playbook, setup_sudoers, is_root +from bench.utils import run_playbook, setup_sudoers # imports - third party imports import click diff --git a/bench/commands/setup.py b/bench/commands/setup.py index c83633b5..b28e704c 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -61,11 +61,10 @@ def setup_fonts(): @click.option("--yes", help="Yes to regeneration config", is_flag=True, default=False) def setup_production(user, yes=False): from bench.config.production_setup import setup_production - from bench.utils import run_playbook # Install prereqs for production from distutils.spawn import find_executable if not find_executable("ansible"): - exec_cmd("sudo {0} install ansible".format("pip3" if PY3 else "pip2")) + exec_cmd("sudo -H {0} -m pip install ansible".format(sys.executable)) if not find_executable("fail2ban-client"): exec_cmd("bench setup role fail2ban") if not find_executable("nginx"): @@ -164,13 +163,19 @@ def setup_requirements(node=False, python=False): @click.option("--domain", help="Domain on which you want to run bench manager") def setup_manager(yes=False, port=23624, domain=None): from six.moves import input + from bench.utils import get_sites + from bench.config.common_site_config import get_config + from bench.config.nginx import make_bench_manager_nginx_conf + create_new_site = True + if "bench-manager.local" in os.listdir("sites"): ans = input("Site already exists. Overwrite existing site? [Y/n]: ").lower() while ans not in ("y", "n", ""): ans = input("Please enter 'y' or 'n'. Site already exists. Overwrite existing site? [Y/n]: ").lower() if ans == "n": create_new_site = False + if create_new_site: exec_cmd("bench new-site --force bench-manager.local") @@ -181,22 +186,18 @@ def setup_manager(yes=False, port=23624, domain=None): exec_cmd("bench --site bench-manager.local install-app bench_manager") - from bench.config.common_site_config import get_config bench_path = "." conf = get_config(bench_path) + if conf.get("restart_supervisor_on_update") or conf.get("restart_systemd_on_update"): # implicates a production setup or so I presume if not domain: print("Please specify the site name on which you want to host bench-manager using the 'domain' flag") sys.exit(1) - from bench.utils import get_sites, get_bench_name - bench_name = get_bench_name(bench_path) - if domain not in get_sites(bench_path): raise Exception("No such site") - from bench.config.nginx import make_bench_manager_nginx_conf make_bench_manager_nginx_conf(bench_path, yes=yes, port=port, domain=domain) diff --git a/bench/utils.py b/bench/utils.py index 35c1a319..72b69054 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -15,16 +15,13 @@ import shutil import site import subprocess import sys -import time from datetime import datetime from distutils.spawn import find_executable # imports - third party imports import click import requests -import semantic_version from six import iteritems -from six.moves import reload_module from six.moves.urllib.parse import urlparse # imports - module imports @@ -314,7 +311,6 @@ def exec_cmd(cmd, cwd='.'): def which(executable, raise_err = False): - from distutils.spawn import find_executable exec_ = find_executable(executable) if not exec_ and raise_err: