From a3dc9e69b77464dd1e855a52b4d7a3deafb262ef Mon Sep 17 00:00:00 2001 From: Development for People <47140294+developmentforpeople@users.noreply.github.com> Date: Sat, 9 Nov 2019 16:22:09 +0100 Subject: [PATCH 1/2] fix: bench.utils.get_sites updated to frappe.utils.get_sites avoids issues with non sites folder like 'jupyter_notebooks' --- bench/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 51aae64a..fd87e702 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -208,10 +208,15 @@ def build_assets(bench_path='.', app=None): exec_cmd(command, cwd=bench_path) def get_sites(bench_path='.'): - sites_dir = os.path.join(bench_path, "sites") - sites = [site for site in os.listdir(sites_dir) - if os.path.isdir(os.path.join(sites_dir, site)) and site not in ('assets',)] - return sites + sites_path = os.path.join(bench_path, 'sites') + sites = [] + for site in os.listdir(sites_path): + path = os.path.join(sites_path, site) + if (os.path.isdir(path) + and not os.path.islink(path) + and os.path.exists(os.path.join(path, 'site_config.json'))): + sites.append(site) + return sorted(sites) def get_sites_dir(bench_path='.'): return os.path.abspath(os.path.join(bench_path, 'sites')) From 8764813121152cb80fde403a21ab5f541074c525 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Jan 2020 18:30:31 +0530 Subject: [PATCH 2/2] fix: "faster" get_sites function chore: dropped unused get_sites_dir function style: pythonic "is not" usage --- bench/commands/utils.py | 2 +- bench/utils.py | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 9ba55bb8..b93d2f59 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -139,7 +139,7 @@ def shell(bench_path='.'): def backup_site(site): "backup site" from bench.utils import get_sites, backup_site - if not site in get_sites(bench_path='.'): + if site not in get_sites(bench_path='.'): print('site not found') sys.exit(1) backup_site(site, bench_path='.') diff --git a/bench/utils.py b/bench/utils.py index fd87e702..c706ed89 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -209,17 +209,8 @@ def build_assets(bench_path='.', app=None): def get_sites(bench_path='.'): sites_path = os.path.join(bench_path, 'sites') - sites = [] - for site in os.listdir(sites_path): - path = os.path.join(sites_path, site) - if (os.path.isdir(path) - and not os.path.islink(path) - and os.path.exists(os.path.join(path, 'site_config.json'))): - sites.append(site) - return sorted(sites) - -def get_sites_dir(bench_path='.'): - return os.path.abspath(os.path.join(bench_path, 'sites')) + sites = (site for site in os.listdir(sites_path) if os.path.exists(os.path.join(sites_path, site, 'site_config.json'))) + return sites def get_bench_dir(bench_path='.'): return os.path.abspath(bench_path) @@ -425,7 +416,7 @@ def restart_systemd_processes(bench_path='.', web_workers=False): exec_cmd('sudo systemctl start -- $(systemctl show -p Requires {bench_name}.target | cut -d= -f2)'.format(bench_name=bench_name)) def set_default_site(site, bench_path='.'): - if not site in get_sites(bench_path=bench_path): + if site not in get_sites(bench_path=bench_path): raise Exception("Site not in bench") exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site), cwd=os.path.join(bench_path, 'sites'))