diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index ac10bf0..c991081 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( @@ -1214,11 +1215,33 @@ def http_server(argv): assert options.port >= 1 try: + if not options.docker 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', - 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/online/fxreader/pr34/commands_typed/os.py b/python/online/fxreader/pr34/commands_typed/os.py index dc04d62..ee2dfbe 100644 --- a/python/online/fxreader/pr34/commands_typed/os.py +++ b/python/online/fxreader/pr34/commands_typed/os.py @@ -1,14 +1,17 @@ import shutil import glob +import subprocess +import pydantic import pathlib 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, Annotated,) from .cli_bootstrap import PyProject @@ -89,4 +92,31 @@ 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 + class Interface: + @dataclasses.dataclass + class AddrInfo: + family: str + local: str + + name: Annotated[ + str, + pydantic.Field( + alias='ifname', + ) + ] + addr_info: list[AddrInfo] + +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 + + return res 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..36c69be --- /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:5218a26e4e8c3aafbe9a35223ad92e4e54ca12d44f2c3b209b52189ae1d56899 +size 69677 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 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 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