Handle process in container

This commit is contained in:
Ivan Kravets
2016-09-29 23:53:19 +03:00
parent 5cfca6b1f6
commit bee52c715e
3 changed files with 21 additions and 5 deletions

View File

@ -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"):
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)

View File

@ -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:]])

View File

@ -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}