Skip to content

Commit

Permalink
Merge pull request #73 from ushiboy/release/1.4.0
Browse files Browse the repository at this point in the history
Preparation for 1.4.0 release
  • Loading branch information
ushiboy authored Sep 15, 2024
2 parents 52f26f7 + 8eee277 commit 8ef4246
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ nmcli.set_lang(lang: str) -> None

## Change Log

### 1.4.0

- Supported unsupported cases of `DeviceWifi.parse`.
- Fixed the problem that `nmcli.general` does not work on nmcli client after version 1.48.x.

### 1.3.0

- Added rescan parameter to `nmcli.device.wifi`.
Expand Down
42 changes: 17 additions & 25 deletions nmcli/data/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,26 @@ def to_json(self):

@classmethod
def parse(cls, text: str) -> General:
#pattern = r'^([\S\s]+)\s{2}(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*'

state_r = r'(?P<state>.+)'
connectivity_r = r'(?P<connectivity>\S+)'
wifi_hw_r = r'(?P<wifi_hw>\S+)'
wifi_r = r'(?P<wifi>\S+)'
wwan_hw_r = r'(?P<wwan_hw>\S+)'
wwan_r = r'(?P<wwan>\S+)'
metered_r = r'(?: (?P<metered>.+)?)?'

pattern = (
r'^'
+ state_r
+ r' '
+ connectivity_r
+ r'\s+'
+ wifi_hw_r
+ r' '
+ wifi_r
+ r' '
+ wwan_hw_r
+ r' '
+ wwan_r
+ metered_r
+ r'$'
r'^'
+ r'(?P<state>.+)'
+ r' '
+ r'(?P<connectivity>\S+)'
+ r'\s+'
+ r'(?P<wifi_hw>\S+)'
+ r' '
+ r'(?P<wifi>\S+)'
+ r' '
+ r'(?P<wwan_hw>\S+)'
+ r' '
+ r'(?P<wwan>\S+)'
+ r'(?: (?P<metered>.+)?)?'
+ r'$'
)

m = re.search(pattern, text)
# The execution result will have a trailing space,
# so trim it and then match it to the pattern.
m = re.search(pattern, text.rstrip())

if m:
state, connectivity, wifi_hw, wifi, wwan_hw, wwan, _metered = m.groups()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_tests(self):

setup(
name='nmcli',
version='1.3.0',
version='1.4.0',
author='ushiboy',
license='MIT',
license_files = ('LICENSE.txt',),
Expand Down
4 changes: 4 additions & 0 deletions tests/data/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def test_device_wifi_parse():
assert DeviceWifi.parse(d4) == \
DeviceWifi(False, 'AAAAAA BBBBBBBBB CCC 9999', '00:00:00:00:00:03',
'Infra', 1, 2403, 130, 82, 'WPA1 WPA2')
d5 = '*:AP1:00\\:00\\:00\\:00\\:00\\:00:Infra:1:2400 MHz:130 Mb/s:82:WPA1 WPA2'
assert DeviceWifi.parse(d5) == \
DeviceWifi(True, 'AP1', '00:00:00:00:00:00',
'Infra', 1, 2400, 130, 82, 'WPA1 WPA2')


def test_device_wifi_parse_when_failed():
Expand Down
16 changes: 8 additions & 8 deletions tests/data/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@ def test_to_json():


def test_parse():
d1 = 'unknown none enabled enabled enabled disabled'
d1 = 'unknown none enabled enabled enabled disabled '
assert General.parse(d1) == General(NetworkManagerState.UNKNOWN,
NetworkConnectivity.NONE,
True, True, True, False)

d2 = 'asleep portal enabled enabled disabled enabled'
d2 = 'asleep portal enabled enabled disabled enabled '
assert General.parse(d2) == General(NetworkManagerState.ASLEEP,
NetworkConnectivity.PORTAL,
True, True, False, True)

d3 = 'connecting limited enabled disabled enabled enabled'
d3 = 'connecting limited enabled disabled enabled enabled '
assert General.parse(d3) == General(NetworkManagerState.CONNECTING,
NetworkConnectivity.LIMITED,
True, False, True, True)

d4 = 'connected (local only) full disabled enabled enabled enabled'
d4 = 'connected (local only) full disabled enabled enabled enabled '
assert General.parse(d4) == General(NetworkManagerState.CONNECTED_LOCAL,
NetworkConnectivity.FULL,
False, True, True, True)

d5 = 'connected (site only) full enabled enabled enabled enabled'
d5 = 'connected (site only) full enabled enabled enabled enabled '
assert General.parse(d5) == General(NetworkManagerState.CONNECTED_SITE,
NetworkConnectivity.FULL,
True, True, True, True)

d6 = 'disconnecting full enabled enabled enabled enabled'
d6 = 'disconnecting full enabled enabled enabled enabled '
assert General.parse(d6) == General(NetworkManagerState.DISCONNECTING,
NetworkConnectivity.FULL,
True, True, True, True)

d7 = 'disconnected full enabled enabled enabled enabled'
d7 = 'disconnected full enabled enabled enabled enabled '
assert General.parse(d7) == General(NetworkManagerState.DISCONNECTED,
NetworkConnectivity.FULL,
True, True, True, True)

d8 = 'connected full enabled enabled missing enabled no (guessed)'
d8 = 'connected full enabled enabled missing enabled no (guessed) '
assert General.parse(d8) == General(NetworkManagerState.CONNECTED_GLOBAL,
NetworkConnectivity.FULL,
True, True, False, True)
Expand Down

0 comments on commit 8ef4246

Please sign in to comment.