Пример #1
0
def configure():
    if CYGWIN:
        raise exception.CygwinEnvDetected()

    # https://urllib3.readthedocs.org
    # /en/latest/security.html#insecureplatformwarning
    try:
        import urllib3
        urllib3.disable_warnings()
    except (AttributeError, ImportError):
        pass

    try:
        if str(os.getenv("PLATFORMIO_DISABLE_COLOR", "")).lower() == "true":
            # pylint: disable=protected-access
            click._compat.isatty = lambda stream: False
        elif str(os.getenv("PLATFORMIO_FORCE_COLOR", "")).lower() == "true":
            # pylint: disable=protected-access
            click._compat.isatty = lambda stream: True
    except:  # pylint: disable=bare-except
        pass

    # Handle IOError issue with VSCode's Terminal (Windows)
    click_echo_origin = [click.echo, click.secho]

    def _safe_echo(origin, *args, **kwargs):
        try:
            click_echo_origin[origin](*args, **kwargs)
        except IOError:
            (sys.stderr.write if kwargs.get("err") else sys.stdout.write)(
                "%s\n" % (args[0] if args else ""))

    click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs)
    click.secho = lambda *args, **kwargs: _safe_echo(1, *args, **kwargs)
Пример #2
0
def main():
    try:
        if "cygwin" in system().lower():
            raise exception.CygwinEnvDetected()

        # https://urllib3.readthedocs.org
        # /en/latest/security.html#insecureplatformwarning
        try:
            requests.packages.urllib3.disable_warnings()
        except AttributeError:
            raise exception.PlatformioException(
                "Invalid installation of Python `requests` package`. See "
                "< https://github.com/platformio/platformio/issues/252 >")

        cli(None, None, None)
    except Exception as e:  # pylint: disable=W0703
        if not isinstance(e, exception.ReturnErrorCode):
            maintenance.on_platformio_exception(e)
            error_str = "Error: "
            if isinstance(e, exception.PlatformioException):
                error_str += str(e)
            else:
                error_str += format_exc()
            click.secho(error_str, fg="red", err=True)
        return 1
    return 0
Пример #3
0
def configure():
    if CYGWIN:
        raise exception.CygwinEnvDetected()

    # https://urllib3.readthedocs.org
    # /en/latest/security.html#insecureplatformwarning
    try:
        import urllib3  # pylint: disable=import-outside-toplevel

        urllib3.disable_warnings()
    except (AttributeError, ImportError):
        pass

    # Handle IOError issue with VSCode's Terminal (Windows)
    click_echo_origin = [click.echo, click.secho]

    def _safe_echo(origin, *args, **kwargs):
        try:
            click_echo_origin[origin](*args, **kwargs)
        except IOError:
            (sys.stderr.write if kwargs.get("err") else sys.stdout.write)(
                "%s\n" % (args[0] if args else ""))

    click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs)
    click.secho = lambda *args, **kwargs: _safe_echo(1, *args, **kwargs)
Пример #4
0
def main():
    try:
        if "cygwin" in system().lower():
            raise exception.CygwinEnvDetected()

        # https://urllib3.readthedocs.org
        # /en/latest/security.html#insecureplatformwarning
        try:
            requests.packages.urllib3.disable_warnings()
        except AttributeError:
            raise exception.PlatformioException(
                "Invalid installation of Python `requests` package`. See "
                "< https://github.com/platformio/platformio/issues/252 >")

        # handle PLATFORMIO_FORCE_COLOR
        if str(getenv("PLATFORMIO_FORCE_COLOR", "")).lower() == "true":
            try:
                # pylint: disable=protected-access
                click._compat.isatty = lambda stream: True
            except:  # pylint: disable=bare-except
                pass

        cli(None, None, None)
    except Exception as e:  # pylint: disable=W0703
        if not isinstance(e, exception.ReturnErrorCode):
            maintenance.on_platformio_exception(e)
            error_str = "Error: "
            if isinstance(e, exception.PlatformioException):
                error_str += str(e)
            else:
                error_str += format_exc()
                error_str += """
============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  http://docs.platformio.org/en/stable/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio/issues

============================================================
"""
            click.secho(error_str, fg="red", err=True)
        return 1
    return 0