def get_project_build_data(self):
        data = {"defines": [], "includes": [], "cxx_path": None}
        envdata = self.get_project_env()
        if "env_name" not in envdata:
            return data
        cmd = [
            normpath(sys.executable), "-m",
            "platformio" + (".__main__" if sys.version_info <
                            (2, 7, 0) else ""), "-f"
        ]
        if app.get_session_var("caller_id"):
            cmd.extend(["-c", app.get_session_var("caller_id")])
        cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
        cmd.extend(["-d", self.project_dir])
        result = util.exec_command(cmd)

        if result['returncode'] != 0 or '"includes":' not in result['out']:
            raise exception.PlatformioException("\n".join(
                [result['out'], result['err']]))

        output = result['out']
        start_index = output.index('{"')
        stop_index = output.rindex('}')
        data = json.loads(output[start_index:stop_index + 1])

        return data
示例#2
0
    def get_project_build_data(self):
        data = {
            "defines": [],
            "includes": [],
            "cxx_path": None
        }
        envdata = self.get_project_env()
        if "env_name" not in envdata:
            return data
        cmd = [
            normpath(sys.executable), "-m",
            "platformio" + (
                ".__main__" if sys.version_info < (2, 7, 0) else ""),
            "-f"
        ]
        if app.get_session_var("caller_id"):
            cmd.extend(["-c", app.get_session_var("caller_id")])
        cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
        cmd.extend(["-d", self.project_dir])
        result = util.exec_command(cmd)

        if result['returncode'] != 0 or '"includes":' not in result['out']:
            raise exception.PlatformioException(
                "\n".join([result['out'], result['err']]))

        output = result['out']
        start_index = output.index('{"')
        stop_index = output.rindex('}')
        data = json.loads(output[start_index:stop_index + 1])

        return data
示例#3
0
 def _prefill_custom_data(self):
     self['cd1'] = util.get_systype()
     self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                     platform.platform())
     self['cd4'] = 1 if not util.is_ci() else 0
     if app.get_session_var("caller_id"):
         self['cd5'] = str(app.get_session_var("caller_id")).lower()
示例#4
0
    def _prefill_screen_name(self):
        def _first_arg_from_list(args_, list_):
            for _arg in args_:
                if _arg in list_:
                    return _arg
            return None

        self['cd3'] = " ".join([str(s).lower() for s in sys.argv[1:]])
        if not app.get_session_var("command_ctx"):
            return
        ctx_args = app.get_session_var("command_ctx").args
        args = [str(s).lower() for s in ctx_args if not str(s).startswith("-")]
        if not args:
            return
        cmd_path = args[:1]
        if args[0] in ("platform", "platforms", "serialports", "device",
                       "settings", "account"):
            cmd_path = args[:2]
        if args[0] == "lib" and len(args) > 1:
            lib_subcmds = ("builtin", "install", "list", "register", "search",
                           "show", "stats", "uninstall", "update")
            sub_cmd = _first_arg_from_list(args[1:], lib_subcmds)
            if sub_cmd:
                cmd_path.append(sub_cmd)
        elif args[0] == "remote" and len(args) > 1:
            remote_subcmds = ("agent", "device", "run", "test")
            sub_cmd = _first_arg_from_list(args[1:], remote_subcmds)
            if sub_cmd:
                cmd_path.append(sub_cmd)
                if len(args) > 2 and sub_cmd in ("agent", "device"):
                    remote2_subcmds = ("list", "start", "monitor")
                    sub_cmd = _first_arg_from_list(args[2:], remote2_subcmds)
                    if sub_cmd:
                        cmd_path.append(sub_cmd)
        self['screen_name'] = " ".join([p.title() for p in cmd_path])
示例#5
0
    def _prefill_screen_name(self):

        def _first_arg_from_list(args_, list_):
            for _arg in args_:
                if _arg in list_:
                    return _arg
            return None

        if not app.get_session_var("command_ctx"):
            return
        ctx_args = app.get_session_var("command_ctx").args
        args = [str(s).lower() for s in ctx_args if not str(s).startswith("-")]
        if not args:
            return
        cmd_path = args[:1]
        if args[0] in ("platform", "platforms", "serialports", "device",
                       "settings", "account"):
            cmd_path = args[:2]
        if args[0] == "lib" and len(args) > 1:
            lib_subcmds = ("builtin", "install", "list", "register", "search",
                           "show", "stats", "uninstall", "update")
            sub_cmd = _first_arg_from_list(args[1:], lib_subcmds)
            if sub_cmd:
                cmd_path.append(sub_cmd)
        elif args[0] == "remote" and len(args) > 1:
            remote_subcmds = ("agent", "device", "run", "test")
            sub_cmd = _first_arg_from_list(args[1:], remote_subcmds)
            if sub_cmd:
                cmd_path.append(sub_cmd)
                if len(args) > 2 and sub_cmd in ("agent", "device"):
                    remote2_subcmds = ("list", "start", "monitor")
                    sub_cmd = _first_arg_from_list(args[2:], remote2_subcmds)
                    if sub_cmd:
                        cmd_path.append(sub_cmd)
        self['screen_name'] = " ".join([p.title() for p in cmd_path])
示例#6
0
    def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        self['an'] = " ".join(dpdata)
示例#7
0
    def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        self['an'] = " ".join(dpdata)
示例#8
0
    def _prefill_appinfo(self):
        self["av"] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        if getenv("PLATFORMIO_IDE"):
            dpdata.append("IDE/%s" % getenv("PLATFORMIO_IDE"))
        self["an"] = " ".join(dpdata)
示例#9
0
    def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("PlatformIO/%s" % __version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        if getenv("PLATFORMIO_IDE"):
            dpdata.append("IDE/%s" % getenv("PLATFORMIO_IDE"))
        self['an'] = " ".join(dpdata)
示例#10
0
def on_command():
    resend_backuped_reports()

    mp = MeasurementProtocol()
    mp.send("screenview")

    if util.is_ci():
        measure_ci()

    if app.get_session_var("caller_id"):
        measure_caller(app.get_session_var("caller_id"))
示例#11
0
def on_command():
    resend_backuped_reports()

    mp = MeasurementProtocol()
    mp.send("screenview")

    if util.is_ci():
        measure_ci()

    if app.get_session_var("caller_id"):
        measure_caller(app.get_session_var("caller_id"))
示例#12
0
    def _prefill_screen_name(self):
        self['cd3'] = " ".join([str(s).lower() for s in sys.argv[1:]])

        if not app.get_session_var("command_ctx"):
            return
        ctx_args = app.get_session_var("command_ctx").args
        args = [str(s).lower() for s in ctx_args if not str(s).startswith("-")]
        if not args:
            return
        if args[0] in ("lib", "platforms", "serialports", "settings"):
            cmd_path = args[:2]
        else:
            cmd_path = args[:1]
        self['screen_name'] = " ".join([p.title() for p in cmd_path])
示例#13
0
    def _prefill_screen_name(self):
        self['cd3'] = " ".join([str(s).lower() for s in sys.argv[1:]])

        if not app.get_session_var("command_ctx"):
            return
        ctx_args = app.get_session_var("command_ctx").args
        args = [str(s).lower() for s in ctx_args if not str(s).startswith("-")]
        if not args:
            return
        if args[0] in ("lib", "platforms", "serialports", "settings"):
            cmd_path = args[:2]
        else:
            cmd_path = args[:1]
        self['screen_name'] = " ".join([p.title() for p in cmd_path])
示例#14
0
 def _ignore_hit():
     if not app.get_setting("enable_telemetry"):
         return True
     if app.get_session_var("caller_id") and \
             all(c in sys.argv for c in ("run", "idedata")):
         return True
     return False
示例#15
0
    def load_state():
        with app.State(AppRPC.APPSTATE_PATH, lock=True) as state:
            storage = state.get("storage", {})

            # base data
            caller_id = app.get_session_var("caller_id")
            storage["cid"] = app.get_cid()
            storage["coreVersion"] = __version__
            storage["coreSystype"] = util.get_systype()
            storage["coreCaller"] = str(
                caller_id).lower() if caller_id else None
            storage["coreSettings"] = {
                name: {
                    "description": data["description"],
                    "default_value": data["value"],
                    "value": app.get_setting(name),
                }
                for name, data in app.DEFAULT_SETTINGS.items()
            }

            storage["homeDir"] = fs.expanduser("~")
            storage["projectsDir"] = storage["coreSettings"]["projects_dir"][
                "value"]

            # skip non-existing recent projects
            storage["recentProjects"] = [
                p for p in storage.get("recentProjects", [])
                if is_platformio_project(p)
            ]

            state["storage"] = storage
            state.modified = False  # skip saving extra fields
            return state.as_dict()
示例#16
0
    def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        try:
            result = util.exec_command(["scons", "--version"])
            match = re.search(r"engine: v([\d\.]+)", result['out'])
            if match:
                dpdata.append("SCons/%s" % match.group(1))
        except:  # pylint: disable=W0702
            pass
        self['an'] = " ".join(dpdata)
示例#17
0
    def _prefill_appinfo(self):
        self['av'] = __version__

        # gather dependent packages
        dpdata = []
        dpdata.append("Click/%s" % click.__version__)
        if app.get_session_var("caller_id"):
            dpdata.append("Caller/%s" % app.get_session_var("caller_id"))
        try:
            result = util.exec_command(["scons", "--version"])
            match = re.search(r"engine: v([\d\.]+)", result['out'])
            if match:
                dpdata.append("SCons/%s" % match.group(1))
        except:  # pylint: disable=W0702
            pass
        self['an'] = " ".join(dpdata)
示例#18
0
    def load_state():
        with app.State(AppRPC.APPSTATE_PATH, lock=True) as state:
            storage = state.get("storage", {})

            # base data
            caller_id = app.get_session_var("caller_id")
            storage['cid'] = app.get_cid()
            storage['coreVersion'] = __version__
            storage['coreSystype'] = util.get_systype()
            storage['coreCaller'] = (str(caller_id).lower()
                                     if caller_id else None)
            storage['coreSettings'] = {
                name: {
                    "description": data['description'],
                    "default_value": data['value'],
                    "value": app.get_setting(name)
                }
                for name, data in app.DEFAULT_SETTINGS.items()
            }

            storage['homeDir'] = expanduser("~")
            storage['projectsDir'] = storage['coreSettings']['projects_dir'][
                'value']

            # skip non-existing recent projects
            storage['recentProjects'] = [
                p for p in storage.get("recentProjects", [])
                if is_platformio_project(p)
            ]

            state['storage'] = storage
            return state.as_dict()
示例#19
0
 def _ignore_hit():
     if not app.get_setting("enable_telemetry"):
         return True
     if app.get_session_var("caller_id") and \
             all(c in sys.argv for c in ("run", "idedata")):
         return True
     return False
示例#20
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    assert ctx
    ctx_args = ctx.args or []
    return ctx_args and any([
        ctx.args[0] == "upgrade", "--json-output" in ctx_args,
        "--version" in ctx_args
    ])
示例#21
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    assert ctx
    ctx_args = ctx.args or []
    return ctx_args and any([
        ctx.args[0] == "upgrade", "--json-output" in ctx_args,
        "--version" in ctx_args
    ])
示例#22
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    if not ctx:
        return True
    return ctx.args and any([
        ctx.args[0] == "debug" and "--interpreter" in " ".join(ctx.args),
        ctx.args[0] == "upgrade", "--json-output" in ctx.args, "--version"
        in ctx.args
    ])
示例#23
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    if not ctx:
        return True
    return ctx.args and any([
        ctx.args[0] == "debug" and "--interpreter" in " ".join(ctx.args),
        ctx.args[0] == "upgrade", "--json-output" in ctx.args,
        "--version" in ctx.args
    ])
示例#24
0
 def _prefill_custom_data(self):
     caller_id = str(app.get_session_var("caller_id"))
     self['cd1'] = util.get_systype()
     self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                     platform.platform())
     self['cd4'] = 1 if (not util.is_ci() and
                         (caller_id or not util.is_container())) else 0
     if caller_id:
         self['cd5'] = caller_id.lower()
    def get_project_build_data(self):
        data = {"defines": [], "includes": [], "cxx_path": None}
        envdata = self.get_project_env()
        if "env_name" not in envdata:
            return data
        cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"]
        if app.get_session_var("caller_id"):
            cmd.extend(["-c", app.get_session_var("caller_id")])
        cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
        cmd.extend(["-d", self.project_dir])
        result = util.exec_command(cmd)

        if result['returncode'] != 0 or '"includes":' not in result['out']:
            raise exception.PlatformioException("\n".join(
                [result['out'], result['err']]))

        for line in result['out'].split("\n"):
            line = line.strip()
            if line.startswith('{"') and line.endswith("}"):
                data = json.loads(line)
        return data
示例#26
0
    def get_project_build_data(self):
        data = {"defines": [], "includes": [], "cxx_path": None}
        envdata = self.get_project_env()
        if "env_name" not in envdata:
            return data
        cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"]
        if app.get_session_var("caller_id"):
            cmd.extend(["-c", app.get_session_var("caller_id")])
        cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
        cmd.extend(["-d", self.project_dir])
        result = util.exec_command(cmd)

        if result['returncode'] != 0 or '"includes":' not in result['out']:
            raise exception.PlatformioException("\n".join(
                [result['out'], result['err']]))

        for line in result['out'].split("\n"):
            line = line.strip()
            if line.startswith('{"') and line.endswith("}"):
                data = json.loads(line)
        return data
示例#27
0
    def device_monitor(**kwargs):
        sys.argv = app.get_session_var("command_ctx").args[1:]

        if not kwargs['port']:
            for item in get_serialports():
                if "VID:PID" in item['hwid']:
                    sys.argv += ["--port", item['port']]
                    break

        try:
            miniterm.main()
        except Exception as e:  # pylint: disable=W0702
            raise MinitermException(e)
    def serialports_monitor(**kwargs):
        sys.argv = app.get_session_var("command_ctx").args[1:]

        if not kwargs['port']:
            for item in get_serialports():
                if "VID:PID" in item['hwid']:
                    sys.argv += ["--port", item['port']]
                    break

        try:
            miniterm.main()
        except Exception as e:  # pylint: disable=W0702
            raise MinitermException(e)
示例#29
0
    def _prefill_custom_data(self):
        def _filter_args(items):
            result = []
            stop = False
            for item in items:
                item = str(item).lower()
                result.append(item)
                if stop:
                    break
                if item == "account":
                    stop = True
            return result

        caller_id = str(app.get_session_var("caller_id"))
        self["cd1"] = util.get_systype()
        self["cd4"] = (1 if (not util.is_ci() and
                             (caller_id or not is_container())) else 0)
        if caller_id:
            self["cd5"] = caller_id.lower()
示例#30
0
    def _prefill_custom_data(self):
        def _filter_args(items):
            result = []
            stop = False
            for item in items:
                item = str(item).lower()
                result.append(item)
                if stop:
                    break
                if item == "account":
                    stop = True
            return result

        caller_id = str(app.get_session_var("caller_id"))
        self['cd1'] = util.get_systype()
        self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                        platform.platform())
        # self['cd3'] = " ".join(_filter_args(sys.argv[1:]))
        self['cd4'] = 1 if (not util.is_ci() and
                            (caller_id or not is_container())) else 0
        if caller_id:
            self['cd5'] = caller_id.lower()
示例#31
0
    def _prefill_custom_data(self):

        def _filter_args(items):
            result = []
            stop = False
            for item in items:
                item = str(item).lower()
                result.append(item)
                if stop:
                    break
                if item == "account":
                    stop = True
            return result

        caller_id = str(app.get_session_var("caller_id"))
        self['cd1'] = util.get_systype()
        self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                        platform.platform())
        # self['cd3'] = " ".join(_filter_args(sys.argv[1:]))
        self['cd4'] = 1 if (not util.is_ci() and
                            (caller_id or not util.is_container())) else 0
        if caller_id:
            self['cd5'] = caller_id.lower()
示例#32
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    assert ctx
    ctx_args = ctx.args or []
    return (ctx_args
            and (ctx.args[0] == "upgrade" or "--json-output" in ctx_args))
示例#33
0
def cli(dev):
    if not dev and __version__ == get_latest_version():
        return click.secho(
            "You're up-to-date!\nPlatformIO %s is currently the "
            "newest version available." % __version__,
            fg="green",
        )

    click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")

    to_develop = dev or not all(c.isdigit() for c in __version__ if c != ".")
    cmds = (
        ["pip", "install", "--upgrade",
         get_pip_package(to_develop)],
        ["platformio", "--version"],
    )

    cmd = None
    r = {}
    try:
        for cmd in cmds:
            cmd = [get_pythonexe_path(), "-m"] + cmd
            r = exec_command(cmd)

            # try pip with disabled cache
            if r["returncode"] != 0 and cmd[2] == "pip":
                cmd.insert(3, "--no-cache-dir")
                r = exec_command(cmd)

            assert r["returncode"] == 0
        assert "version" in r["out"]
        actual_version = r["out"].strip().split("version", 1)[1].strip()
        click.secho(
            "PlatformIO has been successfully upgraded to %s" % actual_version,
            fg="green",
        )
        click.echo("Release notes: ", nl=False)
        click.secho("https://docs.platformio.org/en/latest/history.html",
                    fg="cyan")
        if app.get_session_var("caller_id"):
            click.secho(
                "Warning! Please restart IDE to affect PIO Home changes",
                fg="yellow")
    except Exception as e:  # pylint: disable=broad-except
        if not r:
            raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
        permission_errors = ("permission denied", "not permitted")
        if any(m in r["err"].lower()
               for m in permission_errors) and not WINDOWS:
            click.secho(
                """
-----------------
Permission denied
-----------------
You need the `sudo` permission to install Python packages. Try

> sudo pip install -U platformio

WARNING! Don't use `sudo` for the rest PlatformIO commands.
""",
                fg="yellow",
                err=True,
            )
            raise exception.ReturnErrorCode(1)
        raise exception.UpgradeError("\n".join([str(cmd), r["out"], r["err"]]))

    return True
示例#34
0
 def _prefill_custom_data(self):
     self['cd1'] = util.get_systype()
     self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                     platform.platform())
     self['cd4'] = (1 if app.get_setting("enable_prompts") or
                    app.get_session_var("caller_id") else 0)
示例#35
0
 def _prefill_custom_data(self):
     self['cd1'] = util.get_systype()
     self['cd2'] = "Python/%s %s" % (platform.python_version(),
                                     platform.platform())
     self['cd4'] = (1 if app.get_setting("enable_prompts")
                    or app.get_session_var("caller_id") else 0)
示例#36
0
    def get_default_path():
        from platformio import app  # pylint: disable=import-outside-toplevel

        return app.get_session_var("custom_project_conf") or os.path.join(
            os.getcwd(), "platformio.ini")
示例#37
0
def in_silence(ctx=None):
    ctx = ctx or app.get_session_var("command_ctx")
    assert ctx
    ctx_args = ctx.args or []
    return (ctx_args and
            (ctx.args[0] == "upgrade" or "--json-output" in ctx_args))