mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
Use enviornment variable
This commit is contained in:
parent
7354551954
commit
7f038eb5d2
@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ def run_platformio_cli(*args, **kwargs):
|
|||||||
import platformio.__main__
|
import platformio.__main__
|
||||||
|
|
||||||
cmd = ['platformio'] + list(args)
|
cmd = ['platformio'] + list(args)
|
||||||
|
os.environ["PLATFORMIO_FORCE_COLOR"] = 'true'
|
||||||
return run_external_command(platformio.__main__.main,
|
return run_external_command(platformio.__main__.main,
|
||||||
*cmd, **kwargs)
|
*cmd, **kwargs)
|
||||||
|
|
||||||
|
@ -48,18 +48,6 @@ def shlex_quote(s):
|
|||||||
return u"'" + s.replace(u"'", u"'\"'\"'") + u"'"
|
return u"'" + s.replace(u"'", u"'\"'\"'") + u"'"
|
||||||
|
|
||||||
|
|
||||||
class RedirectText(object):
|
|
||||||
def __init__(self, out):
|
|
||||||
self._out = out
|
|
||||||
|
|
||||||
def __getattr__(self, item):
|
|
||||||
return getattr(self._out, item)
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
|
||||||
def isatty(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def run_external_command(func, *cmd, **kwargs):
|
def run_external_command(func, *cmd, **kwargs):
|
||||||
def mock_exit(return_code):
|
def mock_exit(return_code):
|
||||||
raise SystemExit(return_code)
|
raise SystemExit(return_code)
|
||||||
@ -69,9 +57,6 @@ def run_external_command(func, *cmd, **kwargs):
|
|||||||
full_cmd = u' '.join(shlex_quote(x) for x in cmd)
|
full_cmd = u' '.join(shlex_quote(x) for x in cmd)
|
||||||
_LOGGER.info(u"Running: %s", full_cmd)
|
_LOGGER.info(u"Running: %s", full_cmd)
|
||||||
|
|
||||||
sys.stdout = RedirectText(sys.stdout)
|
|
||||||
sys.stderr = RedirectText(sys.stderr)
|
|
||||||
|
|
||||||
capture_stdout = kwargs.get('capture_stdout', False)
|
capture_stdout = kwargs.get('capture_stdout', False)
|
||||||
if capture_stdout:
|
if capture_stdout:
|
||||||
sys.stdout = io.BytesIO()
|
sys.stdout = io.BytesIO()
|
||||||
@ -91,11 +76,6 @@ def run_external_command(func, *cmd, **kwargs):
|
|||||||
sys.argv = orig_argv
|
sys.argv = orig_argv
|
||||||
sys.exit = orig_exit
|
sys.exit = orig_exit
|
||||||
|
|
||||||
if isinstance(sys.stdout, RedirectText):
|
|
||||||
sys.stdout = sys.__stdout__
|
|
||||||
if isinstance(sys.stderr, RedirectText):
|
|
||||||
sys.stderr = sys.__stderr__
|
|
||||||
|
|
||||||
if capture_stdout:
|
if capture_stdout:
|
||||||
# pylint: disable=lost-exception
|
# pylint: disable=lost-exception
|
||||||
stdout = sys.stdout.getvalue()
|
stdout = sys.stdout.getvalue()
|
||||||
|
Loading…
Reference in New Issue
Block a user