Commit Graph

26 Commits

Author SHA1 Message Date
Thomas Haller
28a1afca63
python: reformat with black-23.7.0-2.fc39.noarch
The base image for the "check-tree" test got bumped to Fedora 39.  This
brings a new python-black version (23.7.0 vs. 22.8.0) and requires
reformatting.

Maybe we should stick to 22.8.0, via `pip install`. But it seems better
to just follow the latest black version (the one from current Fedora).

So do the reformatting instead.

https://black.readthedocs.io/en/stable/change_log.html#id38
2023-12-06 11:56:11 +01:00
Íñigo Huguet
c9ced304d2 man nm-setting-*: add "expand enumvals" capability to property-infos
In some cases, properties documentation might require to provide an
explanation of each of the possible values that the property accepts.
If the possible values are the variants of an enum, we can use the
introspection data to get all the possible values for that enum and
their descriptions. With that info, we can automatically generate the
documentation with an always up to date list of accepted values.

Add a new "expand enumvals" feature: it will convert a token with the
format `#EnumName:*` to a list of all the possible values. For the
docbook (description-docbook field in the XML), it is expanded to a
bulleted list of all the values and their respective documentations.

This feature is limited to the "property-infos" comments (those like
---nmcli---, ---dbus---, etc). This comments are used only to generate
the nm-settings-* manual pages. For the documentation under the doc/
folder this is not needed: it's not supported by gtkdoc and, anyway,
it's better to use just `#EnumName` that will generate an HTML link.

Additionally, expansion of `%ENUM_VALUE` is now supported in the
property-infos comments. Instead of expanding them in the same style
than gtkdoc "ENUM_VALUE (num)", it is expanded in a format more suitable
for the nm-setting-* manual pages:
- for nmcli: value_nick (num)
- others: num (value_nick)

Also, fix typo in meson build file propery -> property.
2023-09-21 15:57:35 +02:00
Íñigo Huguet
5c6ae44e00 man nm-settings-nmcli: add "Special values" field
If there are properties that accept special values apart from the
normally accepted values, or any of those values has an special meaning,
it can be shown as "Special value", indicating the nicknames and numbers
that can be used to select it.
2023-09-21 15:57:35 +02:00
Thomas Haller
42aa225185
docs: better handle description tags in generate-docs-nm-settings-docs-merge.py
When we generate the manual page for nm-settings-nmcli, we run:

   "/usr/bin/python" \
        ./tools/generate-docs-nm-settings-docs-merge.py \
        --only-from-first \
        man/nm-settings-docs-nmcli.xml \
        src/nmcli/gen-metadata-nm-settings-nmcli.xml \
        src/libnm-client-impl/nm-property-infos-nmcli.xml \
        src/libnm-client-impl/nm-settings-docs-gir.xml

If "gen-metadata-nm-settings-nmcli.xml" contains either a <description>
or a <description-docbook>, then we must not continue searching the
other XML documents. The user provided an explicit override, and
fallback (search further) is wrong. Previously, we might take
<description> from the first file, and <description-docbook> from the
second file. As "man/nm-settings-nmcli.xsl" prefers
<description-docbook>, it takes the wrong text. Instead, as we search
the files during merge, we must prefer the first one.

Note that the change doesn't really matter anymore, because each XML
now must also contain both <description> and <description-docbook>.
There is an assertion for that.

Also, stop generating <deprecated-docbook>. First, it lacked the
important "since=" attribute and was necessary. Also, it's redundant and
does not contain anything interesting. So far, we don't need special
formatting for the deprecated message, and we likely never will.

Also, stop accepting or generating the "description=" attribute. This
should always be an XML element now.
2023-05-19 12:52:00 +02:00
Thomas Haller
89abede3df
docs: rework generating property infos to use <description> element
The "generate-docs-nm-property-infos.py" script parses the tags like
"---nmcli---" and generates an XML.

Rework it:

- don't put long text descriptions in a "description=" XML attribute.
  Instead, use an XML element. That is in line with what
  "generate-docs-nm-settings-docs-gir.py" does, which generates
  a similar file.

- if there is no <description-docbook> element, generate one based
  on <description>. That is important, because we want to create
  paragraphs.
  It's also important because "generate-docs-nm-settings-docs-gir.py"
  tends to generate <description-docbook> from the libnm/gir data.
  However, if you specify a "---nmcli---" override, then that should
  automatically apply to <description> and <description-docbook>.
2023-05-19 12:52:00 +02:00
Thomas Haller
ea5cd47bc4
tools: drop unused variables from "tools/generate-docs-nm-property-infos.py"
Found by lgtm.com.
2022-10-25 12:12:44 +02:00
Thomas Haller
70fee1cf46
tools: avoid Python 3 f-string in "generate-docs-nm-property-infos.py"
We also need to build with python2. No f-strings.

Fixes: 8fc7b6df12 ('tools: rework generating documentation from libnm meta data')
2022-10-07 21:08:39 +02:00
Thomas Haller
77e0041b27
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.
2022-10-06 13:40:30 +02:00
Thomas Haller
c1bebdfaa6
tools: don't set empty attributes in "generate-docs-nm-property-infos.py"
If the information is missing, the entire attribute should not be there.
Don't set it to the empty word.

Also, don't alias the "variable" attribute to the "name". It's not clear
what the "variable" fields is supposed to mean, but if it's not
explicitly set, don't make up the information. If a user of that
information cares, the can always fallback to the "name".
2022-10-06 13:40:30 +02:00
Thomas Haller
e56f7f5c2d
tools: don't write empty XML nodes in "generate-docs-nm-property-infos.py"
This generates '<setting name="XXX">\n</setting>' nodes in case there is
no additional data. Don't do that. Just '<setting name="XXX"/>'
2022-10-06 13:40:29 +02:00
Thomas Haller
8899ecc0d8
tools: preserve newlines and indentation in "generate-docs-nm-property-infos.py"
Our docs can be long. It's important to be able to express paragraphs.
Honor a blank line to include a newline. For XML often whitespace is
ignored, but our tools can choose to honor the newline.

Also, don't strip the whitespace from the beginning and the end.
We keep whitespace for a certain indentation level, but additional
whitespace gets preserved. This is less important, because regular
spaces is indeed irrelevant. But when we write the annotations, we
should be in full control over spaces.
2022-10-06 13:40:29 +02:00
Thomas Haller
8fc7b6df12
tools: rework generating documentation from libnm meta data
With the given input, this produces *exactly* the same XML as before.

- the parsing is now stricter (and thus the code more verbose). No
  funny stuff, get the annotations correct.
- on parsing errors, we log now the affecting lines
- "nm-setting-ip-config.c" is a base class. Previously it was ignored
  and for the moment we still do that. Next, we will allow to also
  describe properties there.
- prepare the code to better preserve whitespace, indentation and line
  wrappings. In particular, to honor a blank line to indicate a line break
  and support paragraphs. This is not yet done to compare the output
  to before, but will be turned on with a small patch next.
- the code will make it simple to promote the XML attributes to
  nodes. Attributes aren't great, let's write XML nodes later.
  We will only need to adjust the "keywords" dictionary for that,
  but this change will require changes to the entire chain of tools.
2022-10-06 13:40:29 +02:00
Thomas Haller
069089cdf2
tools: fix constructing XML by dropping broken pretty_xml()
I don't understand the code, but it mangles the XML.

There is no difference in the markup we have so far. But if you
have nested XML (like for description-docbook tag) there are cases
where this is wrong.

There is also no need to prettify anything. If you want pretty-formatted
XML, do it yourself, for example with

  $ tidy --indent yes --indent-spaces 4 --indent-attributes yes --wrap-attributes yes --input-xml yes --output-xml yes src/libnm-client-impl/nm-property-infos-nmcli.xml

I think this was initially done, because we had the tool in perl, and
when migrating, we wanted to generate the exactly same output. And it
was the same output, and it was fine for the input we have. But with
different input, it's wrong. Drop it now.

(cherry picked from commit 35599b4349)
2022-02-10 08:41:19 +01:00
Thomas Haller
f21cb3065e
tools: re-use regular expression in process_data()
Yes, they get cached by the library already. Still, no need for
doing this repeatedly.

(cherry picked from commit 41a177486b)
2022-02-10 08:41:19 +01:00
Thomas Haller
dd595c6c1d
tools: fix bogus code in "tools/generate-docs-nm-property-infos.py"
Coverity warns about this:

  2. NetworkManager-1.32.2/tools/generate-docs-nm-property-infos.py:117: identical_branches:
  The same code is executed regardless of whether "temp.index(subelement) < len(temp) - 1" is
  true, because the then and else branches are identical. Should one of the branches be modified,
  or the entire 'if' statement replaced?

Fixes: c3504f7e62 ('Rewrite `./tools/generate-docs-nm-property-infos.py` with XML library')
2021-07-06 09:08:36 +02:00
Wen Liang
0b87d8d6c5 Support new attribute tag description-docbook
`description-docbook` is the alternative tag to `description`, the
difference is that `description-docbook` expects docbook XML but not
plaintext.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-06-23 08:59:45 -04:00
Thomas Haller
26f0fb0604
python: remove unused imports
They are flagged by lgtm.com. Avoid the warning by dropping unused
includes.
2021-05-27 08:52:30 +02:00
Thomas Haller
c3d3429916
tools: drop spurious whitespace in "src/libnm-client-impl/nm-property-infos-*.xml"
<nm-setting-docs>
  -  <setting name="6lowpan">
  +<setting name="6lowpan">
   </setting>
2021-05-26 15:33:29 +02:00
Wen Liang
c3504f7e62
Rewrite ./tools/generate-docs-nm-property-infos.py with XML library
Instead of writing XML text word by word, it is less error prone to
write with XML library.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-20 10:41:20 +02:00
Wen Liang
dd38eb1f76
Adjust property tag format in nm-property-infos-*.xml
In order to make the generated XML file format consistent before and
after using XML library, adjust `property` tag format.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-20 10:41:19 +02:00
Thomas Haller
c34e36bb8d
Revert "Rewrite ./tools/generate-docs-nm-property-infos.py with XML library"
This breaks build on RHEL7, probably due to an older python version.
Revert for now.

This reverts commit a83fb33840.
2021-05-18 16:00:25 +02:00
Wen Liang
a83fb33840
Rewrite ./tools/generate-docs-nm-property-infos.py with XML library
Instead of writing XML text word by word, it is less error prone to
write with XML library.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
403d776730
Remove unnecessary escaping for single quote
When writing XML text with XML library, single quote will not be
escaped. So remove the escaping for single quote in current tool.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
f6e52708a2
Add paired property tag to nm-property-infos-*.xml
In order to make the generated XML file format consistent before and
after using XML library, replace self-closing `property` tag with
paired `property` tag.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
90422ddd1a
Remove line breaks in attribute value of nm-property-infos-*.xml
Since line breaks are not needed for XML's attribute tag, remove the
unnecessary line breaks.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
86dcb31ab3
build: replace ./tools/generate-docs-nm-property-infos.pl with python script
In order to have more structured settings in man page and make it more
manageable to generate the docbook, it is recommended to use python
script to replace `./tools/generate-docs-nm-property-infos.pl` (this
tool is used to parse the comment section starting with `---nmcli---`,
`---dbus---`, `---keyfile---`, `---ifcfg-rh---`).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/824
2021-05-05 15:28:17 +02:00