Skip to content

Commit

Permalink
Refactor NetConf
Browse files Browse the repository at this point in the history
* Unify DHCP handler classes
* Drop pickled state file
* Pass data explicitely
* Store configuration in GSettings
* Add some tests
* Extract DNS server handling
  • Loading branch information
cschramm committed Jul 7, 2022
1 parent 884ed1b commit 7c5f875
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 340 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Raise minimum Python version to 3.8
* Hide recent connections associated with unavailable adapters
* Store network configuration in GSettings instead of /var/lib/blueman/network.state.

## 2.3

Expand Down
24 changes: 24 additions & 0 deletions blueman/main/DNSServerProvider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re
from ipaddress import IPv4Address
from typing import List, Generator

from gi.repository import GObject


class DNSServerProvider(GObject.GObject):
RESOLVER_PATH = "/etc/resolv.conf"

def __init__(self) -> None:
super().__init__()

@classmethod
def get_servers(cls) -> List[IPv4Address]:
return list(cls._get_servers_from_resolver())

@classmethod
def _get_servers_from_resolver(cls) -> Generator[IPv4Address, None, None]:
with open(cls.RESOLVER_PATH) as f:
for line in f:
match = re.search(r"^nameserver\s+((?:\d{1,3}\.){3}\d{1,3}$)", line)
if match:
yield IPv4Address(match.group(1))
1 change: 1 addition & 0 deletions blueman/main/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ blueman_PYTHON = \
NetConf.py \
SpeedCalc.py \
DbusService.py \
DNSServerProvider.py \
PluginManager.py \
Adapter.py \
Applet.py \
Expand Down
Loading

0 comments on commit 7c5f875

Please sign in to comment.