mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Revert "Use enviornment variable"
This reverts commit 7f038eb5d26df72f76ea9ae76774e2cec1fd7f59.
This commit is contained in:
parent
29015d0c3a
commit
ddbb6d064d
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -14,7 +13,6 @@ 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,6 +48,18 @@ 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)
|
||||||
@ -57,6 +69,9 @@ 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()
|
||||||
@ -76,6 +91,11 @@ 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…
x
Reference in New Issue
Block a user