Skip to content

Commit 9607a62

Browse files
committed
v0.6.1 - Handle new .nmconnection extensions on NetworkManager system-connection files
1 parent 868dcc2 commit 9607a62

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

nordnm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__package__ = "nordnm"
2-
__version__ = "0.6.0"
2+
__version__ = "0.6.1"
33
__license__ = "GNU General Public License v3 or later (GPLv3+)"

nordnm/networkmanager.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@
1515
class ConnectionConfig(object):
1616
def __init__(self, connection_name):
1717
self.config = configparser.ConfigParser(interpolation=None)
18-
self.path = os.path.join("/etc/NetworkManager/system-connections/", connection_name)
18+
self.path = None
1919

2020
try:
21-
if os.path.isfile(self.path):
21+
# Get all system-connection files and check for a match, with or without the new '.nmconnection' extension
22+
_, _, file_names = next(os.walk(paths.SYSTEM_CONNECTIONS, (None, None, [])))
23+
for file_name in file_names:
24+
if re.search(re.escape(connection_name) + "(.nmconnection)?", file_name):
25+
# Found a match, so store the full path as self.path and break out
26+
self.path = os.path.join(paths.SYSTEM_CONNECTIONS, file_name)
27+
break
28+
29+
if self.path and os.path.isfile(self.path):
2230
self.config.read(self.path)
2331
else:
24-
logger.error("VPN config file not found! (%s)", self.path)
25-
self.path = None
32+
logger.error("VPN config file not found in system-connections! (%s)", connection_name)
2633

2734
except Exception as ex:
2835
logger.error(ex)
29-
self.path = None
3036

3137
def save(self):
3238
try:
@@ -187,7 +193,7 @@ def set_global_mac_address(value):
187193

188194
logger.info("Global NetworkManager MAC address settings set to '%s'.", value)
189195
return True
190-
except Exception as e:
196+
except Exception:
191197
logger.error("Could not save MAC address configuration to '%s'", paths.MAC_CONFIG)
192198
return False
193199
else:

0 commit comments

Comments
 (0)