hcs-core 0.1.296__py3-none-any.whl → 0.1.298__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.296"
1
+ __version__ = "0.1.298"
@@ -48,7 +48,7 @@ def get(name: str, key: str):
48
48
  @click.argument("name")
49
49
  @click.argument("key_value") # 'key value pair, example: k1=v1'
50
50
  def set(name: str, key_value: str):
51
- """Set a context object by name."""
51
+ """Set a context property by name."""
52
52
  parts = key_value.split("=")
53
53
  if len(parts) != 2:
54
54
  ctxp.panic("Invalid KEY_VALUE format. Valid example: key1=value1")
@@ -58,6 +58,20 @@ def set(name: str, key_value: str):
58
58
  ctxp.context.set(name, data)
59
59
 
60
60
 
61
+ @context.command()
62
+ @click.argument("name")
63
+ @click.argument("key")
64
+ def unset(name: str, key: str):
65
+ """Unset a context property by name."""
66
+ data = ctxp.context.get(name, default=None)
67
+ if data is None:
68
+ return
69
+ data.pop(key, None)
70
+ if len(data) == 0:
71
+ return ctxp.context.delete(name)
72
+ return ctxp.context.set(name, data)
73
+
74
+
61
75
  @context.command()
62
76
  @click.argument("name")
63
77
  def delete(name: str):
@@ -19,7 +19,7 @@ import sys
19
19
  import click
20
20
  import questionary
21
21
 
22
- from hcs_core.ctxp import cli_processor, panic, profile, util
22
+ from hcs_core.ctxp import cli_options, cli_processor, panic, profile, util
23
23
 
24
24
 
25
25
  @click.group(name="profile", cls=cli_processor.LazyGroup)
@@ -62,8 +62,8 @@ def use(name: str):
62
62
  @profile_cmd_group.command()
63
63
  @click.option("--from-name", "-f", required=False)
64
64
  @click.option("--to-name", "-t", required=True)
65
- @click.option("--edit", "-e", required=False, is_flag=True, help="Edit the profile after copying.")
66
- def copy(from_name: str, to_name: str, edit: bool):
65
+ @click.option("--no-edit", "-e", required=False, is_flag=True, help="Edit the profile after copying.")
66
+ def copy(from_name: str, to_name: str, no_edit: bool):
67
67
  """Copy profile."""
68
68
 
69
69
  if not from_name:
@@ -76,10 +76,9 @@ def copy(from_name: str, to_name: str, edit: bool):
76
76
  panic("Profile already exists: " + to_name)
77
77
  data = profile.create(to_name, data, True)
78
78
 
79
- if edit:
80
- util.launch_text_editor(profile.file(to_name))
81
- else:
79
+ if no_edit:
82
80
  return data
81
+ util.launch_text_editor(profile.file(to_name))
83
82
 
84
83
 
85
84
  @profile_cmd_group.command()
@@ -101,11 +100,20 @@ def get(name: str):
101
100
 
102
101
 
103
102
  @profile_cmd_group.command()
103
+ @cli_options.confirm
104
104
  @click.argument("name", required=False)
105
- def delete(name: str):
105
+ def delete(confirm: bool, name: str):
106
106
  """Delete a profile by name."""
107
107
  if not name:
108
108
  name = profile.name()
109
+
110
+ if not profile.exists(name):
111
+ return
112
+ if not confirm:
113
+ question = f"Are you sure to delete profile '{name}'?"
114
+ if not questionary.confirm(question, default=False).ask():
115
+ click.echo("Aborted")
116
+ return
109
117
  profile.delete(name)
110
118
 
111
119
 
hcs_core/ctxp/context.py CHANGED
@@ -34,6 +34,8 @@ def get(name: str, reload: bool = False, default=None) -> jsondot.dotdict:
34
34
 
35
35
 
36
36
  def set(name: str, data: dict):
37
+ if data is None or len(data) == 0:
38
+ return _store().delete(name)
37
39
  return _store().save(name, data)
38
40
 
39
41
 
hcs_core/ctxp/util.py CHANGED
@@ -368,3 +368,29 @@ def format_table(data: list, fields_mapping: dict, columns_to_sum: list = None):
368
368
  traceback.print_exc()
369
369
 
370
370
  return tabulate(table, headers=headers) + "\n"
371
+
372
+
373
+ def colorize(data: dict, name: str, mapping: dict):
374
+ if os.environ.get("TERM_COLOR") == "0":
375
+ return
376
+
377
+ s = data.get(name)
378
+ if not s:
379
+ return
380
+
381
+ if isinstance(mapping, dict):
382
+ c = mapping.get(s)
383
+ if c:
384
+ if isinstance(c, str):
385
+ data[name] = click.style(s, fg=c)
386
+ elif callable(c):
387
+ color = c(data)
388
+ data[name] = click.style(s, fg=color)
389
+ else:
390
+ raise Exception(f"Unexpected color type: {type(c)} {c}")
391
+ elif callable(mapping):
392
+ c = mapping(s)
393
+ if c:
394
+ data[name] = click.style(s, fg=c)
395
+ else:
396
+ raise Exception(f"Unexpected mapping type: {type(mapping)} {mapping}")
@@ -191,7 +191,7 @@ class EzClient:
191
191
  timeout: float = 30.0,
192
192
  ):
193
193
  # import json as jsonlib
194
- # print(url, jsonlib.dumps(json, indent=4))
194
+ # print("->", self._client().base_url, url, jsonlib.dumps(json, indent=4))
195
195
  try:
196
196
  resp = self._client().post(url, json=json, content=text, files=files, headers=headers, timeout=timeout)
197
197
  except httpx.HTTPStatusError as e:
@@ -208,7 +208,7 @@ class EzClient:
208
208
 
209
209
  def get(self, url: str, headers: dict = None, raise_on_404: bool = False, type: Optional[Type[BaseModel]] = None):
210
210
  try:
211
- # print("->", url)
211
+ # print("->", self._client().base_url, url)
212
212
  resp = self._client().get(url, headers=headers)
213
213
  data = _parse_resp(resp)
214
214
  if data and type:
hcs_core/util/versions.py CHANGED
@@ -30,14 +30,16 @@ def check_upgrade():
30
30
  checked_at = hcs_core.ctxp.state.get(last_upgrade_check_at, 0)
31
31
 
32
32
  now = time.time()
33
- if now - checked_at > 24 * 60 * 60:
34
- try:
35
- latest = get_latest_version()
36
- current = Version(get_version())
37
- if current < latest:
38
- log.warning(f"New version available: {latest}. Execute 'hcs upgrade' to upgrade.")
39
- except Exception as e:
40
- logging.debug(e)
33
+ if now - checked_at < 24 * 60 * 60:
34
+ return
35
+
36
+ try:
37
+ latest = get_latest_version()
38
+ current = Version(get_version())
39
+ if current < latest:
40
+ log.warning(f"New version available: {latest}. Execute 'hcs upgrade' to upgrade.")
41
+ except Exception as e:
42
+ logging.debug(e)
41
43
 
42
44
  hcs_core.ctxp.state.set(last_upgrade_check_at, now)
43
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hcs-core
3
- Version: 0.1.296
3
+ Version: 0.1.298
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
@@ -36,7 +36,7 @@ Requires-Dist: schedule>=1.1.0
36
36
  Requires-Dist: setuptools>=70.0.0
37
37
  Requires-Dist: tabulate>=0.9.0
38
38
  Requires-Dist: websocket-client>=1.2.3
39
- Requires-Dist: yumako>=0.1.27
39
+ Requires-Dist: yumako>=0.1.31
40
40
  Provides-Extra: dev
41
41
  Requires-Dist: bandit; extra == 'dev'
42
42
  Requires-Dist: black; extra == 'dev'
@@ -1,11 +1,11 @@
1
- hcs_core/__init__.py,sha256=tWega_C2IREoYz7O6B0hfh16qnFYyEpvEwZ0sfzXPxM,24
1
+ hcs_core/__init__.py,sha256=iCAiJetE04YjkRvTLJlNnalMA2Qh13pOV7pEpnXQOBk,24
2
2
  hcs_core/ctxp/__init__.py,sha256=bHVHhJP10Luz1a3Kk3zFx14dAO4SY6Q20Lrv8rNWWGc,1075
3
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
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
- hcs_core/ctxp/context.py,sha256=y0ouOzXyYTg9MOuWjzjls9WfOKYaO31_MGJJ2S-Y9p4,3375
8
+ hcs_core/ctxp/context.py,sha256=LafhucyGRGYLmnXoZLZOKRWXUwJ1KzP-6vjDTTrC8j4,3451
9
9
  hcs_core/ctxp/data_util.py,sha256=PECaLaAQoqTyuYILXm1Deg5iL96tBxgiBhggp-f-qVE,14933
10
10
  hcs_core/ctxp/dispatcher.py,sha256=GAK-jGXDpyX0C88oRDtDi4yeM0qlvID96k98z_vqJkg,2261
11
11
  hcs_core/ctxp/duration.py,sha256=_0mt8Ng5mzNzEdSXkOqExPOzQcw8HkQDUH_hwt5CMLM,2109
@@ -22,12 +22,12 @@ hcs_core/ctxp/task_schd.py,sha256=mvZMeKDSSo2p7VidSoZY1XZj433TQn_YF9SGJEzl9lg,45
22
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
- hcs_core/ctxp/util.py,sha256=4vnaItrdkxCqMTdBf5bKDJ9dSSX9sraSP9XjGRq6xpU,11616
25
+ hcs_core/ctxp/util.py,sha256=ckPyheoS08-bP4aixtBhYwi-C6syjFA6UHyIL6cUsPs,12350
26
26
  hcs_core/ctxp/var_template.py,sha256=cTjj1UJ58ac6s5z4Oh5hSDQwKixq-rdbCF1D8akjAo0,3219
27
27
  hcs_core/ctxp/built_in_cmds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  hcs_core/ctxp/built_in_cmds/_ut.py,sha256=e50XBmPim2qRe0RYk_XAuRz1HWYyLJuMu-6dVxWR_fQ,3356
29
- hcs_core/ctxp/built_in_cmds/context.py,sha256=bU-BG60DyA8rpv1sw3LpHnPQb1wQiZQCoIMYLW_g5_c,2389
30
- hcs_core/ctxp/built_in_cmds/profile.py,sha256=xTIHziDniMd-BXH2XymtP1HB4K9fkkU8STtLVqDuY1Y,4371
29
+ hcs_core/ctxp/built_in_cmds/context.py,sha256=NbnsAaAkvnascSVqbh7BScXznvfPtTbgQWkU0GLYYGk,2747
30
+ hcs_core/ctxp/built_in_cmds/profile.py,sha256=z9K4o1n7ugducPpOFjaDMS9xA2RVhWcIcgljKOCn200,4667
31
31
  hcs_core/plan/__init__.py,sha256=5klVuXXLQLn2Hj6Gz2Hc-1XSyDXKE9o-BjQ82oXekiI,465
32
32
  hcs_core/plan/actions.py,sha256=UvCynzApJUxi39HUoPIQ_uownlbvFbJ4aAs6pmulrLY,125
33
33
  hcs_core/plan/base_provider.py,sha256=CSJFN8lopWTUblw8CW78Epnef9BbJVLhPLk9bPfZceM,1299
@@ -46,7 +46,7 @@ hcs_core/sglib/auth.py,sha256=x2LjNCOTf_OJYsNggTG2rVagnVartyDCOlK4lSpXfso,6773
46
46
  hcs_core/sglib/cli_options.py,sha256=NvdiHpX_o6IYPEM8cQYLb_R7T4aiXVvYLqn6Vk4Q2-Y,1761
47
47
  hcs_core/sglib/client_util.py,sha256=t7zCldRRWt5f0l4TTRhmX-ZIaEm6MzNs_3B2RlwtXfk,14119
48
48
  hcs_core/sglib/csp.py,sha256=UcO68YtLOPDQWiTjPVIPwQ2Z-Mywc-154aoIkLdyzwE,10991
49
- hcs_core/sglib/ez_client.py,sha256=M3BqAXizWbdE1mba0nPHZXC5qJ_t2k_Vurttpg_VqF4,8355
49
+ hcs_core/sglib/ez_client.py,sha256=AgpWvB79NLWr_lyrZXbaY1iOyHg7hEgeM6Ll0SVCBmY,8411
50
50
  hcs_core/sglib/hcs_client.py,sha256=pjrAVQDEy2tiQMypMpOzODFntT6aNHXjje8or_mkL2U,804
51
51
  hcs_core/sglib/init.py,sha256=w_0ZU70Q1TGbSZsqSi7ewKQqpExFlepOT7mIqH0wnho,310
52
52
  hcs_core/sglib/login_support.py,sha256=rHKZDAZXlo62IsjETyXxCSPxg1L4nV6ffZM_tulfe0A,7574
@@ -63,7 +63,7 @@ hcs_core/util/pki_util.py,sha256=Lt3-IzIoGcaQKNE7KUszxR7JSZkpXduVZJ262TszsIs,668
63
63
  hcs_core/util/query_util.py,sha256=5bh3bUVIQuY9qerndfuyfyzkTExYJ8zD0_e3PSN7y-4,3142
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
- hcs_core/util/versions.py,sha256=urMtShfoBx_Eqq0D-450LP0i-rW447k9yX8q8j5H_qA,1721
67
- hcs_core-0.1.296.dist-info/METADATA,sha256=EOuDHFuN5KefNw_F2VCNdKQFTQvIkfUMORGB6UH-_Ko,1951
68
- hcs_core-0.1.296.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
69
- hcs_core-0.1.296.dist-info/RECORD,,
66
+ hcs_core/util/versions.py,sha256=6nyyZzi3P69WQfioPc2_YWZQcUc13mC1eKoK58b3WUQ,1709
67
+ hcs_core-0.1.298.dist-info/METADATA,sha256=id4wfYatf5BOeT96YpnWpGnoXpSt_cB3eTn56JDZVws,1951
68
+ hcs_core-0.1.298.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
69
+ hcs_core-0.1.298.dist-info/RECORD,,