shvcli-ell 0.1.0__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.
- shvcli_ell/__init__.py +8 -0
- shvcli_ell/__version__.py +1 -0
- shvcli_ell/plugin.py +6 -0
- shvcli_ell/py.typed +0 -0
- shvcli_ell/timesync.py +56 -0
- shvcli_ell/timezone.py +56 -0
- shvcli_ell-0.1.0.dist-info/METADATA +23 -0
- shvcli_ell-0.1.0.dist-info/RECORD +11 -0
- shvcli_ell-0.1.0.dist-info/WHEEL +5 -0
- shvcli_ell-0.1.0.dist-info/entry_points.txt +2 -0
- shvcli_ell-0.1.0.dist-info/top_level.txt +1 -0
shvcli_ell/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.1.0"
|
shvcli_ell/plugin.py
ADDED
shvcli_ell/py.typed
ADDED
|
File without changes
|
shvcli_ell/timesync.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""The builtin to sync time of NuttX based devices."""
|
|
2
|
+
|
|
3
|
+
import collections.abc
|
|
4
|
+
import datetime
|
|
5
|
+
|
|
6
|
+
from prompt_toolkit.completion import Completion
|
|
7
|
+
from shvcli import Builtin, Builtins, Client, CliItems, State, Tree
|
|
8
|
+
from shvcli.tools.complet import comp_path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BuiltinTimeSync(Builtin):
|
|
12
|
+
"""The builtin for time synchronization of ``utcTime`` with local one."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, builtins: Builtins, state: State) -> None:
|
|
15
|
+
super().__init__(builtins, state)
|
|
16
|
+
builtins["timesync"] = self
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def description(self) -> tuple[str, str]: # noqa: D102
|
|
20
|
+
return "[PATH]", "Synchronize the time of the board with the local time."
|
|
21
|
+
|
|
22
|
+
def completion( # noqa: D102
|
|
23
|
+
self, items: CliItems, client: Client
|
|
24
|
+
) -> collections.abc.Iterable[Completion]:
|
|
25
|
+
yield from comp_path(items.param, self.state.path, Tree(self.state), "")
|
|
26
|
+
|
|
27
|
+
async def completion_async( # noqa: D102
|
|
28
|
+
self, items: CliItems, client: Client
|
|
29
|
+
) -> collections.abc.AsyncGenerator[Completion, None]:
|
|
30
|
+
await client.probe(
|
|
31
|
+
items.path_param if items.param.endswith("/") else items.path_param.parent
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
async for res in super().completion_async(items, client):
|
|
35
|
+
yield res
|
|
36
|
+
|
|
37
|
+
async def run(self, items: CliItems, client: Client) -> None: # noqa: PLR6301, D102
|
|
38
|
+
path = items.path_param
|
|
39
|
+
if path.name != "utcTime":
|
|
40
|
+
path /= "utcTime"
|
|
41
|
+
got = await client.call(str(path), "get")
|
|
42
|
+
if not isinstance(got, datetime.datetime):
|
|
43
|
+
print(f"Unexpected result of {path}:get: {got}")
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
now = datetime.datetime.now(datetime.UTC)
|
|
47
|
+
diff = now - got
|
|
48
|
+
drift = datetime.timedelta(milliseconds=500)
|
|
49
|
+
if not (-drift <= diff <= drift):
|
|
50
|
+
await client.call(str(path), "set", now)
|
|
51
|
+
print(f"Time synchronized. The difference: {diff}")
|
|
52
|
+
else:
|
|
53
|
+
print(
|
|
54
|
+
"Time is syncrhonized withing half a second tolerance. "
|
|
55
|
+
f"The difference: {diff}"
|
|
56
|
+
)
|
shvcli_ell/timezone.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""The builtin to set local time time of NuttX based devices."""
|
|
2
|
+
|
|
3
|
+
import collections.abc
|
|
4
|
+
import pathlib
|
|
5
|
+
import zoneinfo
|
|
6
|
+
|
|
7
|
+
from prompt_toolkit.completion import Completion
|
|
8
|
+
from prompt_toolkit.validation import ValidationError
|
|
9
|
+
from shvcli import Builtin, Builtins, Client, CliItems, State
|
|
10
|
+
from shvcli.file import copy_file
|
|
11
|
+
from shvcli.tools.complet import comp_from
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BuiltinTimeSync(Builtin):
|
|
15
|
+
"""The builtin for setting local time zone."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, builtins: Builtins, state: State) -> None:
|
|
18
|
+
super().__init__(builtins, state)
|
|
19
|
+
builtins["timezone"] = self
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def description(self) -> tuple[str, str]: # noqa: D102
|
|
23
|
+
return (
|
|
24
|
+
"[TZ]",
|
|
25
|
+
"Upload the given time zone (or local time zone in default).",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def completion( # noqa: PLR6301, D102
|
|
29
|
+
self, items: CliItems, client: Client
|
|
30
|
+
) -> collections.abc.Iterable[Completion]:
|
|
31
|
+
yield from comp_from(items.param, zoneinfo.available_timezones())
|
|
32
|
+
|
|
33
|
+
def validate(self, items: CliItems, client: Client) -> None: # noqa: D102
|
|
34
|
+
param = items.param
|
|
35
|
+
if param and self._zonefile(items.param) is None:
|
|
36
|
+
raise ValidationError(message=f"No such zoneinfo: {param}")
|
|
37
|
+
|
|
38
|
+
async def run(self, items: CliItems, client: Client) -> None: # noqa: D102
|
|
39
|
+
dest = items.path
|
|
40
|
+
if dest.name != "timeZone":
|
|
41
|
+
dest /= "timeZone"
|
|
42
|
+
|
|
43
|
+
param = items.param
|
|
44
|
+
src = self._zonefile(param) if param else pathlib.Path("/etc/localtime")
|
|
45
|
+
if src is not None:
|
|
46
|
+
await copy_file(client, src, dest)
|
|
47
|
+
else:
|
|
48
|
+
print(f"No such zoneinfo: {param}")
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def _zonefile(param: str) -> pathlib.Path | None:
|
|
52
|
+
for tzpath in map(pathlib.Path, zoneinfo.TZPATH):
|
|
53
|
+
path = tzpath / param
|
|
54
|
+
if path.is_file():
|
|
55
|
+
return path
|
|
56
|
+
return None
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: shvcli-ell
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Silicon Heaven CLI Elektroline extension
|
|
5
|
+
Author: Elektroline a.s.
|
|
6
|
+
Project-URL: source, https://gitlab.com/elektroline-predator/shvcli-ell
|
|
7
|
+
Project-URL: changelog, https://gitlab.com/elektroline-predator/shvcli-ell/-/blob/master/CHANGELOG.md
|
|
8
|
+
Project-URL: issues, https://gitlab.com/elektroline-predator/shvcli-ell/-/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/x-rst
|
|
13
|
+
Requires-Dist: shvcli>=0.7.0
|
|
14
|
+
|
|
15
|
+
Silicon Heaven CLI Elektroline extension
|
|
16
|
+
========================================
|
|
17
|
+
|
|
18
|
+
The extension for the Silicon Heaven CLI access application to provide utilities
|
|
19
|
+
to work with Elektroline developed SHV systems.
|
|
20
|
+
|
|
21
|
+
* `📃 Sources <https://gitlab.com/elektroline-predator/shvcli-ell>`__
|
|
22
|
+
* `⁉️ Issue tracker <https://gitlab.com/elektroline-predator/shvcli-ell/-/issues>`__
|
|
23
|
+
* `Silicon Heaven CLI <https://gitlab.com/silicon-heaven/shvcli>`__
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
shvcli_ell/__init__.py,sha256=GlvcFG-HPLFpelk93WSeb9tUwD3oUkoIT3TJcQSOBdc,170
|
|
2
|
+
shvcli_ell/__version__.py,sha256=CpXi3jGlx23RvRyU7iytOMZrnspdWw4yofS8lpP1AJU,18
|
|
3
|
+
shvcli_ell/plugin.py,sha256=vNT4X7m-gvF1zQpn3omOKZ7S2FYTdPkH3oMUMq5n-CA,162
|
|
4
|
+
shvcli_ell/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
shvcli_ell/timesync.py,sha256=mTuKcsn4gbjUk74-KkUD5hptqfGKyP7PlMTjSL3xpiE,2063
|
|
6
|
+
shvcli_ell/timezone.py,sha256=E9f7oE6WUaymTw2oW_czVMzdpoKj1j4W5336qYApWRw,1904
|
|
7
|
+
shvcli_ell-0.1.0.dist-info/METADATA,sha256=dctkP1-fh_2ZO3mBY01wbOdg17unkJ_RZ3eiaHcHW1w,1012
|
|
8
|
+
shvcli_ell-0.1.0.dist-info/WHEEL,sha256=RhQGVt03AJtd1CDOm-ItnBQkdEMFvyyspQepe14x5Ds,97
|
|
9
|
+
shvcli_ell-0.1.0.dist-info/entry_points.txt,sha256=aDXfsHL8yuROUEsEPC3nN8Qien6TRaRRN8q7DMIqdFo,41
|
|
10
|
+
shvcli_ell-0.1.0.dist-info/top_level.txt,sha256=IvTYz-vcRBC0fzai0ggMEPLusy0N5HQ57rEU8t-RhMw,11
|
|
11
|
+
shvcli_ell-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
shvcli_ell
|