From 798cd3e988b4d41b9721915c8693c3be3b74bbfd Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 27 Sep 2021 11:03:27 +0530 Subject: [PATCH] fixed bug in previous commit Added function to get glob as sorted list. This fixes the errors reported by systemd-networkd --- naxalnet/__init__.py | 2 +- naxalnet/scripts.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index f35e3e6..240727f 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -35,4 +35,4 @@ See README.md for documentation. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.4.0a4" +__version__ = "0.4.0a5" diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index c243357..02dffc3 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -40,6 +40,20 @@ from naxalnet.daemon import Daemon from naxalnet.network import NetworkD +def get_sorted_glob(directory: str, glob: str): + """return sorted list of filenames matching glob""" + path = Path(directory) + g = path.glob(glob) + sorted_list = [] + for i in g: + # g is a list of PosixPath objects. + # So we add their absolute path as str. + sorted_list.append(str(i)) + # sorted_list is not sorted, so we sort them here + sorted_list.sort() + return sorted_list + + def setup_mesh(): """configure networkd to setup the mesh""" try: @@ -52,10 +66,9 @@ def setup_mesh(): networkd = NetworkD(runtime_dir=args.networkd_runtime_dir) # TODO: replace with valus from args networkd.set_vars(batdev="bat0", bridgedev="bridge0") - for i in Path(args.networkd_config_dir).glob(MESH_GLOB): - path = str(i) - logger.debug("Adding network config %s", path) - networkd.add_config(path) + for i in get_sorted_glob(args.networkd_config_dir, MESH_GLOB): + logger.debug("Adding network config %s", i) + networkd.add_config(i) except PermissionError: logger.exception("A PermissionError occured while copying files") logger.error(REPORT_BUG_INFO)