From 16dff8bb49d99384aff3bb01c904fec67a7871e1 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Fri, 30 Jul 2021 17:56:33 +0530 Subject: [PATCH] added support for arguments Try naxalnet --help to see help --- README.md | 1 + naxalnet/__init__.py | 2 +- naxalnet/scripts.py | 31 ++++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b91d40..64d2766 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ The author, not unlike the Government of India, does not wish to take responsibility in your well-being if you get arrested under a draconian national security law, which was once used to arrest a person involved in the freedom struggle against British Raj. + --> The name naxal comes from Naxalbari, a village in Darjeeling, diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 9e3bc72..4d66b68 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -16,4 +16,4 @@ # along with this program. If not, see . -__version__ = "0.2.0a" +__version__ = "0.2.0a1" diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index a61878c..d656eb7 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -24,11 +24,13 @@ import sys from pathlib import Path from shutil import copy from dasbus.error import DBusError +from argparse import ArgumentParser from naxalnet.iwd import IWD, Device, Adapter NETWORKD_CONFIGS = "/usr/share/naxalnet/networkd" NETWORKD_VOLATILE_DIR = "/run/systemd/network" -ADHOC_SSID = "HelloWorld" +# default values +ADHOC_NAME = "HelloWorld" AP_SSID = "NaxalNet" AP_PASSWD = "naxalnet256" @@ -58,6 +60,7 @@ def here_be_dragons(): This function is run every time you execute naxalnet from commandline """ + args = parse_args() try: copy_files() except PermissionError as error: @@ -94,7 +97,7 @@ def here_be_dragons(): if not adhoc_adapter.is_powered_on(): adhoc_adapter.power_on() adhoc_device.reload() - adhoc_device.start_adhoc_open(ADHOC_SSID) + adhoc_device.start_adhoc_open(args.adhoc_name) # Start Access point if ap_device is not empty, # ie, we have more devices if len(ap_devices) != 0: @@ -106,10 +109,32 @@ def here_be_dragons(): if not ap_adapter.is_powered_on(): ap_adapter.power_on() ap_adapter.reload() - ap_device.start_ap(AP_SSID, AP_PASSWD) + ap_device.start_ap(args.ap_ssid, args.ap_passwd) except DBusError as error: print(error) sys.exit("An error occured while communicating with iwd") # naxalnet will print Bye if no errors occured print("Bye") + + +def parse_args(): + parser = ArgumentParser(description="setup batman networks") + parser.add_argument( + "--ap-ssid", + type=str, + help="SSID of the WiFi AP", + default=AP_SSID, + ) + parser.add_argument( + "--ap-passwd", + "--ap-password", + type=str, + help="password of the WiFi AP", + default=AP_PASSWD, + ) + parser.add_argument( + "--adhoc-name", type=str, default=ADHOC_NAME, help="name of adhoc network" + ) + + return parser.parse_args()