Skip to content

Commit 7e32042

Browse files
author
Bernhard Kaindl
committed
add-wifi-psk-connection example check return value of example
Check the return value of the example function before declaring success. (And the function name had to be shortened to still fit into 79 columns)
1 parent f0c940f commit 7e32042

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

examples/async/add-wifi-psk-connection-async.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
from sdbus_async.networkmanager import NetworkManagerConnectionProperties
5656

5757

58-
async def add_wifi_psk_connection_profile_async(args: Namespace) -> str:
58+
async def add_wifi_psk_connection_async(args: Namespace) -> str:
5959
"""Add a temporary (not yet saved) network connection profile
6060
:param Namespace args: autoconnect, conn_id, psk, save, ssid, uuid
6161
:return: dbus connection path of the created connection profile
@@ -117,6 +117,8 @@ async def add_wifi_psk_connection_profile_async(args: Namespace) -> str:
117117
p.add_argument("--save", dest="save", action="store_true", help="Save")
118118
args = p.parse_args()
119119
sdbus.set_default_bus(sdbus.sd_bus_open_system())
120-
connection_dpath = asyncio.run(add_wifi_psk_connection_profile_async(args))
121-
print(f"Path of the new connection: {connection_dpath}")
122-
print(f"UUID of the new connection: {args.uuid}")
120+
if connection_dpath := asyncio.run(add_wifi_psk_connection_async(args)):
121+
print(f"Path of the new connection: {connection_dpath}")
122+
print(f"UUID of the new connection: {args.uuid}")
123+
else:
124+
print("Error: No new connection created.")

examples/block/add-wifi-psk-connection.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from sdbus_block.networkmanager import NetworkManagerConnectionProperties
5555

5656

57-
def add_wifi_psk_connection_profile(args: Namespace) -> str:
57+
def add_wifi_psk_connection(args: Namespace) -> str:
5858
"""Add a temporary (not yet saved) network connection profile
5959
:param Namespace args: autoconnect, conn_id, psk, save, ssid, uuid
6060
:return: dbus connection path of the created connection profile
@@ -116,6 +116,8 @@ def add_wifi_psk_connection_profile(args: Namespace) -> str:
116116
p.add_argument("--save", dest="save", action="store_true", help="Save")
117117
args = p.parse_args()
118118
sdbus.set_default_bus(sdbus.sd_bus_open_system())
119-
connection_dpath = add_wifi_psk_connection_profile(args)
120-
print(f"Path of the new connection: {connection_dpath}")
121-
print(f"UUID of the new connection: {args.uuid}")
119+
if connection_dpath := add_wifi_psk_connection(args):
120+
print(f"Path of the new connection: {connection_dpath}")
121+
print(f"UUID of the new connection: {args.uuid}")
122+
else:
123+
print("Error: No new connection created.")

0 commit comments

Comments
 (0)