From d7c5b5ead5e575742282395f5dd569eefb31315d Mon Sep 17 00:00:00 2001 From: age Date: Tue, 15 Jan 2008 10:57:17 +0000 Subject: [PATCH] removed two TODOs --- plugins/network/network.py | 70 ++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/plugins/network/network.py b/plugins/network/network.py index d2c5204..4e26331 100644 --- a/plugins/network/network.py +++ b/plugins/network/network.py @@ -162,7 +162,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): def get_status(self): """The current IP is the status of this feature. """ - return "%d.%d.%d.%d" % self.__get_current_ip() + return "%d.%d.%d.%d" % self.__get_current_ip()[1] + def handle_event(self, event, event_info=None): @@ -212,35 +213,34 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): def __prepare_form_data(self): """Set some hdf values. """ - #TODO: the following looks nicer in a loop - (oc1, oc2, oc3, oc4) = self.__get_current_ip("ip") - self.hdf[self.hdf_prefix + "ip.oc1"] = oc1 - self.hdf[self.hdf_prefix + "ip.oc2"] = oc2 - self.hdf[self.hdf_prefix + "ip.oc3"] = oc3 - self.hdf[self.hdf_prefix + "ip.oc4"] = oc4 - (oc1, oc2, oc3, oc4) = self.__get_current_ip("nm") - self.hdf[self.hdf_prefix + "nm.oc1"] = oc1 - self.hdf[self.hdf_prefix + "nm.oc2"] = oc2 - self.hdf[self.hdf_prefix + "nm.oc3"] = oc3 - self.hdf[self.hdf_prefix + "nm.oc4"] = oc4 + (ip1, ip2, ip3, ip4),(nm1, nm2, nm3, nm4) = self.__get_current_ip() + self.hdf[self.hdf_prefix + "ip.oc1"] = ip1 + self.hdf[self.hdf_prefix + "ip.oc2"] = ip2 + self.hdf[self.hdf_prefix + "ip.oc3"] = ip3 + self.hdf[self.hdf_prefix + "ip.oc4"] = ip4 + self.hdf[self.hdf_prefix + "nm.oc1"] = nm1 + self.hdf[self.hdf_prefix + "nm.oc2"] = nm2 + self.hdf[self.hdf_prefix + "nm.oc3"] = nm3 + self.hdf[self.hdf_prefix + "nm.oc4"] = nm4 + (oc1, oc2, oc3, oc4) = self.__get_current_gw() self.hdf[self.hdf_prefix + "gw.oc1"] = oc1 self.hdf[self.hdf_prefix + "gw.oc2"] = oc2 self.hdf[self.hdf_prefix + "gw.oc3"] = oc3 self.hdf[self.hdf_prefix + "gw.oc4"] = oc4 + if self.prefs.has_key("_dhcp"): self.hdf[self.hdf_prefix + "dhcp"] = str(self.prefs["_dhcp"]) self.hdf[self.hdf_prefix + "interface"] = str(self.__get_interface()) self.hdf[self.hdf_prefix + "mac"] = str(self.__get_interface_mac(self.__get_interface())) - def __get_current_ip(self, address_type="ip"): + def __get_current_ip(self): """Retrieve the current IP. - - TODO: do not use "address_type" for ip and netmask, but return both in - two tuples """ - ## get the current IP of the network interface + ip = (0,0,0,0) + nm = (0,0,0,0) + ## get the current IP/netmask of the network interface proc = subprocess.Popen( shell = False, stdout = subprocess.PIPE, @@ -249,25 +249,23 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): self.__get_interface()]) (stdout, stderr) = proc.communicate() if proc.returncode != 0: - return (0, 0, 0, 0) - if address_type == "ip": - ## this regex matches the four numbers of the IP - match = re.search(r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', stdout) - if match: - ## use the previously matched numbers - return tuple([int(e) for e in match.groups()]) - else: - return (0, 0, 0, 0) - elif address_type == "nm": - ## this greps the netmask - match = re.search( - r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', - stdout) - if match: - ## use the previously matched numbers - return tuple([int(e) for e in match.groups()]) - else: - return (0, 0, 0, 0) + return ip, nm + + ## this regex matches the four numbers of the IP + match = re.search( + r'inet [\w]+:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', + stdout) + if match: + ip = tuple([int(e) for e in match.groups()]) + + ## this greps the netmask + match = re.search( + r'inet [\w]+:.*Mask:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\s', + stdout) + if match: + nm = tuple([int(e) for e in match.groups()]) + + return ip, nm def __get_current_gw(self):