mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 16:36:25 +00:00
refactor: bench.utils.exec_cmd
Refactoring the official way to run any commands through bench. Added a way to pass on envvars, and use the new log API w click ;)
This commit is contained in:
parent
ba289fba25
commit
93e5655570
@ -282,14 +282,17 @@ def clone_apps_from(bench_path, clone_from, update_app=True):
|
|||||||
setup_app(app)
|
setup_app(app)
|
||||||
|
|
||||||
|
|
||||||
def exec_cmd(cmd, cwd='.'):
|
def exec_cmd(cmd, cwd='.', env=None):
|
||||||
import shlex
|
if env:
|
||||||
print(f"{color.silver}$ {cmd}{color.nc}")
|
env.update(os.environ.copy())
|
||||||
|
|
||||||
|
click.secho(f"$ {cmd}", fg='bright_black')
|
||||||
|
|
||||||
cwd_info = f"cd {cwd} && " if cwd != "." else ""
|
cwd_info = f"cd {cwd} && " if cwd != "." else ""
|
||||||
cmd_log = f"{cwd_info}{cmd}"
|
cmd_log = f"{cwd_info}{cmd}"
|
||||||
logger.debug(cmd_log)
|
logger.debug(cmd_log)
|
||||||
cmd = shlex.split(cmd)
|
cmd = split(cmd)
|
||||||
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True)
|
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True, env=env)
|
||||||
if return_code:
|
if return_code:
|
||||||
logger.warning(f"{cmd_log} executed with exit code {return_code}")
|
logger.warning(f"{cmd_log} executed with exit code {return_code}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user