Skip to content

Commit 389cbbf

Browse files
authored
Merge pull request #41 from bernhardkaindl/doctree-add-settings-helpers
Thank you
2 parents f4c693a + 4ce0aca commit 389cbbf

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ of `NetworkManager <https://wiki.gnome.org/Projects/NetworkManager>`_.
1212
examples
1313
device_interfaces
1414
other_interfaces
15-
options
15+
profile_settings
1616
enums
1717
exceptions
1818

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Network Manager settings
2-
========================
1+
Connection Profile Settings Helpers
2+
===================================
3+
34

45
.. autoclass:: sdbus_async.networkmanager.settings.ConnectionSettings
56
:members:

sdbus_async/networkmanager/settings/match.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ class MatchSettings(NetworkManagerSettingsMixin):
1616
default=None,
1717
)
1818
"""A list of driver names to match. Each element is a shell wildcard pattern.
19-
See NMSettingMatch:interface-name for how special characters '|', '&', '!' and
20-
'\\' are used for optional and mandatory matches and inverting the pattern."""
19+
See NMSettingMatch:interface-name for how special characters '\|', '&', '!'
20+
and '\\' are used for optional and mandatory matches and inverting the
21+
pattern."""
2122
interface_name: Optional[List[str]] = field(
2223
metadata={'dbus_name': 'interface-name', 'dbus_type': 'as'},
2324
default=None,
2425
)
2526
"""A list of interface names to match. Each element is a shell wildcard
26-
pattern. An element can be prefixed with a pipe symbol (|) or an ampersand
27+
pattern. An element can be prefixed with a pipe symbol (\|) or an ampersand
2728
(&). The former means that the element is optional and the latter means that
2829
it is mandatory. If there are any optional elements, than the match evaluates
2930
to true if at least one of the optional element matches (logical OR). If there
3031
are any mandatory elements, then they all must match (logical AND). By
3132
default, an element is optional. This means that an element "foo" behaves the
32-
same as "|foo". An element can also be inverted with exclamation mark (!)
33+
same as "\|foo". An element can also be inverted with exclamation mark (!)
3334
between the pipe symbol (or the ampersand) and before the pattern. Note that
3435
"!foo" is a shortcut for the mandatory match "&!foo". Finally, a backslash can
3536
be used at the beginning of the element (after the optional special
@@ -46,7 +47,7 @@ class MatchSettings(NetworkManagerSettingsMixin):
4647
command line is searched for the word appearing as is, or as left hand side of
4748
an assignment. In the latter case, the exact assignment is looked for with
4849
right and left hand side matching. Wildcard patterns are not supported. See
49-
NMSettingMatch:interface-name for how special characters '|', '&', '!' and
50+
NMSettingMatch:interface-name for how special characters '\|', '&', '!' and
5051
'\\' are used for optional and mandatory matches and inverting the match."""
5152
path: Optional[List[str]] = field(
5253
metadata={'dbus_name': 'path', 'dbus_type': 'as'},
@@ -58,8 +59,8 @@ class MatchSettings(NetworkManagerSettingsMixin):
5859
specific identifier. For PCI devices the path has the form
5960
"pci-$domain:$bus:$device.$function", where each variable is an hexadecimal
6061
value; for example "pci-0000:0a:00.0". The path of a device can be obtained
61-
with "udevadm info /sys/class/net/$dev | grep ID_PATH=" or by looking at the
62+
with "udevadm info /sys/class/net/$dev \| grep ID_PATH=" or by looking at the
6263
"path" property exported by NetworkManager ("nmcli -f general.path device show
6364
$dev"). Each element of the list is a shell wildcard pattern. See
64-
NMSettingMatch:interface-name for how special characters '|', '&', '!' and
65+
NMSettingMatch:interface-name for how special characters '\|', '&', '!' and
6566
'\\' are used for optional and mandatory matches and inverting the pattern."""

tools/generate-settings-dataclasses.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
from pathlib import Path
1111
from typing import Any, Dict, List, Optional, OrderedDict, Tuple
1212

13-
14-
def dbg(msg: Any) -> None:
15-
print(f"{msg}")
16-
17-
18-
def write(msg: Any) -> None:
19-
print(f"{msg}")
20-
21-
2213
dbus_type_name_map = {
2314
"b": "bool",
2415
"s": "str",
@@ -219,21 +210,22 @@ def find_first_not_none(itr: List[Any]) -> Optional[Any]:
219210

220211
# Generate docs/options.rst, see:
221212
# https://github.com/python-sdbus/python-sdbus-networkmanager/pull/39#issuecomment-1186522147
222-
def open_options_rst() -> io.TextIOWrapper:
223-
options_rst = open("docs/options.rst", "w")
224-
options_rst.write("Network Manager settings\n========================\n")
225-
return options_rst
213+
def open_profile_settings_rst() -> io.TextIOWrapper:
214+
profile_settings_rst = open("docs/profile_settings.rst", "w")
215+
profile_settings_rst.write("Connection Profile Settings Helpers\n")
216+
profile_settings_rst.write("===================================\n\n")
217+
return profile_settings_rst
226218

227219

228-
def append_sphinx_autoclass(options_rst: io.TextIOWrapper, classname: str) -> None:
220+
def append_sphinx_autoclass(profile_settings: io.TextIOWrapper, classname: str) -> None:
229221
classpath = f"sdbus_async.networkmanager.settings.{classname}"
230-
options_rst.write(f"\n.. autoclass:: {classpath}\n :members:\n")
222+
profile_settings.write(f"\n.. autoclass:: {classpath}\n :members:\n")
231223

232224

233225
# The code quality of this function is poor(Sourcery says 5%), needs refactoring,
234226
# also see the rework in tools/generate-settings-dataclasses-jinja.py
235227
def main(settings_xml_path: Path) -> None:
236-
options_rst = open_options_rst()
228+
profile_settings_rst = open_profile_settings_rst()
237229
gl_input_files = [settings_xml_path]
238230

239231
xml_roots = [ElementTree.parse(f).getroot() for f in gl_input_files]
@@ -315,7 +307,7 @@ def main(settings_xml_path: Path) -> None:
315307
p.write(" )\n")
316308
f.write("@dataclass\n")
317309
f.write(f"class {classname}(NetworkManagerSettingsMixin):\n")
318-
append_sphinx_autoclass(options_rst, classname)
310+
append_sphinx_autoclass(profile_settings_rst, classname)
319311

320312
# generate the docstring of the new settings_class
321313
desc = node_get_attr(settings, "description")
@@ -390,13 +382,16 @@ def main(settings_xml_path: Path) -> None:
390382
# developers when they lookup the attribute declaration:
391383
generate_descriptions_for_attributes = True
392384
if generate_descriptions_for_attributes:
393-
desc = node_get_attr(properties_attrs, "description")
385+
attr_description = node_get_attr(properties_attrs, "description")
386+
# Fix warning from sphinx: WARNING:
387+
# Inline substitution_reference start-string without end-string
388+
attr_docstring = attr_description.replace("|", "\|")
394389
wrapper = textwrap.TextWrapper(
395390
width=82,
396391
initial_indent=" ",
397392
subsequent_indent=" ",
398393
)
399-
lines = wrapper.wrap(text=f'"""{desc}"""')
394+
lines = wrapper.wrap(text=f'"""{attr_docstring}"""')
400395
if len(lines) == 1:
401396
print(lines[0] + '"""')
402397
else:

0 commit comments

Comments
 (0)