Beispiel #1
0
def update_esphome_core_repo():
    if CONF_REPOSITORY not in CORE.esphome_core_version:
        return

    if CONF_BRANCH not in CORE.esphome_core_version:
        # Git commit hash or tag cannot be updated
        return

    esphome_core_path = CORE.relative_piolibdeps_path('esphome-core')

    rc, _, _ = run_system_command('git', '-C', esphome_core_path, '--help')
    if rc != 0:
        # git not installed or repo not downloaded yet
        return
    rc, _, _ = run_system_command('git', '-C', esphome_core_path, 'diff-index',
                                  '--quiet', 'HEAD', '--')
    if rc != 0:
        # local changes, cannot update
        _LOGGER.warning(
            "Local changes in esphome-core copy from git. Will not auto-update."
        )
        return
    _LOGGER.info("Updating esphome-core copy from git (%s)", esphome_core_path)
    rc, stdout, _ = run_system_command('git', '-c', 'color.ui=always', '-C',
                                       esphome_core_path, 'pull', '--stat')
    if rc != 0:
        _LOGGER.warning("Couldn't auto-update local git copy of esphome-core.")
        return
    if IS_PY3:
        stdout = stdout.decode('utf-8', 'backslashreplace')
    safe_print(stdout.strip())
Beispiel #2
0
def clean_build():
    pioenvs = CORE.relative_pioenvs_path()
    if os.path.isdir(pioenvs):
        _LOGGER.info("Deleting %s", pioenvs)
        shutil.rmtree(pioenvs)
    piolibdeps = CORE.relative_piolibdeps_path()
    if os.path.isdir(piolibdeps):
        _LOGGER.info("Deleting %s", piolibdeps)
        shutil.rmtree(piolibdeps)
Beispiel #3
0
def run_platformio_cli(*args, **kwargs):
    os.environ["PLATFORMIO_FORCE_COLOR"] = "true"
    os.environ["PLATFORMIO_BUILD_DIR"] = os.path.abspath(
        CORE.relative_pioenvs_path())
    os.environ["PLATFORMIO_LIBDEPS_DIR"] = os.path.abspath(
        CORE.relative_piolibdeps_path())
    cmd = ['platformio'] + list(args)

    if os.environ.get('ESPHOME_USE_SUBPROCESS') is not None:
        return run_external_process(*cmd, **kwargs)

    import platformio.__main__
    patch_structhash()
    return run_external_command(platformio.__main__.main, *cmd, **kwargs)
Beispiel #4
0
def run_platformio_cli(*args, **kwargs) -> Union[str, int]:
    os.environ["PLATFORMIO_FORCE_COLOR"] = "true"
    os.environ["PLATFORMIO_BUILD_DIR"] = os.path.abspath(CORE.relative_pioenvs_path())
    os.environ.setdefault(
        "PLATFORMIO_LIBDEPS_DIR", os.path.abspath(CORE.relative_piolibdeps_path())
    )
    cmd = ["platformio"] + list(args)

    if not CORE.verbose:
        kwargs["filter_lines"] = FILTER_PLATFORMIO_LINES

    if os.environ.get("ESPHOME_USE_SUBPROCESS") is not None:
        return run_external_process(*cmd, **kwargs)

    import platformio.__main__

    patch_structhash()
    return run_external_command(platformio.__main__.main, *cmd, **kwargs)
Beispiel #5
0
def run_platformio_cli(*args, **kwargs):
    os.environ["PLATFORMIO_FORCE_COLOR"] = "true"
    os.environ["PLATFORMIO_BUILD_DIR"] = os.path.abspath(
        CORE.relative_pioenvs_path())
    os.environ["PLATFORMIO_LIBDEPS_DIR"] = os.path.abspath(
        CORE.relative_piolibdeps_path())
    cmd = ['platformio'] + list(args)

    if os.environ.get('ESPHOME_USE_SUBPROCESS') is None:
        import platformio.__main__
        try:
            if IS_PY2:
                patch_structhash()
        except Exception:  # pylint: disable=broad-except
            # Ignore when patch fails
            pass
        return run_external_command(platformio.__main__.main, *cmd, **kwargs)

    return run_external_process(*cmd, **kwargs)