2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 09:02:10 +00:00

async option in exec_cmd and cousin

This commit is contained in:
Rushabh Mehta 2015-07-28 14:39:02 +05:30
parent e15ea385d8
commit 0ff2561881
2 changed files with 34 additions and 10 deletions

View File

@ -63,9 +63,9 @@ def new_app(app, bench='.'):
apps = os.path.abspath(os.path.join(bench, 'apps')) apps = os.path.abspath(os.path.join(bench, 'apps'))
if FRAPPE_VERSION == 4: if FRAPPE_VERSION == 4:
exec_cmd("{frappe} --make_app {apps} {app}".format(frappe=get_frappe(bench=bench), exec_cmd("{frappe} --make_app {apps} {app}".format(frappe=get_frappe(bench=bench),
apps=apps, app=app)) apps=apps, app=app), async=False)
else: else:
run_frappe_cmd('make-app', apps, app, bench=bench) run_frappe_cmd('make-app', apps, app, bench=bench, async=False)
install_app(app, bench=bench) install_app(app, bench=bench)
def install_app(app, bench='.'): def install_app(app, bench='.'):

View File

@ -48,6 +48,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
from .app import get_app, install_apps_from_path from .app import get_app, install_apps_from_path
from .config import generate_redis_cache_config, generate_redis_async_broker_config from .config import generate_redis_cache_config, generate_redis_async_broker_config
global FRAPPE_VERSION global FRAPPE_VERSION
if os.path.exists(path): if os.path.exists(path):
print 'Directory {} already exists!'.format(path) print 'Directory {} already exists!'.format(path)
sys.exit(1) sys.exit(1)
@ -81,9 +82,19 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
generate_redis_cache_config(bench=path) generate_redis_cache_config(bench=path)
generate_redis_async_broker_config(bench=path) generate_redis_async_broker_config(bench=path)
def exec_cmd(cmd, cwd='.'): def exec_cmd(cmd, cwd='.', async=True):
p = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if async:
return_code = print_output(p) stderr = stdout = subprocess.PIPE
else:
stderr = stdout = None
p = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=stdout, stderr=stderr)
if async:
return_code = print_output(p)
else:
return_code = p.wait()
if return_code > 0: if return_code > 0:
raise CommandFailedError(cmd) raise CommandFailedError(cmd)
@ -107,6 +118,7 @@ def setup_procfile(with_celery_broker=False, with_watch=False, bench='.'):
procfile_contents['redis_cache'] = "redis-server config/redis_cache.conf" procfile_contents['redis_cache'] = "redis-server config/redis_cache.conf"
procfile_contents['redis_async_broker'] = "redis-server config/redis_async_broker.conf" procfile_contents['redis_async_broker'] = "redis-server config/redis_async_broker.conf"
procfile_contents['web'] = "bench serve" procfile_contents['web'] = "bench serve"
procfile_contents['socketio'] = "node apps/frappe/socketio.js"
procfile_contents['socketio'] = "./node_modules/.bin/nodemon apps/frappe/socketio.js" procfile_contents['socketio'] = "./node_modules/.bin/nodemon apps/frappe/socketio.js"
if with_celery_broker: if with_celery_broker:
procfile_contents['redis_celery'] = "redis-server" procfile_contents['redis_celery'] = "redis-server"
@ -448,8 +460,20 @@ def run_frappe_cmd(*args, **kwargs):
bench = kwargs.get('bench', '.') bench = kwargs.get('bench', '.')
f = get_env_cmd('python', bench=bench) f = get_env_cmd('python', bench=bench)
sites_dir = os.path.join(bench, 'sites') sites_dir = os.path.join(bench, 'sites')
p = subprocess.Popen((f, '-m', 'frappe.utils.bench_helper', 'frappe') + args, cwd=sites_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return_code = print_output(p) if kwargs.get('async'):
stderr = stdout = subprocess.PIPE
else:
stderr = stdout = None
p = subprocess.Popen((f, '-m', 'frappe.utils.bench_helper', 'frappe') + args,
cwd=sites_dir, stdout=stdout, stderr=stderr)
if kwargs.get('async'):
return_code = print_output(p)
else:
return_code = p.wait()
if return_code > 0: if return_code > 0:
raise CommandFailedError(args) raise CommandFailedError(args)