mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
formatting for regexes
This commit is contained in:
@ -355,69 +355,135 @@ def parse(
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
# Linux syntax
|
# Linux syntax
|
||||||
re_linux_interface = re.compile(
|
re_linux_interface = re.compile(r'''
|
||||||
r"(?P<name>[a-zA-Z0-9:._-]+)\s+Link encap:(?P<type>\S+\s?\S+)(\s+HWaddr\s+\b"
|
(?P<name>[a-zA-Z0-9:._-]+)\s+
|
||||||
r"(?P<mac_addr>[0-9A-Fa-f:?]+))?",
|
Link encap:(?P<type>\S+\s?\S+)
|
||||||
re.I)
|
(\s+HWaddr\s+\b(?P<mac_addr>[0-9A-Fa-f:?]+))?
|
||||||
re_linux_ipv4 = re.compile(
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
r"inet addr:(?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+Bcast:"
|
)
|
||||||
r"(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+Mask:(?P<mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})",
|
re_linux_ipv4 = re.compile(r'''
|
||||||
re.I)
|
inet addr:(?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+
|
||||||
re_linux_ipv6 = re.compile(
|
Bcast:(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?\s+
|
||||||
r"inet6 addr:\s+(?P<address>\S+)/(?P<mask>[0-9]+)\s+Scope:(?P<scope>Link|Host)",
|
Mask:(?P<mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})
|
||||||
re.I)
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
re_linux_state = re.compile(
|
)
|
||||||
r"\W+(?P<state>(?:\w+\s)+)(?:\s+)?MTU:(?P<mtu>[0-9]+)\s+Metric:(?P<metric>[0-9]+)", re.I)
|
re_linux_ipv6 = re.compile(r'''
|
||||||
re_linux_rx = re.compile(
|
inet6 addr:\s+(?P<address>\S+)/
|
||||||
r"RX packets:(?P<rx_packets>[0-9]+)\s+errors:(?P<rx_errors>[0-9]+)\s+dropped:"
|
(?P<mask>[0-9]+)\s+
|
||||||
r"(?P<rx_dropped>[0-9]+)\s+overruns:(?P<rx_overruns>[0-9]+)\s+frame:(?P<rx_frame>[0-9]+)",
|
Scope:(?P<scope>Link|Host)
|
||||||
re.I)
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
re_linux_tx = re.compile(
|
)
|
||||||
r"TX packets:(?P<tx_packets>[0-9]+)\s+errors:(?P<tx_errors>[0-9]+)\s+dropped:"
|
re_linux_state = re.compile(r'''
|
||||||
r"(?P<tx_dropped>[0-9]+)\s+overruns:(?P<tx_overruns>[0-9]+)\s+carrier:(?P<tx_carrier>[0-9]+)",
|
\W+(?P<state>(?:\w+\s)+)(?:\s+)?
|
||||||
re.I)
|
MTU:(?P<mtu>[0-9]+)\s+
|
||||||
re_linux_bytes = re.compile(r"\W+RX bytes:(?P<rx_bytes>\d+)\s+\(.*\)\s+TX bytes:(?P<tx_bytes>\d+)\s+\(.*\)", re.I)
|
Metric:(?P<metric>[0-9]+)
|
||||||
re_linux_tx_stats = re.compile(r"collisions:(?P<tx_collisions>[0-9]+)\s+txqueuelen:[0-9]+", re.I)
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_linux_rx = re.compile(r'''
|
||||||
|
RX packets:(?P<rx_packets>[0-9]+)\s+
|
||||||
|
errors:(?P<rx_errors>[0-9]+)\s+
|
||||||
|
dropped:(?P<rx_dropped>[0-9]+)\s+
|
||||||
|
overruns:(?P<rx_overruns>[0-9]+)\s+
|
||||||
|
frame:(?P<rx_frame>[0-9]+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_linux_tx = re.compile(r'''
|
||||||
|
TX packets:(?P<tx_packets>[0-9]+)\s+
|
||||||
|
errors:(?P<tx_errors>[0-9]+)\s+
|
||||||
|
dropped:(?P<tx_dropped>[0-9]+)\s+
|
||||||
|
overruns:(?P<tx_overruns>[0-9]+)\s+
|
||||||
|
carrier:(?P<tx_carrier>[0-9]+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_linux_bytes = re.compile(r'''
|
||||||
|
\W+RX bytes:(?P<rx_bytes>\d+)\s+\(.*\)\s+
|
||||||
|
TX bytes:(?P<tx_bytes>\d+)\s+\(.*\)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_linux_tx_stats = re.compile(r'''
|
||||||
|
collisions:(?P<tx_collisions>[0-9]+)\s+
|
||||||
|
txqueuelen:[0-9]+
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
|
||||||
# OpenBSD syntax
|
# OpenBSD syntax
|
||||||
re_openbsd_interface = re.compile(
|
re_openbsd_interface = re.compile(r'''
|
||||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)?>\s+mtu\s+(?P<mtu>[0-9]+)",
|
(?P<name>[a-zA-Z0-9:._-]+):\s+
|
||||||
re.I)
|
flags=(?P<flags>[0-9]+)
|
||||||
re_openbsd_ipv4 = re.compile(
|
<(?P<state>\S+)?>\s+
|
||||||
r"inet (?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+"
|
mtu\s+(?P<mtu>[0-9]+)
|
||||||
r"(?P<mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+"
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
r"(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
)
|
||||||
re.I)
|
re_openbsd_ipv4 = re.compile(r'''
|
||||||
re_openbsd_ipv6 = re.compile(
|
inet\s(?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+
|
||||||
r'inet6\s+(?P<address>\S+)\s+prefixlen\s+(?P<mask>[0-9]+)\s+scopeid\s+(?P<scope>\w+x\w+)<(?P<type>link|host|global)>',
|
(?P<mask>(?:[0-9]{1,3}\.){3}[0-9]{1,3})(\s+broadcast\s+
|
||||||
re.I)
|
(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?
|
||||||
re_openbsd_details = re.compile(
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
r"\S+\s+(?:(?P<mac_addr>[0-9A-Fa-f:?]+)\s+)?txqueuelen\s+[0-9]+\s+\((?P<type>\S+\s?\S+)\)", re.I)
|
)
|
||||||
re_openbsd_rx = re.compile(r"RX packets (?P<rx_packets>[0-9]+)\s+bytes\s+(?P<rx_bytes>\d+)\s+.*", re.I)
|
re_openbsd_ipv6 = re.compile(r'''
|
||||||
re_openbsd_rx_stats = re.compile(
|
inet6\s+(?P<address>\S+)\s+
|
||||||
r"RX errors (?P<rx_errors>[0-9]+)\s+dropped\s+(?P<rx_dropped>[0-9]+)\s+overruns\s+"
|
prefixlen\s+(?P<mask>[0-9]+)\s+
|
||||||
r"(?P<rx_overruns>[0-9]+)\s+frame\s+(?P<rx_frame>[0-9]+)",
|
scopeid\s+(?P<scope>\w+x\w+)
|
||||||
re.I)
|
<(?P<type>link|host|global)>
|
||||||
re_openbsd_tx = re.compile(r"TX packets (?P<tx_packets>[0-9]+)\s+bytes\s+(?P<tx_bytes>\d+)\s+.*", re.I)
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
re_openbsd_tx_stats = re.compile(
|
)
|
||||||
r"TX errors (?P<tx_errors>[0-9]+)\s+dropped\s+(?P<tx_dropped>[0-9]+)\s+overruns\s+"
|
re_openbsd_details = re.compile(r'''
|
||||||
r"(?P<tx_overruns>[0-9]+)\s+carrier\s+(?P<tx_carrier>[0-9]+)\s+collisions\s+(?P<tx_collisions>[0-9]+)",
|
\S+\s+(?:(?P<mac_addr>[0-9A-Fa-f:?]+)\s+)?
|
||||||
re.I)
|
txqueuelen\s+[0-9]+\s+
|
||||||
|
\((?P<type>\S+\s?\S+)\)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_openbsd_rx = re.compile(r'''
|
||||||
|
RX\spackets\s(?P<rx_packets>[0-9]+)\s+
|
||||||
|
bytes\s+(?P<rx_bytes>\d+)\s+.*
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_openbsd_rx_stats = re.compile(r'''
|
||||||
|
RX\serrors\s(?P<rx_errors>[0-9]+)\s+
|
||||||
|
dropped\s+(?P<rx_dropped>[0-9]+)\s+
|
||||||
|
overruns\s+(?P<rx_overruns>[0-9]+)\s+
|
||||||
|
frame\s+(?P<rx_frame>[0-9]+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_openbsd_tx = re.compile(r'''
|
||||||
|
TX\spackets\s(?P<tx_packets>[0-9]+)\s+
|
||||||
|
bytes\s+(?P<tx_bytes>\d+)\s+.*
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_openbsd_tx_stats = re.compile(r'''
|
||||||
|
TX\serrors\s(?P<tx_errors>[0-9]+)\s+
|
||||||
|
dropped\s+(?P<tx_dropped>[0-9]+)\s+
|
||||||
|
overruns\s+(?P<tx_overruns>[0-9]+)\s+
|
||||||
|
carrier\s+(?P<tx_carrier>[0-9]+)\s+
|
||||||
|
collisions\s+(?P<tx_collisions>[0-9]+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
|
||||||
# FreeBSD syntax
|
# FreeBSD syntax
|
||||||
re_freebsd_interface = re.compile(
|
re_freebsd_interface = re.compile(r'''
|
||||||
r"(?P<name>[a-zA-Z0-9:._-]+):\s+flags=(?P<flags>[0-9]+)<(?P<state>\S+)>\s+metric\s+"
|
(?P<name>[a-zA-Z0-9:._-]+):\s+
|
||||||
r"(?P<metric>[0-9]+)\s+mtu\s+(?P<mtu>[0-9]+)",
|
flags=(?P<flags>[0-9]+)
|
||||||
re.I)
|
<(?P<state>\S+)>\s+
|
||||||
re_freebsd_ipv4 = re.compile(
|
metric\s+(?P<metric>[0-9]+)\s+
|
||||||
r"inet (?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+netmask\s+(?P<mask>0x\S+)(\s+broadcast\s+"
|
mtu\s+(?P<mtu>[0-9]+)
|
||||||
r"(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?",
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
re.I)
|
)
|
||||||
re_freebsd_ipv6 = re.compile(r"\s?inet6\s(?P<address>.*)(?:\%\w+\d+)\sprefixlen\s(?P<mask>\d+)(?:\s\w+)?\sscopeid\s(?P<scope>\w+x\w+)", re.I)
|
re_freebsd_ipv4 = re.compile(r'''
|
||||||
re_freebsd_details = re.compile(r"ether\s+(?P<mac_addr>[0-9A-Fa-f:?]+)", re.I)
|
inet\s(?P<address>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s+
|
||||||
|
netmask\s+(?P<mask>0x\S+)(\s+
|
||||||
|
broadcast\s+(?P<broadcast>(?:[0-9]{1,3}\.){3}[0-9]{1,3}))?
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_freebsd_ipv6 = re.compile(r'''
|
||||||
|
\s?inet6\s(?P<address>.*)(?:\%\w+\d+)\s
|
||||||
|
prefixlen\s(?P<mask>\d+)(?:\s\w+)?\s
|
||||||
|
scopeid\s(?P<scope>\w+x\w+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
re_freebsd_details = re.compile(r'''
|
||||||
|
ether\s+(?P<mac_addr>[0-9A-Fa-f:?]+)
|
||||||
|
''', re.IGNORECASE | re.VERBOSE
|
||||||
|
)
|
||||||
|
|
||||||
re_linux = [
|
re_linux = [
|
||||||
re_linux_interface, re_linux_ipv4, re_linux_ipv6, re_linux_state, re_linux_rx, re_linux_tx,
|
re_linux_interface, re_linux_ipv4, re_linux_ipv6, re_linux_state, re_linux_rx, re_linux_tx,
|
||||||
|
10
tests/fixtures/freebsd12/ifconfig-extra-fields.out
vendored
Normal file
10
tests/fixtures/freebsd12/ifconfig-extra-fields.out
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
cxl3: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
|
||||||
|
options=6ec07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6,HWRXTSTMP,NOMAP>
|
||||||
|
ether 00:07:43:3d:b7:70
|
||||||
|
hwaddr 00:07:43:3d:b7:88 media: Ethernet 10Gbase-LR <full-duplex,rxpause,txpause>
|
||||||
|
status: active
|
||||||
|
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
|
||||||
|
plugged: SFP/SFP+/SFP28 10G Base-LR (LC)
|
||||||
|
vendor: INNOLIGHT PN: TR-PX13L-N00 SN: INJBL0431986 DATE: 2020-01-04
|
||||||
|
module temperature: 21.20 C voltage: 3.16 Volts
|
||||||
|
lane 1: RX power: 0.49 mW (-3.10 dBm) TX bias: 23.85 mA
|
Reference in New Issue
Block a user