Compare commits

...

4 Commits

Author SHA1 Message Date
a912e1b6bf [+] update http_server
1. remove ping dependency;
2025-04-19 18:10:07 +03:00
fdcd67aae6 [+] implement interfaces_index 2025-04-18 16:38:36 +03:00
799280f074 [+] add interfaces_index 2025-04-18 16:30:10 +03:00
202bf85f55 [+] partially wrap ip addr 2025-04-17 12:11:18 +03:00
5 changed files with 51 additions and 7 deletions

@ -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)

@ -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
@ -90,3 +93,30 @@ def runtime_libdirs_init(
ctypes.cdll.LoadLibrary(preload_found)
else:
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

@ -1,6 +1,6 @@
[project]
name = 'online.fxreader.pr34'
version = '0.1.5.9'
version = '0.1.5.9+27.2'
dependencies = [
#"-r requirements.txt",

Binary file not shown.

Binary file not shown.