diff options
author | bgstack15 <bgstack15@gmail.com> | 2016-11-04 15:04:51 -0400 |
---|---|---|
committer | bgstack15 <bgstack15@gmail.com> | 2016-11-04 15:04:51 -0400 |
commit | c051b2135b0078741837e6469d49f81d43aaca9f (patch) | |
tree | b40d82d68e4076e4d72fef2f3e16025324f072b4 | |
parent | Initial commit (diff) | |
download | wifi-c051b2135b0078741837e6469d49f81d43aaca9f.tar.gz wifi-c051b2135b0078741837e6469d49f81d43aaca9f.tar.bz2 wifi-c051b2135b0078741837e6469d49f81d43aaca9f.zip |
Added argparse for config file and --quiet
-rw-r--r-- | usr/wifi/docs/wifi.spec | 5 | ||||
-rw-r--r-- | usr/wifi/packaging.txt | 7 | ||||
-rwxr-xr-x | usr/wifi/wifi.py | 34 |
3 files changed, 36 insertions, 10 deletions
diff --git a/usr/wifi/docs/wifi.spec b/usr/wifi/docs/wifi.spec index f69bafe..4dd0c51 100644 --- a/usr/wifi/docs/wifi.spec +++ b/usr/wifi/docs/wifi.spec @@ -36,11 +36,12 @@ rm -rf %{buildroot} %files /README.md +/usr/wifi/inc/scrub.py +%doc %attr(444, -, -) /usr/wifi/inc/scrub.txt +/usr/wifi/inc/localize_git.sh %config /usr/wifi/networks/sample.wifi %config /usr/wifi/networks/campus.wifi %doc %attr(444, -, -) /usr/wifi/packaging.txt -/usr/wifi/docs/wifi.spec.2 -/usr/wifi/docs/wifi.spec.1 /usr/wifi/docs/nmcli.md /usr/wifi/docs/wifi.spec /usr/wifi/docs/wnic.md diff --git a/usr/wifi/packaging.txt b/usr/wifi/packaging.txt index c574282..aa356f5 100644 --- a/usr/wifi/packaging.txt +++ b/usr/wifi/packaging.txt @@ -34,3 +34,10 @@ rm -rf "${package}.tgz"; tar -zc --exclude='.git' -f "${package}.tgz" "${package /bin/cp -pf "${rpmbuilddir}/SOURCES/${packagespecfile}" "${rpmbuilddir}/SPECS" cd "${rpmbuilddir}/RPMS/noarch" rpmbuild -bb "${rpmbuilddir}/SPECS/${package}.spec" + +### PACKAGING in a master.tgz +package=wifi +version=0.1-1 +cd ~/deb 2>/dev/null || cd ~/rpmbuild/SOURCES +rm -rf "./${package}-${version}.master.tgz" +tar -zcf "${package}-${version}.master.tgz" "${package}-${version}/" diff --git a/usr/wifi/wifi.py b/usr/wifi/wifi.py index 8a3bba0..cf7525a 100755 --- a/usr/wifi/wifi.py +++ b/usr/wifi/wifi.py @@ -15,9 +15,9 @@ # specify connection name or filename # provide --verbose flag -import re, subprocess +import re, subprocess, argparse, os -wifipyversion = "2016-11-03b" +wifipyversion = "2016-11-04a" # DEFINE FUNCTIONS def _run_command(command): @@ -51,17 +51,35 @@ def getvaluefromfile(filename, searchstring): thisvalue = re.sub("^" + searchstring + "=", "", line) except Exception as e: - print("Fatal error opening file: " + filename) + print("Fatal error opening file: " + filename + ". Aborted.") quit() return thisvalue -# SAMPLE VARIABLES +# INITIALIZE VARIABLES configfile = "/home/bgstack15-local/software/wifi/campus.wifi" conname = "" # gets con-name nmcli_con_add = [] # gets type, ifname, con-name, ssid nmcli_con_mod = [] # gets everything else +# PARSE PARAMETERS +parser = argparse.ArgumentParser(description="Loads wifi settings from a file.") +parser.add_argument("-q", "--quiet", help="suppresses output", action="store_true",default=False) +parser.add_argument("filename", help="Connection file. Usually ends in .wifi") +parser.add_argument("-V","--version", action="version", version="%(prog)s " + wifipyversion) + +args = parser.parse_args() +bequiet = args.quiet +configfile = args.filename + +try: + with open(configfile,'r') as fp: + foo=0 + +except Exception as e: + print("Fatal error opening file " + configfile + ". Aborted.") + quit() + # PARSE CONFIG FILE for line in open(configfile): usedline=0 @@ -98,14 +116,14 @@ if False: # DELETE EXISTING CONNAME if exists nmcondel = "nmcli con del " + conname -print(nmcondel) +if not bequiet: print(nmcondel) run_command(nmcondel) # EXECUTE NMCLI CON ADD nmconadd = "nmcli con add" for thisstring in nmcli_con_add: nmconadd = nmconadd + " " + thisstring -print(nmconadd) +if not bequiet: print(nmconadd) run_command(nmconadd) # EXECUTE NMCLI CON MODIFY @@ -114,10 +132,10 @@ nmconmodprint = "nmcli con modify " + conname for thisstring in nmcli_con_mod: nmconmod = nmconmod + " " + thisstring nmconmodprint = nmconmodprint + " " + re.sub("(password ).*","\\1REDACTED", thisstring) -print(nmconmodprint) +if not bequiet: print(nmconmodprint) run_command(nmconmod) # EXECUTE NMCLI CON UP nmconup = "nmcli con up " + conname -print(nmconup) +if not bequiet: print(nmconup) run_command(nmconup) |