Skip to content

Instantly share code, notes, and snippets.

@eldondev
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eldondev/2888b96e2f2d3f7b5101 to your computer and use it in GitHub Desktop.
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)
#!/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