Skip to content

Commit

Permalink
fix: "faster" get_sites function
Browse files Browse the repository at this point in the history
chore: dropped unused get_sites_dir function
style: pythonic "is not" usage
  • Loading branch information
gavindsouza committed Jan 2, 2020
1 parent a3dc9e6 commit 8764813
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bench/commands/utils.py
Expand Up @@ -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='.')
Expand Down
15 changes: 3 additions & 12 deletions bench/utils.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 8764813

Please sign in to comment.