2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-13 16:56:33 +00:00

add more config options

This commit is contained in:
Pratik Vyas 2014-07-15 11:47:36 +05:30
parent 808fc386c0
commit 49707d56b0
2 changed files with 48 additions and 5 deletions

View File

@ -5,7 +5,7 @@ from .utils import new_site as _new_site
from .utils import setup_backups as _setup_backups
from .utils import setup_auto_update as _setup_auto_update
from .utils import setup_sudoers as _setup_sudoers
from .utils import build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config
from .utils import build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config, update_config
from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps
@ -17,7 +17,7 @@ import logging
logger = logging.getLogger('bench')
def cli():
if sys.argv[1] == "frappe":
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
return frappe()
return bench()
@ -58,10 +58,16 @@ def new_site(site):
@click.option('--patch',flag_value=True, type=bool)
@click.option('--build',flag_value=True, type=bool)
@click.option('--bench',flag_value=True, type=bool)
def update(pull=False, patch=False, build=False, bench=False):
@click.option('--restart-supervisor',flag_value=True, type=bool)
@click.option('--auto',flag_value=True, type=bool)
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False):
if not (pull or patch or build or bench):
pull, patch, build, bench = True, True, True, True
if bench and get_config().get('update_bench_on_update'):
conf = get_config()
if auto and not conf.get('auto_update'):
sys.exit(1)
if bench and conf.get('update_bench_on_update'):
update_bench()
if pull:
pull_all_apps()
@ -69,6 +75,8 @@ def update(pull=False, patch=False, build=False, bench=False):
patch_sites()
if build:
build_assets()
if restart_supervisor or conf.get('restart_supervisor_on_update'):
restart()
@click.command('restart')
def restart():
@ -115,6 +123,34 @@ setup.add_command(setup_dnsmasq)
setup.add_command(setup_backups)
setup.add_command(setup_env)
## Config
## Not DRY
@click.group()
def config():
pass
@click.command('auto_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_auto_update(state):
state = True if state == 'on' else False
update_config({'auto_update': state})
@click.command('restart_supervisor_on_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_restart_supervisor_on_update(state):
state = True if state == 'on' else False
update_config({'restart_supervisor_on_update': state})
@click.command('update_bench_on_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_update_bench_on_update(state):
state = True if state == 'on' else False
update_config({'update_bench_on_update': state})
config.add_command(config_auto_update)
config.add_command(config_update_bench_on_update)
config.add_command(config_restart_supervisor_on_update)
#Bench commands
bench.add_command(init)
@ -124,4 +160,5 @@ bench.add_command(new_site)
bench.add_command(setup)
bench.add_command(update)
bench.add_command(restart)
bench.add_command(config)

View File

@ -9,6 +9,7 @@ logger = logging.getLogger(__name__)
default_config = {
'restart_supervisor_on_update': True,
'auto_update': True,
'update_bench_on_update': True
}
@ -73,7 +74,7 @@ def get_bench_dir(bench='.'):
def setup_auto_update(bench='.'):
logger.info('setting up auto update')
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 10 * * * cd {bench_dir} && {bench} update\" | grep -v "^$" | uniq | crontab'.format(bench_dir=get_bench_dir(bench=bench),
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 10 * * * cd {bench_dir} && {bench} update --auto\" | grep -v "^$" | uniq | crontab'.format(bench_dir=get_bench_dir(bench=bench),
bench=os.path.join(get_bench_dir(bench=bench), 'env', 'bin', 'bench')))
def setup_backups(bench='.'):
@ -109,3 +110,8 @@ def get_config(bench='.'):
def put_config(config, bench='.'):
with open(os.path.join(bench, 'config.json'), 'w') as f:
return json.dump(config, f)
def update_config(new_config, bench='.'):
config = get_config(bench=bench)
config.update(new_config)
put_config(config, bench=bench)