hcs-core 0.1.293__py3-none-any.whl → 0.1.295__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hcs_core/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.293"
1
+ __version__ = "0.1.295"
hcs_core/ctxp/_init.py CHANGED
@@ -43,6 +43,7 @@ def init(app_name: str, store_path: str = user_home, config_path: str = "./confi
43
43
  global _initialized_app_name
44
44
  if _initialized_app_name == app_name:
45
45
  return
46
+
46
47
  if _initialized_app_name is not None:
47
48
  raise ValueError(f"App {app_name} already initialized with {_initialized_app_name}")
48
49
  _initialized_app_name = app_name
@@ -79,6 +80,7 @@ def app_name():
79
80
 
80
81
  def init_cli(main_cli: click.Group, commands_dir: str = "./cmds"):
81
82
  try:
83
+ telemetry.start(_initialized_app_name)
82
84
  ret = cli_processor.init(main_cli, commands_dir)
83
85
  telemetry.end()
84
86
  return ret
@@ -188,9 +188,9 @@ def _default_io(cmd: click.Command):
188
188
  "exclude_field": kwargs.pop("exclude_field"),
189
189
  }
190
190
  ctx = click.get_current_context()
191
- from .telemetry import start as telemetry_start
191
+ from .telemetry import update as telemetry_update
192
192
 
193
- telemetry_start(ctx.command_path, ctx.params)
193
+ telemetry_update(ctx.command_path, ctx.params)
194
194
 
195
195
  if io_args["output"] == "table":
196
196
 
@@ -12,7 +12,7 @@ log = logging.getLogger(__name__)
12
12
 
13
13
  _record = None
14
14
  _enabled = None
15
- _version = None
15
+ _app_name = ""
16
16
 
17
17
 
18
18
  def disable():
@@ -28,65 +28,108 @@ def _is_disabled():
28
28
 
29
29
 
30
30
  def _get_version():
31
- global _version
32
- if _version is None:
33
- try:
34
- from importlib.metadata import version
31
+ try:
32
+ from importlib.metadata import version
33
+
34
+ return version("hcs-cli")
35
+ except Exception as e:
36
+ log.debug(f"Failed to get hcs-cli version: {e}")
37
+ return "unknown"
35
38
 
36
- _version = version("hcs-cli")
37
- except Exception as e:
38
- log.debug(f"Failed to get hcs-cli version: {e}")
39
- _version = "unknown"
40
- return _version
41
39
 
40
+ def _get_record():
41
+ global _record
42
+ if _record is None:
43
+ _record = {
44
+ "@timestamp": datetime.now(timezone.utc).isoformat(timespec="milliseconds"),
45
+ "app": _app_name,
46
+ "command": None,
47
+ "options": [],
48
+ "return": -1,
49
+ "error": None,
50
+ "time_ms": -1,
51
+ "version": _get_version(),
52
+ "env": {
53
+ "python_version": sys.version,
54
+ "platform": sys.platform,
55
+ "executable": sys.executable,
56
+ },
57
+ }
58
+ return _record
42
59
 
43
- def start(cmd_path: str, params: dict):
60
+
61
+ def start(app_name: str = None):
44
62
  if _is_disabled():
45
63
  return
46
64
 
47
- global _record
48
- _record = {
49
- "@timestamp": datetime.now(timezone.utc).isoformat(timespec="milliseconds"),
50
- "command": cmd_path,
51
- "options": [k.replace("_", "-") for k, v in params.items() if v],
52
- "return": -1,
53
- "error": None,
54
- "time_ms": -1,
55
- "version": _get_version(),
56
- "env": {
57
- "python_version": sys.version,
58
- "platform": sys.platform,
59
- "executable": sys.executable,
60
- },
61
- }
65
+ global _app_name
66
+ _app_name = app_name
67
+ _get_record()
62
68
 
63
69
 
64
- def end(return_code: int = 0, error: Exception = None):
70
+ def update(cmd_path: str, params: dict):
65
71
  if _is_disabled():
66
72
  return
67
73
 
68
- if _record is None:
74
+ record = _get_record()
75
+ record["command"] = cmd_path
76
+ record["options"] = [k.replace("_", "-") for k, v in params.items() if v]
77
+
78
+
79
+ def end(return_code: int = 0, error: Exception = None):
80
+ if _is_disabled():
69
81
  return
70
82
 
83
+ record = _get_record()
71
84
  if error:
72
85
  if isinstance(error, click.exceptions.Exit):
73
86
  return_code = error.exit_code
74
87
  elif isinstance(error, SystemExit):
75
88
  return_code = error.code
76
89
  else:
77
- _record["error"] = str(error)
90
+ record["error"] = str(error)
78
91
  if return_code == 0:
79
92
  return_code = 1
80
- _record["return"] = return_code
81
- _record["time_ms"] = int((time.time() - datetime.fromisoformat(_record["@timestamp"]).timestamp()) * 1000)
93
+ record["return"] = return_code
94
+ record["time_ms"] = int((time.time() - datetime.fromisoformat(record["@timestamp"]).timestamp()) * 1000)
82
95
 
83
- # print('TELEMETRY end', json.dumps(_record, indent=4), flush=True)
96
+ _fix_missing_commands(record)
97
+ _injest(record)
98
+ return record
84
99
 
85
- _injest(_record)
86
- return _record
100
+
101
+ def _fix_missing_commands(record):
102
+ if record["command"]:
103
+ return
104
+
105
+ args = sys.argv[1:]
106
+
107
+ # this does not work for all cases, but only as best effort.
108
+ options_started = False
109
+ options = record["options"]
110
+ command = [_app_name]
111
+ for arg in args:
112
+ if arg.startswith("-"):
113
+ options_started = True
114
+
115
+ if options_started:
116
+ if arg.startswith("--"):
117
+ options.append(arg[2:])
118
+ elif arg.startswith("-"):
119
+ options.append(arg[1:])
120
+ else:
121
+ # value. For privacy no logging.
122
+ continue
123
+ else:
124
+ command.append(arg)
125
+
126
+ record["command"] = " ".join(command)
87
127
 
88
128
 
89
129
  def _injest(doc):
130
+
131
+ # print('TELEMETRY end', json.dumps(doc, indent=4), flush=True)
132
+
90
133
  try:
91
134
  response = httpx.post(
92
135
  f"https://collie.omnissa.com/es/hcs-cli/_doc",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hcs-core
3
- Version: 0.1.293
3
+ Version: 0.1.295
4
4
  Summary: Horizon Cloud Service CLI module.
5
5
  Project-URL: Homepage, https://github.com/euc-eng/hcs-cli
6
6
  Project-URL: Bug Tracker, https://github.com/euc-eng/hcs-cli/issues
@@ -42,6 +42,7 @@ Requires-Dist: bandit; extra == 'dev'
42
42
  Requires-Dist: black; extra == 'dev'
43
43
  Requires-Dist: build; extra == 'dev'
44
44
  Requires-Dist: flake8; extra == 'dev'
45
+ Requires-Dist: hatch; extra == 'dev'
45
46
  Requires-Dist: mypy; extra == 'dev'
46
47
  Requires-Dist: pylint; extra == 'dev'
47
48
  Requires-Dist: pytest; extra == 'dev'
@@ -1,8 +1,8 @@
1
- hcs_core/__init__.py,sha256=dpURb1M-NF0ulraHpSZhuqRQqVLMZL5u8ZeOnRNcw1M,24
1
+ hcs_core/__init__.py,sha256=Cru0kvgt1VLfBCuVDXGLqKb3MgCs91b24AErV6yJlmQ,24
2
2
  hcs_core/ctxp/__init__.py,sha256=bHVHhJP10Luz1a3Kk3zFx14dAO4SY6Q20Lrv8rNWWGc,1075
3
- hcs_core/ctxp/_init.py,sha256=QCIAHCue6KZQ-gq-dcxHsGW5QQQmhuGgBUm_E9x_Beg,2885
3
+ hcs_core/ctxp/_init.py,sha256=fMcRMPfJx-N0c-u0Zj2sFVKQL1-lWQd28gooAZETGUA,2933
4
4
  hcs_core/ctxp/cli_options.py,sha256=cwlUgYXzIie9eRcu8fkBo_iFvC8LhflKGblWYtM2Hto,2739
5
- hcs_core/ctxp/cli_processor.py,sha256=pVfMLAJne34YY2EYz_Tz-8yUxUry60gooGm6EFPIieM,7652
5
+ hcs_core/ctxp/cli_processor.py,sha256=uxWqDecENdO8xd7ghR0wz10qwsroCZ93OtZAqtIFuJ8,7655
6
6
  hcs_core/ctxp/cmd_util.py,sha256=_-VwQSmkfi52qWC3uHQI06mSiIPfsZroDruTDYHXiMA,3119
7
7
  hcs_core/ctxp/config.py,sha256=vRdzPxi3Yrt04cnR6b5mJwEOtYBh21qvmlSSsgyGoI4,931
8
8
  hcs_core/ctxp/context.py,sha256=y0ouOzXyYTg9MOuWjzjls9WfOKYaO31_MGJJ2S-Y9p4,3375
@@ -19,7 +19,7 @@ hcs_core/ctxp/profile_store.py,sha256=v4RvKSaKSJhAt5rEGbC6v-NfaI3N67YffPm-qlrQWd
19
19
  hcs_core/ctxp/recent.py,sha256=ER1HASPRm1k_3MIO-WVbj2vGipY565ZpBlmo-_V3vjo,1797
20
20
  hcs_core/ctxp/state.py,sha256=gjcMRVONKBq7WiFQo-xca1726ngZe90mnPrF3vbXDrU,1634
21
21
  hcs_core/ctxp/task_schd.py,sha256=mvZMeKDSSo2p7VidSoZY1XZj433TQn_YF9SGJEzl9lg,4586
22
- hcs_core/ctxp/telemetry.py,sha256=IpJF-BGqU_2nlZm2nfKzpSPwTQQPX_BESMIzR3nH3EM,2483
22
+ hcs_core/ctxp/telemetry.py,sha256=iZv9x2n2aovpjYxNhnih_LS1fEJZjH_rbTsRKngv_Q0,3477
23
23
  hcs_core/ctxp/template_util.py,sha256=XslvIuRBlTVsUW0Y9M_D8gUPc1jWq6X2p4At2VAe1KU,731
24
24
  hcs_core/ctxp/timeutil.py,sha256=RyRrIRdFHbIghdB8wbC8VdABvc7hki2v51b1x2JvHgo,445
25
25
  hcs_core/ctxp/util.py,sha256=4vnaItrdkxCqMTdBf5bKDJ9dSSX9sraSP9XjGRq6xpU,11616
@@ -64,6 +64,6 @@ hcs_core/util/query_util.py,sha256=5bh3bUVIQuY9qerndfuyfyzkTExYJ8zD0_e3PSN7y-4,3
64
64
  hcs_core/util/scheduler.py,sha256=bPpCmGUL1UctJMfLPAg-h4Hl2YZr96FiI78-G_Usn08,2958
65
65
  hcs_core/util/ssl_util.py,sha256=MvU102fGwWWh9hhSmLnn1qQIWuD6TjZnN0iH0MXUtW0,1239
66
66
  hcs_core/util/versions.py,sha256=urMtShfoBx_Eqq0D-450LP0i-rW447k9yX8q8j5H_qA,1721
67
- hcs_core-0.1.293.dist-info/METADATA,sha256=wX5U-HdIKSqC2IdMHnJqQiVGs3UrnwrDtxvZNJHzv8k,1914
68
- hcs_core-0.1.293.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
69
- hcs_core-0.1.293.dist-info/RECORD,,
67
+ hcs_core-0.1.295.dist-info/METADATA,sha256=0ruALOs54xQC6ZbgrH6A18mf7AtY56dCVQCFBA2x2ng,1951
68
+ hcs_core-0.1.295.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
69
+ hcs_core-0.1.295.dist-info/RECORD,,