diff --git a/platformio/maintenance.py b/platformio/maintenance.py index f65e4b26..05bdc5b9 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -51,8 +51,11 @@ def on_platformio_start(ctx, force, caller): if not caller: if getenv("PLATFORMIO_CALLER"): caller = getenv("PLATFORMIO_CALLER") - elif getenv("C9_UID"): - caller = "C9" + elif util.is_container(): + if getenv("C9_UID"): + caller = "C9" + elif getenv("USER") == "cabox": + caller = "CA" app.set_session_var("command_ctx", ctx) app.set_session_var("force_option", force) diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 5f045951..121dac1b 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -92,12 +92,14 @@ class MeasurementProtocol(TelemetryBase): self['an'] = " ".join(dpdata) 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() else 0 - if app.get_session_var("caller_id"): - self['cd5'] = str(app.get_session_var("caller_id")).lower() + 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 _prefill_screen_name(self): self['cd3'] = " ".join([str(s).lower() for s in sys.argv[1:]]) diff --git a/platformio/util.py b/platformio/util.py index e0db6b2b..c8399187 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -298,6 +298,17 @@ def is_ci(): return os.getenv("CI", "").lower() == "true" +def is_container(): + if not isfile("/proc/1/cgroup"): + return False + with open("/proc/1/cgroup") as fp: + for line in fp: + line = line.strip() + if ":" in line and not line.endswith(":/"): + return True + return False + + def exec_command(*args, **kwargs): result = {"out": None, "err": None, "returncode": None}