mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
call platformio and esptool using subprocess if $ESPHOME_USE_SUBPROCESS is set (#359)
* call platformio and esptool using subprocess if $ESPHOME_USE_SUBPROCESS is set * Update setup.py
This commit is contained in:
parent
c86675f644
commit
d799c03f0c
4 changed files with 52 additions and 12 deletions
|
@ -19,7 +19,7 @@ from esphomeyaml.helpers import color, indent
|
|||
from esphomeyaml.py_compat import safe_input, text_type, IS_PY2
|
||||
from esphomeyaml.storage_json import StorageJSON, esphomeyaml_storage_path, \
|
||||
start_update_check_thread, storage_path
|
||||
from esphomeyaml.util import run_external_command, safe_print
|
||||
from esphomeyaml.util import run_external_command, run_external_process, safe_print
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -167,13 +167,16 @@ def compile_program(args, config):
|
|||
|
||||
|
||||
def upload_using_esptool(config, port):
|
||||
import esptool
|
||||
|
||||
path = os.path.join(CORE.build_path, '.pioenvs', CORE.name, 'firmware.bin')
|
||||
cmd = ['esptool.py', '--before', 'default_reset', '--after', 'hard_reset',
|
||||
'--chip', 'esp8266', '--port', port, 'write_flash', '0x0', path]
|
||||
# pylint: disable=protected-access
|
||||
return run_external_command(esptool._main, *cmd)
|
||||
|
||||
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
|
||||
import esptool
|
||||
# pylint: disable=protected-access
|
||||
return run_external_command(esptool._main, *cmd)
|
||||
|
||||
return run_external_process(*cmd)
|
||||
|
||||
|
||||
def upload_program(config, args, host):
|
||||
|
|
|
@ -7,18 +7,21 @@ import re
|
|||
import subprocess
|
||||
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.util import run_external_command
|
||||
from esphomeyaml.util import run_external_command, run_external_process
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_platformio_cli(*args, **kwargs):
|
||||
import platformio.__main__
|
||||
|
||||
os.environ["PLATFORMIO_FORCE_COLOR"] = "true"
|
||||
cmd = ['platformio'] + list(args)
|
||||
return run_external_command(platformio.__main__.main,
|
||||
*cmd, **kwargs)
|
||||
|
||||
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
|
||||
import platformio.__main__
|
||||
return run_external_command(platformio.__main__.main,
|
||||
*cmd, **kwargs)
|
||||
|
||||
return run_external_process(*cmd, **kwargs)
|
||||
|
||||
|
||||
def run_platformio_cli_run(config, verbose, *args, **kwargs):
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import print_function
|
|||
import io
|
||||
import logging
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -121,3 +122,28 @@ def run_external_command(func, *cmd, **kwargs):
|
|||
if capture_stdout:
|
||||
# pylint: disable=lost-exception
|
||||
return cap_stdout.getvalue()
|
||||
|
||||
|
||||
def run_external_process(*cmd, **kwargs):
|
||||
full_cmd = u' '.join(shlex_quote(x) for x in cmd)
|
||||
_LOGGER.info(u"Running: %s", full_cmd)
|
||||
|
||||
capture_stdout = kwargs.get('capture_stdout', False)
|
||||
if capture_stdout:
|
||||
sub_stdout = io.BytesIO()
|
||||
else:
|
||||
sub_stdout = RedirectText(sys.stdout)
|
||||
|
||||
sub_stderr = RedirectText(sys.stderr)
|
||||
|
||||
try:
|
||||
return subprocess.call(cmd,
|
||||
stdout=sub_stdout,
|
||||
stderr=sub_stderr)
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.error(u"Running command failed: %s", err)
|
||||
_LOGGER.error(u"Please try running %s locally.", full_cmd)
|
||||
finally:
|
||||
if capture_stdout:
|
||||
# pylint: disable=lost-exception
|
||||
return sub_stdout.getvalue()
|
||||
|
|
12
setup.py
12
setup.py
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
"""esphomeyaml setup script."""
|
||||
from setuptools import setup, find_packages
|
||||
import os
|
||||
|
||||
from esphomeyaml import const
|
||||
|
||||
|
@ -23,18 +24,25 @@ DOWNLOAD_URL = '{}/archive/{}.zip'.format(GITHUB_URL, const.__version__)
|
|||
|
||||
REQUIRES = [
|
||||
'voluptuous>=0.11.1',
|
||||
'platformio>=3.5.3',
|
||||
'pyyaml>=3.12',
|
||||
'paho-mqtt>=1.3.1',
|
||||
'colorlog>=3.1.2',
|
||||
'tornado>=5.0.0',
|
||||
'esptool>=2.3.1',
|
||||
'typing>=3.0.0;python_version<"3.5"',
|
||||
'protobuf>=3.4',
|
||||
'tzlocal>=1.4',
|
||||
'pyserial>=3.4,<4',
|
||||
]
|
||||
|
||||
# If you have problems importing platformio and esptool as modules you can set
|
||||
# $ESPHOME_USE_SUBPROCESS to make ESPHome call their executables instead.
|
||||
# This means they have to be in your $PATH.
|
||||
if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
|
||||
REQUIRES.extend([
|
||||
'platformio>=3.5.3',
|
||||
'esptool>=2.3.1',
|
||||
])
|
||||
|
||||
CLASSIFIERS = [
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Developers',
|
||||
|
|
Loading…
Reference in a new issue