summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-10-04 10:15:17 +0200
committerThomas Haller <thaller@redhat.com>2022-10-06 13:40:30 +0200
commit77e0041b274826d17ed94a1680a045aec756819d (patch)
treedaafd67d35ee0c01e706ed39cfb1088d36f10119
parentc1bebdfaa6994a053a0905c9348009ae5bc3de8c (diff)
tools: sort the settings in "generate-docs-nm-property-infos.py" by name
"nm-setting-ip-config.c" is a base class for IPv4 and IPv6 settings. So far, any tags there were ignored, which was not obvious. It can be useful to document common properties there. Well, maybe every property better has a IPv4/IPv6 specific text, but that should not be a technical limitation of the tool. So also honor the base file for "ipv4" and "ipv6" settings. When doing that, the settings are no longer processed in the order as they are provided on the command line. Because, one file would be parsed twice, it wouldn't make much sense. Instead, sort the my setting name. The advantage is that the generated XML is independent from the order that make/meson passes to the tool.
-rwxr-xr-xtools/generate-docs-nm-property-infos.py55
1 files changed, 44 insertions, 11 deletions
diff --git a/tools/generate-docs-nm-property-infos.py b/tools/generate-docs-nm-property-infos.py
index ce30100e49..dd40531e70 100755
--- a/tools/generate-docs-nm-property-infos.py
+++ b/tools/generate-docs-nm-property-infos.py
@@ -60,7 +60,7 @@ def get_setting_names(source_file):
if file_base == "nm-setting-ip-config":
# Special case ip-config, which is a base class.
- return None
+ return 0, ("ipv4", "ipv6")
header_file = "%s/libnm-core-public/%s.h" % (path_prefix, file_base)
@@ -75,7 +75,7 @@ def get_setting_names(source_file):
for line in f:
m = re.search(r"^#define +NM_SETTING_.+SETTING_NAME\s+\"(\S+)\"$", line)
if m:
- return m.group(1)
+ return 1, (m.group(1),)
raise Exception(
'Can\'t find setting name in header file "%s" for "%s"'
@@ -84,10 +84,35 @@ def get_setting_names(source_file):
def get_file_infos(source_files):
+ # This function parses the source files and detects the
+ # used setting name. The returned sections are sorted by setting
+ # name.
+ #
+ # The file "nm-setting-ip-config.c" can contain information
+ # for "ipv4" and "ipv6" settings. Thus, to sort the files
+ # is a bit more involved.
+
+ # First, get a list of priority and setting-names that belong
+ # to the source file. Sort by priority,setting-names. It's
+ # important that "nm-setting-ip-config.c" gets parsed before
+ # "nm-setting-ip[46]-config.c".
+ file_infos = []
for source_file in source_files:
- setting_name = get_setting_names(source_file)
- if setting_name:
- yield setting_name, source_file
+ priority, setting_names = get_setting_names(source_file)
+ file_infos.append((priority, setting_names, source_file))
+ file_infos.sort()
+
+ d = {}
+ for priority, setting_names, source_file in file_infos:
+ for setting_name in setting_names:
+ l = d.get(setting_name, None)
+ if l is None:
+ l = list()
+ d[setting_name] = l
+ l.append(source_file)
+ for key in sorted(d.keys()):
+ for f in d[key]:
+ yield key, f
KEYWORD_XML_TYPE_NESTED = "nested"
@@ -368,13 +393,13 @@ def test_file_location():
def test_get_setting_names():
- assert "connection" == get_setting_names(
+ assert (1, ("connection",)) == get_setting_names(
t_srcdir() + "/src/libnm-core-impl/nm-setting-connection.c"
)
- assert "ipv4" == get_setting_names(
+ assert (1, ("ipv4",)) == get_setting_names(
t_srcdir() + "/src/libnm-core-impl/nm-setting-ip4-config.c"
)
- assert None == get_setting_names(
+ assert (0, ("ipv4", "ipv6")) == get_setting_names(
t_srcdir() + "/src/libnm-core-impl/nm-setting-ip-config.c"
)
@@ -385,18 +410,26 @@ def test_get_file_infos():
assert [
(
+ "802-3-ethernet",
+ t_setting_c("wired"),
+ ),
+ (
"connection",
t_setting_c("connection"),
),
(
"ipv4",
+ t_setting_c("ip-config"),
+ ),
+ (
+ "ipv4",
t_setting_c("ip4-config"),
),
- ("proxy", t_setting_c("proxy")),
(
- "802-3-ethernet",
- t_setting_c("wired"),
+ "ipv6",
+ t_setting_c("ip-config"),
),
+ ("proxy", t_setting_c("proxy")),
] == list(get_file_infos([t_setting_c(x) for x in t]))