From a3e9b450507b1cb8f88e8f8039f96b6ba204db49 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 6 Sep 2021 12:23:07 +0530 Subject: [PATCH] more logging messages and code cleanup Removed log messages from config.py --- naxalnet/__init__.py | 2 +- naxalnet/config.py | 9 +++++---- naxalnet/iwd.py | 2 ++ naxalnet/scripts.py | 15 ++++++++------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 27c93ba..2160232 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -36,4 +36,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.3.0a2" +__version__ = "0.3.0a2.dev1" diff --git a/naxalnet/config.py b/naxalnet/config.py index 38a7a16..711166b 100644 --- a/naxalnet/config.py +++ b/naxalnet/config.py @@ -46,7 +46,8 @@ from pathlib import Path from configparser import ConfigParser from argparse import ArgumentParser, Namespace from naxalnet.default import CONFIG, CONFIG_FILES, CONFIG_DIRS -from naxalnet.log import logger + +# from naxalnet.log import logger def get_config_files(): @@ -70,14 +71,14 @@ def parse_config(): Parse all configuration files, with the values in default.py as fallback """ - logger.debug("Parsing config files") + # logger.debug("Parsing config files") parser = ConfigParser() # encoded defaults parser.read_dict(CONFIG) # read config files files = get_config_files() for i in files: - logger.debug("Reading config file %s", str(i)) + # logger.debug("Reading config file %s", str(i)) parser.read_file(i.open()) return parser @@ -145,5 +146,5 @@ def parse_args() -> Namespace: help="prints the version and exit", ) - logger.debug("Parsing arguments") + # logger.debug("Parsing arguments") return parser.parse_args() diff --git a/naxalnet/iwd.py b/naxalnet/iwd.py index b9eb90c..e15d660 100644 --- a/naxalnet/iwd.py +++ b/naxalnet/iwd.py @@ -310,11 +310,13 @@ class Adapter: """power on the adapter""" self._proxy.Powered = True logger.debug("Powered on adapter %s", self.name) + self.reload() def power_off(self): """power off the adapter""" self._proxy.Powered = False logger.debug("Powered off adapter %s", self.name) + self.reload() def supports_mode(self, mode: str) -> bool: """ diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index ce2d268..18086cf 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -99,7 +99,6 @@ def setup_devices(args): if not adhoc_adapter.is_powered_on(): logger.debug("Adapter %s is off. Turning on", adhoc_adapter.name) adhoc_adapter.power_on() - adhoc_device.reload() adhoc_device.start_adhoc_open(args.adhoc_name) # Start Access point if ap_device is not empty, # ie, we have more devices @@ -113,11 +112,13 @@ def setup_devices(args): if not ap_adapter.is_powered_on(): logger.debug("Adapter %s is off. Turning on", ap_adapter.name) ap_adapter.power_on() - ap_adapter.reload() ap_device.start_ap(args.ap_ssid, args.ap_passwd) - - # naxalnet prints Bye if no errors occured - logger.info("Bye") + else: + logger.info("Not setting up WiFi AP.") + else: + logger.warning( + "No device found to setup mesh. Make sure a WiFi adapter is connected" + ) def print_wifi(args): @@ -161,5 +162,5 @@ def here_be_dragons(): except DBusError: logger.exception("Error while communicating with iwd") sys.exit(4) - - logger.debug("Finished.") + # naxalnet prints Bye if no errors occured + logger.info("Bye")