mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
add more config options
This commit is contained in:
parent
808fc386c0
commit
49707d56b0
45
bench/cli.py
45
bench/cli.py
@ -5,7 +5,7 @@ from .utils import new_site as _new_site
|
|||||||
from .utils import setup_backups as _setup_backups
|
from .utils import setup_backups as _setup_backups
|
||||||
from .utils import setup_auto_update as _setup_auto_update
|
from .utils import setup_auto_update as _setup_auto_update
|
||||||
from .utils import setup_sudoers as _setup_sudoers
|
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 get_app as _get_app
|
||||||
from .app import new_app as _new_app
|
from .app import new_app as _new_app
|
||||||
from .app import pull_all_apps
|
from .app import pull_all_apps
|
||||||
@ -17,7 +17,7 @@ import logging
|
|||||||
logger = logging.getLogger('bench')
|
logger = logging.getLogger('bench')
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
if sys.argv[1] == "frappe":
|
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
|
||||||
return frappe()
|
return frappe()
|
||||||
return bench()
|
return bench()
|
||||||
|
|
||||||
@ -58,10 +58,16 @@ def new_site(site):
|
|||||||
@click.option('--patch',flag_value=True, type=bool)
|
@click.option('--patch',flag_value=True, type=bool)
|
||||||
@click.option('--build',flag_value=True, type=bool)
|
@click.option('--build',flag_value=True, type=bool)
|
||||||
@click.option('--bench',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):
|
if not (pull or patch or build or bench):
|
||||||
pull, patch, build, bench = True, True, True, True
|
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()
|
update_bench()
|
||||||
if pull:
|
if pull:
|
||||||
pull_all_apps()
|
pull_all_apps()
|
||||||
@ -69,6 +75,8 @@ def update(pull=False, patch=False, build=False, bench=False):
|
|||||||
patch_sites()
|
patch_sites()
|
||||||
if build:
|
if build:
|
||||||
build_assets()
|
build_assets()
|
||||||
|
if restart_supervisor or conf.get('restart_supervisor_on_update'):
|
||||||
|
restart()
|
||||||
|
|
||||||
@click.command('restart')
|
@click.command('restart')
|
||||||
def restart():
|
def restart():
|
||||||
@ -115,6 +123,34 @@ setup.add_command(setup_dnsmasq)
|
|||||||
setup.add_command(setup_backups)
|
setup.add_command(setup_backups)
|
||||||
setup.add_command(setup_env)
|
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 commands
|
||||||
|
|
||||||
bench.add_command(init)
|
bench.add_command(init)
|
||||||
@ -124,4 +160,5 @@ bench.add_command(new_site)
|
|||||||
bench.add_command(setup)
|
bench.add_command(setup)
|
||||||
bench.add_command(update)
|
bench.add_command(update)
|
||||||
bench.add_command(restart)
|
bench.add_command(restart)
|
||||||
|
bench.add_command(config)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
default_config = {
|
default_config = {
|
||||||
'restart_supervisor_on_update': True,
|
'restart_supervisor_on_update': True,
|
||||||
|
'auto_update': True,
|
||||||
'update_bench_on_update': True
|
'update_bench_on_update': True
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ def get_bench_dir(bench='.'):
|
|||||||
|
|
||||||
def setup_auto_update(bench='.'):
|
def setup_auto_update(bench='.'):
|
||||||
logger.info('setting up auto update')
|
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')))
|
bench=os.path.join(get_bench_dir(bench=bench), 'env', 'bin', 'bench')))
|
||||||
|
|
||||||
def setup_backups(bench='.'):
|
def setup_backups(bench='.'):
|
||||||
@ -109,3 +110,8 @@ def get_config(bench='.'):
|
|||||||
def put_config(config, bench='.'):
|
def put_config(config, bench='.'):
|
||||||
with open(os.path.join(bench, 'config.json'), 'w') as f:
|
with open(os.path.join(bench, 'config.json'), 'w') as f:
|
||||||
return json.dump(config, 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user