[+] partially wrap ip addr
This commit is contained in:
parent
7fa2a8a83c
commit
202bf85f55
@ -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
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user