mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
This was requested in review: https://github.com/systemd/systemd/pull/27846#discussion_r1210383265 I kept this as separate commit because the change would impact both of the previous commits and splitting it up seems like unnecessary work. The result is unchanged. v2: - use universal_newlines=True to keep compat with Python 3.6 on C8S.
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
import re
|
|
import shlex
|
|
import subprocess
|
|
import sys
|
|
|
|
OVERRIDES = {
|
|
'autoneg' : 'autonegotiation',
|
|
}
|
|
|
|
mode, cpp, header = sys.argv[1:]
|
|
xml = mode == '--xml'
|
|
|
|
command = [*shlex.split(cpp), '-include', header, '-']
|
|
out = subprocess.check_output(command, stdin=subprocess.DEVNULL, universal_newlines=True)
|
|
|
|
lines = iter(out.splitlines())
|
|
for line in lines:
|
|
if line.startswith('enum ethtool_link_mode_bit_indices {'):
|
|
break
|
|
|
|
entries = []
|
|
for line in lines:
|
|
if line.startswith('}'):
|
|
break
|
|
# ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0,
|
|
m = re.match(r'^\s*(ETHTOOL_LINK_MODE_((\d*).*)_BIT)\s*=\s*(\d+),', line)
|
|
if not m:
|
|
continue
|
|
enum, name, speed, value = m.groups()
|
|
|
|
name = name.lower().replace('_', '-')
|
|
name = OVERRIDES.get(name, name)
|
|
|
|
duplex = name.split('-')[-1].lower()
|
|
if duplex not in {'half', 'full'}:
|
|
duplex = ''
|
|
|
|
entries += [(enum, name, speed, value, duplex)]
|
|
|
|
if xml:
|
|
print(' <tbody>')
|
|
|
|
entries.sort(key=lambda entry: (int(entry[2]) if entry[2] else 1e20, entry[4], entry[1], entry[3]))
|
|
|
|
for enum, name, speed, value, duplex in entries:
|
|
if xml:
|
|
print(f'''\
|
|
<row><entry><option>{name}</option></entry>
|
|
<entry>{speed}</entry><entry>{duplex}</entry></row>
|
|
''')
|
|
else:
|
|
enum = f'[{enum}]'
|
|
print(f' {enum:50} = "{name}",')
|
|
|
|
if xml:
|
|
print(' </tbody>')
|
|
|
|
assert len(entries) >= 99
|