Last active
August 29, 2015 14:25
-
-
Save eldondev/2888b96e2f2d3f7b5101 to your computer and use it in GitHub Desktop.
A little gist that will comment out all but a single wpa config in a wpa_supplicant.conf (pass part of the SSID as an arg to the script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
lines = open('/etc/wpa_supplicant/wpa_supplicant.conf').readlines() | |
groups = [[]] | |
for line in lines: | |
if line[0] != '#': | |
line = '#' + line | |
groups[-1] += [ line ] | |
if '}' in line: | |
groups += [[]] | |
groups += [[]] | |
import sys, itertools | |
for net in groups: | |
if sys.argv[1] in ''.join(net): | |
groups.remove(net) | |
for line in net: | |
while line[0] == '#': | |
line = line[1:] | |
groups[-1] += [line] | |
print(''.join(groups[-1])) | |
with open('/etc/wpa_supplicant/wpa_supplicant.conf','w') as w: | |
w.writelines(itertools.chain(*groups)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment