From 202bf85f55cf8476e84299e2d4de77527847611c Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Thu, 17 Apr 2025 12:11:18 +0300 Subject: [PATCH 1/6] [+] partially wrap ip addr --- .../online/fxreader/pr34/commands_typed/os.py | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/python/online/fxreader/pr34/commands_typed/os.py b/python/online/fxreader/pr34/commands_typed/os.py index dc04d62..34d76b0 100644 --- a/python/online/fxreader/pr34/commands_typed/os.py +++ b/python/online/fxreader/pr34/commands_typed/os.py @@ -5,10 +5,11 @@ import ctypes import os import sys import logging +import dataclasses logger = logging.getLogger(__name__) -from typing import (overload, Optional, Literal,) +from typing import (overload, Optional, Literal, Any,) from .cli_bootstrap import PyProject @@ -89,4 +90,45 @@ def runtime_libdirs_init( ctypes.cdll.LoadLibrary(preload_found) else: - raise NotImplementedError \ No newline at end of file + raise NotImplementedError + +class interfaces_index_t: + @dataclasses.dataclass(frozen=True) + class Interface: + @dataclasses.dataclass(frozen=True) + class AddrInfo: + family: str + local: str + + name: str + addr_info: list[AddrInfo] + +def interfaces_index() -> list[Interfaces]: + ip_addr_res: Any = json.loads( + subprocess.check_output([ + 'ip', '-j', 'addr', + ]).decode('utf-8') + ) + + assert isinstance(ip_addr_res, list) + + ip_addr_res2 = cast(list[Any], p_addr_res,) + + assert all([ + isinstance(o, dict) + for o in ip_addr_res2.items() + ]) + + ip_addr_res3 = cast(list[dict[Any, Any]], ip_addr_res2) + + assert all([ + assert isinstance(k, str) + for k, v in o.items() + for o in ip_addr_res3 + ]) + + ip_addr_res4 = cast(list[dict[str, Any]], ip_addr_res3) + + res : list[interfaces_index_t.Interface] = [] + + for o in ip_addr_res4: From 799280f07405c06d91ba8f63a1f167350fc1dee3 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Fri, 18 Apr 2025 16:30:10 +0300 Subject: [PATCH 2/6] [+] add interfaces_index --- .../online/fxreader/pr34/commands_typed/os.py | 37 +++++-------------- python/pyproject.toml | 2 +- ...xreader_pr34-0.1.5.9+27.1-py3-none-any.whl | 3 ++ 3 files changed, 14 insertions(+), 28 deletions(-) create mode 100644 releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl diff --git a/python/online/fxreader/pr34/commands_typed/os.py b/python/online/fxreader/pr34/commands_typed/os.py index 34d76b0..c2bdc86 100644 --- a/python/online/fxreader/pr34/commands_typed/os.py +++ b/python/online/fxreader/pr34/commands_typed/os.py @@ -1,5 +1,7 @@ import shutil import glob +import subprocess +import pydantic import pathlib import ctypes import os @@ -93,9 +95,9 @@ def runtime_libdirs_init( raise NotImplementedError class interfaces_index_t: - @dataclasses.dataclass(frozen=True) + @dataclasses.dataclass class Interface: - @dataclasses.dataclass(frozen=True) + @dataclasses.dataclass class AddrInfo: family: str local: str @@ -103,32 +105,13 @@ class interfaces_index_t: name: str addr_info: list[AddrInfo] -def interfaces_index() -> list[Interfaces]: - ip_addr_res: Any = json.loads( +def interfaces_index() -> list[interfaces_index_t.Interface]: + res = pydantic.RootModel[ + list[interfaces_index_t.Interface] + ].model_validate_json( subprocess.check_output([ 'ip', '-j', 'addr', ]).decode('utf-8') - ) + ).root - assert isinstance(ip_addr_res, list) - - ip_addr_res2 = cast(list[Any], p_addr_res,) - - assert all([ - isinstance(o, dict) - for o in ip_addr_res2.items() - ]) - - ip_addr_res3 = cast(list[dict[Any, Any]], ip_addr_res2) - - assert all([ - assert isinstance(k, str) - for k, v in o.items() - for o in ip_addr_res3 - ]) - - ip_addr_res4 = cast(list[dict[str, Any]], ip_addr_res3) - - res : list[interfaces_index_t.Interface] = [] - - for o in ip_addr_res4: + return res diff --git a/python/pyproject.toml b/python/pyproject.toml index 35976b5..835d2fe 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'online.fxreader.pr34' -version = '0.1.5.9' +version = '0.1.5.9+27.1' dependencies = [ #"-r requirements.txt", diff --git a/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl new file mode 100644 index 0000000..55e3df5 --- /dev/null +++ b/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0f6f824ee5e87742e4744b13bc86787c9cbd8eecec722103aa603f6fff9566e +size 69644 From fdcd67aae6ff68be1524d833d027ee4ca65f537b Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Fri, 18 Apr 2025 16:38:36 +0300 Subject: [PATCH 3/6] [+] implement interfaces_index --- python/online/fxreader/pr34/commands_typed/os.py | 9 +++++++-- .../online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python/online/fxreader/pr34/commands_typed/os.py b/python/online/fxreader/pr34/commands_typed/os.py index c2bdc86..ee2dfbe 100644 --- a/python/online/fxreader/pr34/commands_typed/os.py +++ b/python/online/fxreader/pr34/commands_typed/os.py @@ -11,7 +11,7 @@ import dataclasses logger = logging.getLogger(__name__) -from typing import (overload, Optional, Literal, Any,) +from typing import (overload, Optional, Literal, Any, Annotated,) from .cli_bootstrap import PyProject @@ -102,7 +102,12 @@ class interfaces_index_t: family: str local: str - name: str + name: Annotated[ + str, + pydantic.Field( + alias='ifname', + ) + ] addr_info: list[AddrInfo] def interfaces_index() -> list[interfaces_index_t.Interface]: diff --git a/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl index 55e3df5..36c69be 100644 --- a/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl +++ b/releases/whl/online_fxreader_pr34-0.1.5.9+27.1-py3-none-any.whl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c0f6f824ee5e87742e4744b13bc86787c9cbd8eecec722103aa603f6fff9566e -size 69644 +oid sha256:5218a26e4e8c3aafbe9a35223ad92e4e54ca12d44f2c3b209b52189ae1d56899 +size 69677 From a912e1b6bf8e54ab73e37363fe907a57c6f35783 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sat, 19 Apr 2025 18:10:07 +0300 Subject: [PATCH 4/6] [+] update http_server 1. remove ping dependency; --- python/online/fxreader/pr34/commands.py | 16 ++++++++++++---- python/pyproject.toml | 2 +- ...e_fxreader_pr34-0.1.5.9+27.2-py3-none-any.whl | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 releases/whl/online_fxreader_pr34-0.1.5.9+27.2-py3-none-any.whl diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index ac10bf0..3ddc74a 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -1158,6 +1158,7 @@ done' ) def http_server(argv): + from .commands_typed import os as commands_os assert isinstance(argv, list) and all([isinstance(o, str) for o in argv]) parser = optparse.OptionParser() parser.add_option( @@ -1215,10 +1216,17 @@ def http_server(argv): try: assert not socket.inet_aton(options.host) is None - subprocess.check_call([ - 'ping', '-w', '1', - options.host - ]) + # subprocess.check_call([ + # 'ping', '-w', '1', + # options.host + # ]) + assert options.host in sum([ + [ + o2.local + for o2 in o.addr_info + ] + for o in commands_os.interfaces_index() + ], []) except Exception: raise RuntimeError('invalid ip address %s' % options.host) diff --git a/python/pyproject.toml b/python/pyproject.toml index 835d2fe..6c471a1 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'online.fxreader.pr34' -version = '0.1.5.9+27.1' +version = '0.1.5.9+27.2' dependencies = [ #"-r requirements.txt", diff --git a/releases/whl/online_fxreader_pr34-0.1.5.9+27.2-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.9+27.2-py3-none-any.whl new file mode 100644 index 0000000..1facb36 --- /dev/null +++ b/releases/whl/online_fxreader_pr34-0.1.5.9+27.2-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eefcb7da4191f1b10128201346c09db768692a1f29d3f64a7f19d1440799b279 +size 69753 From dc39583cc6af1e2e741767e32ab7598a0c4f7d47 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Mon, 21 Apr 2025 17:45:53 +0300 Subject: [PATCH 5/6] [+] add auto addr search for public, http-server --- python/online/fxreader/pr34/commands.py | 15 +++++++++++++++ python/pyproject.toml | 2 +- ...ne_fxreader_pr34-0.1.5.9+27.3-py3-none-any.whl | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 releases/whl/online_fxreader_pr34-0.1.5.9+27.3-py3-none-any.whl diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index 3ddc74a..e46505d 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -1215,6 +1215,21 @@ def http_server(argv): assert options.port >= 1 try: + if options.public and options.host == '0.0.0.0': + found : bool = False + for o in commands_os.interfaces_index(): + if found: + break + for o2 in o.addr_info: + if o2.family == 'inet' and o2.local != '127.0.0.1': + options.host = o2.local + logger.info(dict( + host=options.host, + msg='found', + )) + found = True + break + assert not socket.inet_aton(options.host) is None # subprocess.check_call([ # 'ping', '-w', '1', diff --git a/python/pyproject.toml b/python/pyproject.toml index 6c471a1..034c986 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'online.fxreader.pr34' -version = '0.1.5.9+27.2' +version = '0.1.5.9+27.3' dependencies = [ #"-r requirements.txt", diff --git a/releases/whl/online_fxreader_pr34-0.1.5.9+27.3-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.9+27.3-py3-none-any.whl new file mode 100644 index 0000000..542dfd8 --- /dev/null +++ b/releases/whl/online_fxreader_pr34-0.1.5.9+27.3-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e209b950527be9887687ddb0cf7a866595c0222f6492df4b7860683dffc9e030 +size 69874 From 2fef63a253b5daa928fc0583a9b0d4783deb5100 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Mon, 21 Apr 2025 18:07:42 +0300 Subject: [PATCH 6/6] [+] update auto host, http-server --- python/online/fxreader/pr34/commands.py | 2 +- python/pyproject.toml | 2 +- .../whl/online_fxreader_pr34-0.1.5.9+27.4-py3-none-any.whl | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 releases/whl/online_fxreader_pr34-0.1.5.9+27.4-py3-none-any.whl diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index e46505d..c991081 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -1215,7 +1215,7 @@ def http_server(argv): assert options.port >= 1 try: - if options.public and options.host == '0.0.0.0': + if not options.docker and options.host == '0.0.0.0': found : bool = False for o in commands_os.interfaces_index(): if found: diff --git a/python/pyproject.toml b/python/pyproject.toml index 034c986..b773374 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'online.fxreader.pr34' -version = '0.1.5.9+27.3' +version = '0.1.5.9+27.4' dependencies = [ #"-r requirements.txt", diff --git a/releases/whl/online_fxreader_pr34-0.1.5.9+27.4-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.9+27.4-py3-none-any.whl new file mode 100644 index 0000000..de428de --- /dev/null +++ b/releases/whl/online_fxreader_pr34-0.1.5.9+27.4-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8560d66935c9bf65cb848f4eb1385c43cb117644145e293ded589d6d5b5d967c +size 69872