From d28f0b259a5a51315e0d6ff326f64693abf4a296 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 27 Aug 2016 23:15:32 +0300 Subject: [PATCH] Generate better UID --- platformio/__main__.py | 2 -- platformio/app.py | 16 ++++++++++++++++ platformio/telemetry.py | 12 +----------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index ae9fb061..05486bf0 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -72,8 +72,6 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 @click.option("--caller", "-c", help="Caller ID (service).") @click.pass_context def cli(ctx, force, caller): - if not caller and getenv("PLATFORMIO_CALLER"): - caller = getenv("PLATFORMIO_CALLER") maintenance.on_platformio_start(ctx, force, caller) diff --git a/platformio/app.py b/platformio/app.py index 42c8ee8d..cfd6b164 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -13,6 +13,7 @@ # limitations under the License. import json +import uuid from copy import deepcopy from os import environ, getenv from os.path import getmtime, isfile, join @@ -164,6 +165,11 @@ def reset_settings(): def get_session_var(name, default=None): + if name == "caller_id" and not SESSION_VARS[name]: + if getenv("PLATFORMIO_CALLER"): + return getenv("PLATFORMIO_CALLER") + elif getenv("C9_UID"): + return "C9" return SESSION_VARS.get(name, default) @@ -175,3 +181,13 @@ def set_session_var(name, value): def is_disabled_progressbar(): return any([get_session_var("force_option"), util.is_ci(), getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true"]) + + +def get_cid(): + cid = get_state_item("cid") + if not cid: + cid = str( + uuid.uuid5(uuid.NAMESPACE_OID, str( + getenv("C9_UID") if getenv("C9_UID") else uuid.getnode()))) + set_state_item("cid", cid) + return cid diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 08a8302d..68a1e517 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -17,7 +17,6 @@ import platform import Queue import sys import threading -import uuid from collections import deque from os import getenv from time import sleep, time @@ -31,8 +30,6 @@ from platformio import __version__, app, exception, util class TelemetryBase(object): - MACHINE_ID = str(uuid.uuid5(uuid.NAMESPACE_OID, str(uuid.getnode()))) - def __init__(self): self._params = {} @@ -46,13 +43,6 @@ class TelemetryBase(object): if name in self._params: del self._params[name] - def get_cid(self): - cid = app.get_state_item("cid") - if not cid: - cid = self.MACHINE_ID - app.set_state_item("cid", cid) - return cid - def send(self, hittype): raise NotImplementedError() @@ -72,7 +62,7 @@ class MeasurementProtocol(TelemetryBase): TelemetryBase.__init__(self) self['v'] = 1 self['tid'] = self.TID - self['cid'] = self.get_cid() + self['cid'] = app.get_cid() self['sr'] = "%dx%d" % click.get_terminal_size() self._prefill_screen_name()