2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-23 15:08:24 +00:00

fix: "faster" get_sites function

chore: dropped unused get_sites_dir function
style: pythonic "is not" usage
This commit is contained in:
Gavin D'souza 2020-01-02 18:30:31 +05:30
parent a3dc9e69b7
commit 8764813121
2 changed files with 4 additions and 13 deletions

View File

@ -139,7 +139,7 @@ def shell(bench_path='.'):
def backup_site(site): def backup_site(site):
"backup site" "backup site"
from bench.utils import get_sites, 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') print('site not found')
sys.exit(1) sys.exit(1)
backup_site(site, bench_path='.') backup_site(site, bench_path='.')

View File

@ -209,17 +209,8 @@ def build_assets(bench_path='.', app=None):
def get_sites(bench_path='.'): def get_sites(bench_path='.'):
sites_path = os.path.join(bench_path, 'sites') sites_path = os.path.join(bench_path, 'sites')
sites = [] sites = (site for site in os.listdir(sites_path) if os.path.exists(os.path.join(sites_path, site, 'site_config.json')))
for site in os.listdir(sites_path): return sites
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'))
def get_bench_dir(bench_path='.'): def get_bench_dir(bench_path='.'):
return os.path.abspath(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)) 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='.'): 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") raise Exception("Site not in bench")
exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site), exec_cmd("{frappe} --use {site}".format(frappe=get_frappe(bench_path=bench_path), site=site),
cwd=os.path.join(bench_path, 'sites')) cwd=os.path.join(bench_path, 'sites'))