mirror of
https://github.com/frappe/bench.git
synced 2024-11-16 01:57:08 +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)
|
||||
|
||||
|
||||
def exec_cmd(cmd, cwd='.'):
|
||||
import shlex
|
||||
print(f"{color.silver}$ {cmd}{color.nc}")
|
||||
def exec_cmd(cmd, cwd='.', env=None):
|
||||
if env:
|
||||
env.update(os.environ.copy())
|
||||
|
||||
click.secho(f"$ {cmd}", fg='bright_black')
|
||||
|
||||
cwd_info = f"cd {cwd} && " if cwd != "." else ""
|
||||
cmd_log = f"{cwd_info}{cmd}"
|
||||
logger.debug(cmd_log)
|
||||
cmd = shlex.split(cmd)
|
||||
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True)
|
||||
cmd = split(cmd)
|
||||
return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True, env=env)
|
||||
if return_code:
|
||||
logger.warning(f"{cmd_log} executed with exit code {return_code}")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user