2014-07-10 17:21:34 +00:00
|
|
|
import click
|
|
|
|
from .utils import init as _init
|
|
|
|
from .utils import setup_env as _setup_env
|
2014-07-11 04:29:57 +00:00
|
|
|
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
|
2014-07-15 09:18:50 +00:00
|
|
|
from .utils import start as _start
|
|
|
|
from .utils import setup_procfile as _setup_procfile
|
2014-07-21 04:45:18 +00:00
|
|
|
from .utils import set_nginx_port as _set_nginx_port
|
2014-07-21 06:18:07 +00:00
|
|
|
from .utils import set_default_site as _set_default_site
|
2014-07-22 06:38:17 +00:00
|
|
|
from .utils import build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements
|
2014-07-10 17:21:34 +00:00
|
|
|
from .app import get_app as _get_app
|
|
|
|
from .app import new_app as _new_app
|
|
|
|
from .app import pull_all_apps
|
2014-07-21 04:45:18 +00:00
|
|
|
from .config import generate_nginx_config, generate_supervisor_config
|
2014-07-10 17:21:34 +00:00
|
|
|
import os
|
2014-07-11 07:40:33 +00:00
|
|
|
import sys
|
2014-07-11 09:33:07 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger('bench')
|
2014-07-11 07:40:33 +00:00
|
|
|
|
|
|
|
def cli():
|
2014-07-15 06:17:36 +00:00
|
|
|
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
|
2014-07-11 07:40:33 +00:00
|
|
|
return frappe()
|
|
|
|
return bench()
|
|
|
|
|
|
|
|
def frappe(bench='.'):
|
|
|
|
f = get_frappe(bench=bench)
|
|
|
|
os.chdir(os.path.join(bench, 'sites'))
|
|
|
|
os.execv(f, [f] + sys.argv[2:])
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.group()
|
2014-07-11 09:33:07 +00:00
|
|
|
def bench(bench='.'):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Bench manager for Frappe"
|
2014-07-11 09:33:07 +00:00
|
|
|
# TODO add bench path context
|
|
|
|
setup_logging(bench=bench)
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.argument('path')
|
2014-07-21 06:10:03 +00:00
|
|
|
@click.option('--apps_path', default=None, help="path to json files with apps to install after init")
|
|
|
|
def init(path, apps_path):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Create a new bench"
|
2014-07-21 06:10:03 +00:00
|
|
|
_init(path, apps_path=apps_path)
|
2014-07-10 17:21:34 +00:00
|
|
|
click.echo('Bench {} initialized'.format(path))
|
|
|
|
|
|
|
|
@click.command('get-app')
|
|
|
|
@click.argument('name')
|
|
|
|
@click.argument('git-url')
|
|
|
|
def get_app(name, git_url):
|
2014-07-15 06:54:44 +00:00
|
|
|
"clone an app from the internet and set it up in your bench"
|
2014-07-10 17:21:34 +00:00
|
|
|
_get_app(name, git_url)
|
|
|
|
|
|
|
|
@click.command('new-app')
|
|
|
|
@click.argument('app-name')
|
|
|
|
def new_app(app_name):
|
2014-07-15 06:54:44 +00:00
|
|
|
"start a new app"
|
2014-07-10 17:21:34 +00:00
|
|
|
_new_app(app_name)
|
|
|
|
|
|
|
|
@click.command('new-site')
|
|
|
|
@click.argument('site')
|
|
|
|
def new_site(site):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Create a new site in the bench"
|
2014-07-10 17:21:34 +00:00
|
|
|
_new_site(site)
|
|
|
|
|
|
|
|
@click.command('update')
|
2014-07-15 06:54:44 +00:00
|
|
|
@click.option('--pull', flag_value=True, type=bool, help="Pull changes in all the apps in bench")
|
|
|
|
@click.option('--patch',flag_value=True, type=bool, help="Run migrations for all sites in the bench")
|
|
|
|
@click.option('--build',flag_value=True, type=bool, help="Build JS and CSS artifacts for the bench")
|
|
|
|
@click.option('--bench',flag_value=True, type=bool, help="Update bench")
|
2014-07-22 06:38:17 +00:00
|
|
|
@click.option('--requirements',flag_value=True, type=bool, help="Update requirements")
|
2014-07-15 06:54:44 +00:00
|
|
|
@click.option('--restart-supervisor',flag_value=True, type=bool, help="restart supervisor processes after update")
|
2014-07-15 06:17:36 +00:00
|
|
|
@click.option('--auto',flag_value=True, type=bool)
|
2014-07-22 06:38:17 +00:00
|
|
|
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Update bench"
|
2014-07-17 06:44:08 +00:00
|
|
|
|
2014-07-22 06:38:17 +00:00
|
|
|
if not (pull or patch or build or bench or requirements):
|
|
|
|
pull, patch, build, bench, requirements = True, True, True, True, True
|
2014-07-15 06:17:36 +00:00
|
|
|
|
|
|
|
conf = get_config()
|
|
|
|
if auto and not conf.get('auto_update'):
|
|
|
|
sys.exit(1)
|
|
|
|
if bench and conf.get('update_bench_on_update'):
|
2014-07-11 04:32:54 +00:00
|
|
|
update_bench()
|
2014-07-10 17:21:34 +00:00
|
|
|
if pull:
|
|
|
|
pull_all_apps()
|
2014-07-22 06:38:17 +00:00
|
|
|
if requirements:
|
|
|
|
update_requirements()
|
2014-07-10 17:21:34 +00:00
|
|
|
if patch:
|
|
|
|
patch_sites()
|
|
|
|
if build:
|
|
|
|
build_assets()
|
2014-07-22 06:38:17 +00:00
|
|
|
if restart_supervisor or conf.get('restart_supervisor_on_update'):
|
|
|
|
restart_supervisor_processes()
|
2014-07-17 06:44:08 +00:00
|
|
|
|
|
|
|
print "_"*80
|
|
|
|
print "https://frappe.io/buy - Donate to help make better free and open source tools"
|
|
|
|
print
|
2014-07-11 04:29:57 +00:00
|
|
|
|
|
|
|
@click.command('restart')
|
|
|
|
def restart():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Restart supervisor processes"
|
2014-07-16 06:24:02 +00:00
|
|
|
restart_supervisor_processes()
|
2014-07-10 17:21:34 +00:00
|
|
|
|
2014-07-15 09:18:50 +00:00
|
|
|
@click.command('start')
|
|
|
|
def start():
|
|
|
|
"Start Frappe development processes"
|
|
|
|
_start()
|
|
|
|
|
2014-07-17 09:38:26 +00:00
|
|
|
@click.command('migrate-3to4')
|
|
|
|
@click.argument('path')
|
|
|
|
def migrate_3to4(path):
|
|
|
|
"Migrate from ERPNext v3.x"
|
2014-07-21 10:45:32 +00:00
|
|
|
exec_cmd("{python} {migrate_3to4} {site}".format(
|
|
|
|
python=os.path.join('env', 'bin', 'python'),
|
|
|
|
migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'),
|
|
|
|
site=path))
|
2014-07-17 09:38:26 +00:00
|
|
|
|
2014-07-21 04:45:18 +00:00
|
|
|
@click.command('set-nginx-port')
|
|
|
|
@click.argument('site')
|
|
|
|
@click.argument('port', type=int)
|
|
|
|
def set_nginx_port(site, port):
|
|
|
|
"Set nginx port for site"
|
|
|
|
_set_nginx_port(site, port)
|
|
|
|
|
2014-07-21 06:18:07 +00:00
|
|
|
@click.command('set-default-site')
|
|
|
|
@click.argument('site')
|
|
|
|
def set_default_site(site):
|
|
|
|
"Set default site for bench"
|
|
|
|
_set_default_site(site)
|
|
|
|
|
2014-07-10 17:21:34 +00:00
|
|
|
## Setup
|
|
|
|
@click.group()
|
|
|
|
def setup():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Setup bench"
|
2014-07-10 17:21:34 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@click.command('sudoers')
|
|
|
|
def setup_sudoers():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Add commands to sudoers list for execution without password"
|
2014-07-11 04:29:57 +00:00
|
|
|
_setup_sudoers()
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command('nginx')
|
|
|
|
def setup_nginx():
|
2014-07-15 06:54:44 +00:00
|
|
|
"generate config for nginx"
|
2014-07-21 04:45:18 +00:00
|
|
|
generate_nginx_config()
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command('supervisor')
|
|
|
|
def setup_supervisor():
|
2014-07-15 06:54:44 +00:00
|
|
|
"generate config for supervisor"
|
2014-07-21 04:45:18 +00:00
|
|
|
generate_supervisor_config()
|
2014-07-17 10:16:17 +00:00
|
|
|
update_config({'restart_supervisor_on_update': True})
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command('auto-update')
|
|
|
|
def setup_auto_update():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Add cronjob for bench auto update"
|
2014-07-11 04:29:57 +00:00
|
|
|
_setup_auto_update()
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command('backups')
|
|
|
|
def setup_backups():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Add cronjob for bench backups"
|
2014-07-11 04:29:57 +00:00
|
|
|
_setup_backups()
|
2014-07-10 17:21:34 +00:00
|
|
|
|
|
|
|
@click.command('dnsmasq')
|
|
|
|
def setup_dnsmasq():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@click.command('env')
|
|
|
|
def setup_env():
|
2014-07-15 06:54:44 +00:00
|
|
|
"Setup virtualenv for bench"
|
2014-07-10 17:21:34 +00:00
|
|
|
_setup_env()
|
|
|
|
|
2014-07-15 09:18:50 +00:00
|
|
|
@click.command('procfile')
|
|
|
|
def setup_procfile():
|
|
|
|
"Setup Procfile for bench start"
|
|
|
|
_setup_procfile()
|
|
|
|
|
2014-07-21 09:41:32 +00:00
|
|
|
@click.command('config')
|
|
|
|
def setup_config():
|
|
|
|
"overwrite or make config.json"
|
|
|
|
put_config(default_config)
|
|
|
|
|
2014-07-10 17:21:34 +00:00
|
|
|
setup.add_command(setup_nginx)
|
|
|
|
setup.add_command(setup_sudoers)
|
|
|
|
setup.add_command(setup_supervisor)
|
|
|
|
setup.add_command(setup_auto_update)
|
|
|
|
setup.add_command(setup_dnsmasq)
|
|
|
|
setup.add_command(setup_backups)
|
|
|
|
setup.add_command(setup_env)
|
2014-07-15 09:18:50 +00:00
|
|
|
setup.add_command(setup_procfile)
|
2014-07-21 09:41:32 +00:00
|
|
|
setup.add_command(setup_config)
|
2014-07-10 17:21:34 +00:00
|
|
|
|
2014-07-15 06:17:36 +00:00
|
|
|
## Config
|
|
|
|
## Not DRY
|
|
|
|
@click.group()
|
|
|
|
def config():
|
2014-07-15 06:54:44 +00:00
|
|
|
"change bench configuration"
|
2014-07-15 06:17:36 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@click.command('auto_update')
|
|
|
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
|
|
|
def config_auto_update(state):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Enable/Disable auto update for bench"
|
2014-07-15 06:17:36 +00:00
|
|
|
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):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Enable/Disable auto restart of supervisor processes"
|
2014-07-15 06:17:36 +00:00
|
|
|
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):
|
2014-07-15 06:54:44 +00:00
|
|
|
"Enable/Disable bench updates on running bench update"
|
2014-07-15 06:17:36 +00:00
|
|
|
state = True if state == 'on' else False
|
|
|
|
update_config({'update_bench_on_update': state})
|
|
|
|
|
2014-07-21 04:45:18 +00:00
|
|
|
@click.command('dns_multitenant')
|
|
|
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
|
|
|
def config_dns_multitenant(state):
|
|
|
|
"Enable/Disable bench updates on running bench update"
|
|
|
|
state = True if state == 'on' else False
|
|
|
|
update_config({'dns_multitenant': state})
|
|
|
|
|
2014-07-25 06:45:16 +00:00
|
|
|
@click.command('serve_default_site')
|
|
|
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
|
|
|
def config_dns_multitenant(state):
|
|
|
|
"Configure nginx to serve the default site on port 80"
|
|
|
|
state = True if state == 'on' else False
|
|
|
|
update_config({'serve_default_site': state})
|
|
|
|
|
2014-07-15 06:17:36 +00:00
|
|
|
config.add_command(config_auto_update)
|
|
|
|
config.add_command(config_update_bench_on_update)
|
|
|
|
config.add_command(config_restart_supervisor_on_update)
|
2014-07-21 04:45:18 +00:00
|
|
|
config.add_command(config_dns_multitenant)
|
2014-07-15 06:17:36 +00:00
|
|
|
|
2014-07-10 17:21:34 +00:00
|
|
|
#Bench commands
|
|
|
|
|
|
|
|
bench.add_command(init)
|
|
|
|
bench.add_command(get_app)
|
|
|
|
bench.add_command(new_app)
|
|
|
|
bench.add_command(new_site)
|
|
|
|
bench.add_command(setup)
|
|
|
|
bench.add_command(update)
|
2014-07-11 04:29:57 +00:00
|
|
|
bench.add_command(restart)
|
2014-07-15 06:17:36 +00:00
|
|
|
bench.add_command(config)
|
2014-07-15 09:18:50 +00:00
|
|
|
bench.add_command(start)
|
2014-07-21 04:45:18 +00:00
|
|
|
bench.add_command(set_nginx_port)
|
2014-07-21 06:18:07 +00:00
|
|
|
bench.add_command(set_default_site)
|
2014-07-17 09:38:26 +00:00
|
|
|
bench.add_command(migrate_3to4)
|