Skip to content

Commit 7b632d8

Browse files
authored
Merge pull request #54 from ushiboy/release/1.1.0
Release 1.1.0
2 parents fb83b2f + 263c4c7 commit 7b632d8

File tree

9 files changed

+84
-19
lines changed

9 files changed

+84
-19
lines changed

.github/workflows/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ['3.7', '3.8', '3.9']
10+
python-version: ['3.7', '3.8', '3.9', '3.10']
1111
steps:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-python@v2

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,20 @@ nmcli.device.status() -> List[Device]
189189

190190
Show details of device.
191191

192+
The `fields` argument applies the same effect to the command as the `-f | --fields` option. If it is omitted, the default behavior is followed.
193+
192194
```
193-
nmcli.device.show(ifname: str) -> DeviceDetails
195+
nmcli.device.show(ifname: str, fields: str = None) -> DeviceDetails
194196
```
195197

196198
#### nmcli.device.show_all
197199

198200
Show details of devices.
199201

202+
The `fields` argument applies the same effect to the command as the `-f | --fields` option. If it is omitted, the default behavior is followed.
203+
200204
```
201-
nmcli.device.show_all() -> List[DeviceDetails]
205+
nmcli.device.show_all(fields: str = None) -> List[DeviceDetails]
202206
```
203207

204208
#### nmcli.device.connect
@@ -455,6 +459,10 @@ nmcli.set_lang(lang: str) -> None
455459

456460
## Change Log
457461

462+
### 1.1.0
463+
464+
- Added fields option to `nmcli.device.show` and `nmcli.device.show_all`
465+
458466
### 1.0.0
459467

460468
- Handle connection failure exceptions with `nmcli.device.wifi_connect`.

nmcli/_device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List, Tuple
33

44
from ._exception import ConnectionActivateFailedException
5-
from ._helper import add_wait_option_if_needed, add_fields_option_if_needed
5+
from ._helper import add_fields_option_if_needed, add_wait_option_if_needed
66
from ._system import SystemCommand, SystemCommandInterface
77
from .data.device import Device, DeviceDetails, DeviceWifi
88
from .data.hotspot import Hotspot
@@ -42,10 +42,10 @@ def __call__(self) -> List[Device]:
4242
def status(self) -> List[Device]:
4343
raise NotImplementedError
4444

45-
def show(self, ifname: str, fields: str) -> DeviceDetails:
45+
def show(self, ifname: str, fields: str = None) -> DeviceDetails:
4646
raise NotImplementedError
4747

48-
def show_all(self, fields: str) -> List[DeviceDetails]:
48+
def show_all(self, fields: str = None) -> List[DeviceDetails]:
4949
raise NotImplementedError
5050

5151
def connect(self, ifname: str, wait: int = None) -> None:

nmcli/_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
def add_wait_option_if_needed(wait: int = None) -> List[str]:
55
return [] if wait is None else ['--wait', str(wait)]
66

7+
78
def add_fields_option_if_needed(fields: str = None) -> List[str]:
89
return [] if fields is None else ['-f', fields]

nmcli/dummy/_device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self,
5656
self._result_show = result_show
5757
self._result_show_all = result_show_all or []
5858
self._result_wifi_hotspot = result_wifi_hotspot
59-
self._show_args: List[str] = []
59+
self._show_args: List[Tuple] = []
6060
self._connect_args: List[Tuple] = []
6161
self._disconnect_args: List[Tuple] = []
6262
self._reapply_args: List[str] = []
@@ -74,14 +74,14 @@ def status(self) -> List[Device]:
7474
self._raise_error_if_needed()
7575
return self._result_call
7676

77-
def show(self, ifname: str) -> DeviceDetails:
77+
def show(self, ifname: str, fields: str = None) -> DeviceDetails:
7878
self._raise_error_if_needed()
79-
self._show_args.append(ifname)
79+
self._show_args.append((ifname, fields))
8080
if not self._result_show is None:
8181
return self._result_show
8282
raise ValueError("'result_show' is not properly initialized")
8383

84-
def show_all(self) -> List[DeviceDetails]:
84+
def show_all(self, fields: str = None) -> List[DeviceDetails]:
8585
self._raise_error_if_needed()
8686
return self._result_show_all
8787

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def run_tests(self):
1313

1414
setup(
1515
name='nmcli',
16-
version='1.0.0',
16+
version='1.1.0',
1717
author='ushiboy',
1818
license='MIT',
1919
description='A python wrapper library for the network-manager cli client',

tests/dummy/test_device.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def test_show():
3333
c = DummyDeviceControl(result_show=result_show)
3434
ifname = 'eth0'
3535
assert c.show(ifname) == result_show
36-
assert c.show_args == [ifname]
36+
assert c.show_args == [(ifname, None)]
37+
38+
fields = 'all'
39+
assert c.show(ifname, fields) == result_show
40+
assert c.show_args == [(ifname, None), (ifname, fields)]
3741

3842

3943
def test_show_when_raise_error():

tests/test_device.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def test_show():
6060
IP6.ADDRESS[1]: ::1/128
6161
IP6.GATEWAY: --
6262
IP6.ROUTE[1]: dst = ::1/128, nh = ::, mt = 256'''
63-
s = DummySystemCommand(d)
64-
device = DeviceControl(s)
63+
s1 = DummySystemCommand(d)
64+
device = DeviceControl(s1)
6565
assert device.show('lo') == {
6666
'GENERAL.DEVICE': 'lo',
6767
'GENERAL.TYPE': 'loopback',
@@ -76,7 +76,25 @@ def test_show():
7676
'IP6.GATEWAY': None,
7777
'IP6.ROUTE[1]': 'dst = ::1/128, nh = ::, mt = 256'
7878
}
79-
assert s.passed_parameters == ['device', 'show', 'lo']
79+
assert s1.passed_parameters == ['device', 'show', 'lo']
80+
81+
s2 = DummySystemCommand(d)
82+
device = DeviceControl(s2)
83+
assert device.show('lo', 'all') == {
84+
'GENERAL.DEVICE': 'lo',
85+
'GENERAL.TYPE': 'loopback',
86+
'GENERAL.HWADDR': '00:00:00:00:00:00',
87+
'GENERAL.MTU': '65536',
88+
'GENERAL.STATE': '10 (unmanaged)',
89+
'GENERAL.CONNECTION': None,
90+
'GENERAL.CON-PATH': None,
91+
'IP4.ADDRESS[1]': '127.0.0.1/8',
92+
'IP4.GATEWAY': None,
93+
'IP6.ADDRESS[1]': '::1/128',
94+
'IP6.GATEWAY': None,
95+
'IP6.ROUTE[1]': 'dst = ::1/128, nh = ::, mt = 256'
96+
}
97+
assert s2.passed_parameters == ['-f', 'all', 'device', 'show', 'lo']
8098

8199

82100
def test_show_all():
@@ -100,8 +118,8 @@ def test_show_all():
100118
IP6.ADDRESS[1]: ::1/128
101119
IP6.GATEWAY: --
102120
IP6.ROUTE[1]: dst = ::1/128, nh = ::, mt = 256'''
103-
s = DummySystemCommand(d)
104-
device = DeviceControl(s)
121+
s1 = DummySystemCommand(d)
122+
device = DeviceControl(s1)
105123
assert device.show_all() == [{
106124
'GENERAL.DEVICE': 'wlan0',
107125
'GENERAL.TYPE': 'wifi',
@@ -124,7 +142,33 @@ def test_show_all():
124142
'IP6.GATEWAY': None,
125143
'IP6.ROUTE[1]': 'dst = ::1/128, nh = ::, mt = 256'
126144
}]
127-
assert s.passed_parameters == ['device', 'show']
145+
assert s1.passed_parameters == ['device', 'show']
146+
147+
s2 = DummySystemCommand(d)
148+
device = DeviceControl(s2)
149+
assert device.show_all('all') == [{
150+
'GENERAL.DEVICE': 'wlan0',
151+
'GENERAL.TYPE': 'wifi',
152+
'GENERAL.HWADDR': '46:7B:1F:32:36:E2',
153+
'GENERAL.MTU': '1500',
154+
'GENERAL.STATE': '30 (disconnected)',
155+
'GENERAL.CONNECTION': None,
156+
'GENERAL.CON-PATH': None
157+
}, {
158+
'GENERAL.DEVICE': 'lo',
159+
'GENERAL.TYPE': 'loopback',
160+
'GENERAL.HWADDR': '00:00:00:00:00:00',
161+
'GENERAL.MTU': '65536',
162+
'GENERAL.STATE': '10 (unmanaged)',
163+
'GENERAL.CONNECTION': None,
164+
'GENERAL.CON-PATH': None,
165+
'IP4.ADDRESS[1]': '127.0.0.1/8',
166+
'IP4.GATEWAY': None,
167+
'IP6.ADDRESS[1]': '::1/128',
168+
'IP6.GATEWAY': None,
169+
'IP6.ROUTE[1]': 'dst = ::1/128, nh = ::, mt = 256'
170+
}]
171+
assert s2.passed_parameters == ['-f', 'all', 'device', 'show']
128172

129173

130174
def test_connect():

tests/test_helper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
from nmcli._helper import add_wait_option_if_needed
1+
from nmcli._helper import (add_fields_option_if_needed,
2+
add_wait_option_if_needed)
23

34

45
def test_add_wait_option_if_needed():
56
assert add_wait_option_if_needed(10) == ['--wait', '10']
67
assert add_wait_option_if_needed(11) == ['--wait', '11']
78
assert not add_wait_option_if_needed()
89
assert not add_wait_option_if_needed(None)
10+
11+
12+
def test_add_fields_option_if_needed():
13+
assert add_fields_option_if_needed('all') == ['-f', 'all']
14+
assert add_fields_option_if_needed('common') == ['-f', 'common']
15+
assert not add_fields_option_if_needed()
16+
assert not add_fields_option_if_needed(None)

0 commit comments

Comments
 (0)