mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add helper code to run CLI commands
This commit is contained in:
parent
65c22bf488
commit
743b47de51
1 changed files with 18 additions and 2 deletions
|
@ -1654,8 +1654,24 @@ class VirtualEnv(object):
|
|||
def __exit__(self, *args):
|
||||
shutil.rmtree(self.venv_dir, ignore_errors=True)
|
||||
|
||||
def install(self, *args):
|
||||
subprocess.check_call([self.venv_python, "-m", "pip", "install"] + list(args))
|
||||
def install(self, *args, **kwargs):
|
||||
return self.run(self.venv_python, "-m", "pip", "install", *args, **kwargs)
|
||||
|
||||
def run(self, *args, **kwargs):
|
||||
kwargs.setdefault("cwd", self.venv_dir)
|
||||
kwargs.setdefault("check", True)
|
||||
kwargs.setdefault("stdout", subprocess.PIPE)
|
||||
kwargs.setdefault("stderr", subprocess.PIPE)
|
||||
kwargs.setdefault("universal_newlines", True)
|
||||
try:
|
||||
return subprocess.run( # pylint: disable=subprocess-run-check
|
||||
args, **kwargs
|
||||
)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
print(exc)
|
||||
print(exc.stdout)
|
||||
print(exc.stderr)
|
||||
raise
|
||||
|
||||
def _get_real_python(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue