diff options
author | Jacob Appelbaum <jacob@appelbaum.net> | 2011-08-19 17:25:35 +0200 |
---|---|---|
committer | Jacob Appelbaum <jacob@appelbaum.net> | 2011-08-19 17:25:35 +0200 |
commit | 18ce925004eb3030b91c01beda43a58017607103 (patch) | |
tree | 8dc479f49f66125af86933f91309db4a9ed98d71 /packages/torouter-web/src/tui/utils/parsing.py | |
parent | f76a57a4534722c7facb0432b4ee49e0030c7d1a (diff) | |
parent | fe239d1d9e8a590798abc31cd7bf7cf11324cfd5 (diff) | |
download | torouter-18ce925004eb3030b91c01beda43a58017607103.tar.gz torouter-18ce925004eb3030b91c01beda43a58017607103.zip |
Merge branch 'master' of ssh://git-rw.torproject.org/torouter
Diffstat (limited to 'packages/torouter-web/src/tui/utils/parsing.py')
-rw-r--r-- | packages/torouter-web/src/tui/utils/parsing.py | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/packages/torouter-web/src/tui/utils/parsing.py b/packages/torouter-web/src/tui/utils/parsing.py index daf4436..d6aaf2b 100644 --- a/packages/torouter-web/src/tui/utils/parsing.py +++ b/packages/torouter-web/src/tui/utils/parsing.py @@ -1,15 +1,29 @@ # These functions are for parsing /etc/network/interface # files, they will be used inside torouter to visualize # and edit configuration -import os +import os, re class interfaces: def __init__(self,filename): + self.filename = filename self.fp = open(filename, "r") self.wifi = {} self.eth1 = {} self.eth0 = {} - + + def exclude_output(self, iexclude): + iface = None + output = "" + self.fp = open(self.filename, "r") + for line in self.fp.readlines(): + if line.lstrip().startswith("iface"): + iface = line.split(" ")[1] + if iface == iexclude: + continue + else: + output += line + return output + def parse_line(self, line, iface): name = line.split(" ")[0] values = " ".join(line.split(" ")[1:]).rstrip() @@ -65,14 +79,28 @@ class interfaces: return output def output(self, data): - print "iface %s" % data['iface'] + output = "iface %s" % data['iface'] for item in data.items(): if item[0] != "iface": if type(item[1]) is list: for i in item[1]: - print "%s %s" % (item[0], i) + output += item[0] + " " + i + "\n" else: - print "%s %s" % (item[0],item[1]) + output += item[0] + " " + item[1] + "\n" + return output + + def set_ssid(self, essid): + i = 0 + for entry in self.wifi['post-up']: + if re.search("sys_cfg_ssid", entry): + print essid + self.wifi['post-up'][i] = 'post-up /usr/bin/uaputl sys_cfg_ssid "' + essid + '"' + i += 1 + + # XXX currently works for one pre-up entry, must make it work also for arrays + def set_mac(self, mac): + self.wifi['pre-up'] = 'ifconfig uap0 hw ether ' + mac + class torrc: def __init__(self,filename): |