Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
v0.6.1 - Handle new .nmconnection extensions on NetworkManager system…
Browse files Browse the repository at this point in the history
…-connection files
  • Loading branch information
chadsr committed Oct 25, 2018
1 parent 868dcc2 commit 9607a62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nordnm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__package__ = "nordnm"
__version__ = "0.6.0"
__version__ = "0.6.1"
__license__ = "GNU General Public License v3 or later (GPLv3+)"
18 changes: 12 additions & 6 deletions nordnm/networkmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@
class ConnectionConfig(object):
def __init__(self, connection_name):
self.config = configparser.ConfigParser(interpolation=None)
self.path = os.path.join("/etc/NetworkManager/system-connections/", connection_name)
self.path = None

try:
if os.path.isfile(self.path):
# Get all system-connection files and check for a match, with or without the new '.nmconnection' extension
_, _, file_names = next(os.walk(paths.SYSTEM_CONNECTIONS, (None, None, [])))
for file_name in file_names:
if re.search(re.escape(connection_name) + "(.nmconnection)?", file_name):
# Found a match, so store the full path as self.path and break out
self.path = os.path.join(paths.SYSTEM_CONNECTIONS, file_name)
break

if self.path and os.path.isfile(self.path):
self.config.read(self.path)
else:
logger.error("VPN config file not found! (%s)", self.path)
self.path = None
logger.error("VPN config file not found in system-connections! (%s)", connection_name)

except Exception as ex:
logger.error(ex)
self.path = None

def save(self):
try:
Expand Down Expand Up @@ -187,7 +193,7 @@ def set_global_mac_address(value):

logger.info("Global NetworkManager MAC address settings set to '%s'.", value)
return True
except Exception as e:
except Exception:
logger.error("Could not save MAC address configuration to '%s'", paths.MAC_CONFIG)
return False
else:
Expand Down

0 comments on commit 9607a62

Please sign in to comment.