mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 09:02:10 +00:00
[command] bench config set-common-config / remove-common-config
bench config set-common-config --config KEY1 VAL1 --config KEY2 VAL2 ... bench config remove-common-config KEY1 KEY2 ...
This commit is contained in:
parent
62d20c9699
commit
012be92f09
@ -1,4 +1,4 @@
|
||||
import click
|
||||
import click, json
|
||||
from bench.config.common_site_config import update_config
|
||||
|
||||
## Config
|
||||
@ -8,7 +8,6 @@ def config():
|
||||
"change bench configuration"
|
||||
pass
|
||||
|
||||
|
||||
@click.command('auto_update')
|
||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||
def config_auto_update(state):
|
||||
@ -64,9 +63,57 @@ def config_http_timeout(seconds):
|
||||
update_config({'http_timeout': seconds})
|
||||
|
||||
|
||||
@click.command('set-common-config')
|
||||
@click.option('configs', '-c', '--config', multiple=True, type=(unicode, unicode))
|
||||
def set_common_config(configs):
|
||||
import ast
|
||||
from bench.config.common_site_config import update_config
|
||||
|
||||
common_site_config = {}
|
||||
for key, value in configs:
|
||||
if value in ("False", "True"):
|
||||
value = ast.literal_eval(value)
|
||||
|
||||
elif "." in value:
|
||||
try:
|
||||
value = float(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
elif "{" in value or "[" in value:
|
||||
try:
|
||||
value = json.loads(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
else:
|
||||
try:
|
||||
value = int(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
common_site_config[key] = value
|
||||
|
||||
update_config(common_site_config, bench_path='.')
|
||||
|
||||
|
||||
@click.command('remove-common-config')
|
||||
@click.argument('keys', nargs=-1)
|
||||
def remove_common_config(keys):
|
||||
from bench.config.common_site_config import get_config, put_config
|
||||
common_site_config = get_config('.')
|
||||
for key in keys:
|
||||
if key in common_site_config:
|
||||
del common_site_config[key]
|
||||
|
||||
put_config(common_site_config)
|
||||
|
||||
|
||||
config.add_command(config_auto_update)
|
||||
config.add_command(config_update_bench_on_update)
|
||||
config.add_command(config_restart_supervisor_on_update)
|
||||
config.add_command(config_dns_multitenant)
|
||||
config.add_command(config_serve_default_site)
|
||||
config.add_command(config_http_timeout)
|
||||
config.add_command(set_common_config)
|
||||
config.add_command(remove_common_config)
|
||||
|
Loading…
Reference in New Issue
Block a user