mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
feat: added bench find command
This commit is contained in:
parent
e32281557f
commit
963b2f9ce5
@ -93,7 +93,7 @@ def get_frappe_commands(bench_path='.'):
|
||||
python = get_env_cmd('python', bench_path=bench_path)
|
||||
sites_path = os.path.join(bench_path, 'sites')
|
||||
if not os.path.exists(sites_path):
|
||||
log("WARN: Command not being executed in bench directory", level=3)
|
||||
log("Command not being executed in bench directory", level=3)
|
||||
return []
|
||||
try:
|
||||
output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)
|
||||
|
@ -47,7 +47,7 @@ bench_command.add_command(switch_to_develop)
|
||||
|
||||
from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root,
|
||||
set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt,
|
||||
disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host)
|
||||
disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host, find_benches)
|
||||
bench_command.add_command(start)
|
||||
bench_command.add_command(restart)
|
||||
bench_command.add_command(set_nginx_port)
|
||||
@ -68,6 +68,7 @@ bench_command.add_command(renew_lets_encrypt)
|
||||
bench_command.add_command(disable_production)
|
||||
bench_command.add_command(bench_src)
|
||||
bench_command.add_command(prepare_beta_release)
|
||||
bench_command.add_command(find_benches)
|
||||
|
||||
from bench.commands.setup import setup
|
||||
bench_command.add_command(setup)
|
||||
|
@ -190,3 +190,11 @@ def bench_src():
|
||||
"""Prints bench source folder path, which can be used as: cd `bench src` """
|
||||
import bench
|
||||
print(os.path.dirname(bench.__path__[0]))
|
||||
|
||||
|
||||
@click.command('find')
|
||||
@click.argument('location', default='')
|
||||
def find_benches(location):
|
||||
"""Finds benches recursively from location"""
|
||||
from bench.utils import find_benches
|
||||
find_benches(directory=location)
|
||||
|
@ -31,8 +31,8 @@ def log(message, level=0):
|
||||
levels = {
|
||||
0: '\033[94m', # normal
|
||||
1: '\033[92m', # success
|
||||
2: '\033[91m', # fail
|
||||
3: '\033[93m' # warn/suggest
|
||||
2: '\033[91mERROR: ', # fail
|
||||
3: '\033[93mWARN: ' # warn/suggest
|
||||
}
|
||||
start = levels.get(level) or ''
|
||||
end = '\033[0m'
|
||||
@ -872,3 +872,31 @@ def run_playbook(playbook_name, extra_vars=None, tag=None):
|
||||
args.extend(['-t', tag])
|
||||
|
||||
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
|
||||
|
||||
def find_benches(directory=None):
|
||||
if not directory:
|
||||
directory = os.path.expanduser("~")
|
||||
elif os.path.exists(directory):
|
||||
directory = os.path.abspath(directory)
|
||||
else:
|
||||
log("Directory doesn't exist", level=2)
|
||||
sys.exit(1)
|
||||
|
||||
if is_bench_directory(directory):
|
||||
if os.path.curdir == directory:
|
||||
print("You are in a bench directory!")
|
||||
else:
|
||||
print("{0} is a bench directory!".format(directory))
|
||||
return
|
||||
|
||||
benches = []
|
||||
for sub in os.listdir(directory):
|
||||
sub = os.path.join(directory, sub)
|
||||
if os.path.isdir(sub) and not os.path.islink(sub):
|
||||
if is_bench_directory(sub):
|
||||
print("{} found!".format(sub))
|
||||
benches.append(sub)
|
||||
else:
|
||||
benches.extend(find_benches(sub))
|
||||
|
||||
return benches
|
||||
|
Loading…
Reference in New Issue
Block a user