def get_ifs_widgets(self): ifs_info_widget = [] for interface in ifconfig.iterifs(physical=True): try: subprocess.check_output("brctl show|grep %s" % interface.name, shell=True) continue except subprocess.CalledProcessError: pass address_edit = urwid.Edit(u"Adress: ", str(interface.get_ip())) netmask_edit = urwid.Edit(u"Netmask: ", str(interface.get_netmask())) gateway_edit = urwid.Edit(u"Gateway: ", self.config_gateway(interface.name)) apply_button = urwid.Button(u"Apply") ifs_info_widget.append(urwid.Pile([ urwid.Divider("-"), urwid.Text(u"Name: " + interface.name), address_edit, netmask_edit, gateway_edit, urwid.Text(u"Status: " + ("up" if interface.is_up() else "down")), apply_button, ])) urwid.connect_signal( apply_button, "click", self.on_if_apply, user_arg=(interface.name, address_edit, netmask_edit, gateway_edit)) return ifs_info_widget
def get_bridge_widgets(self): bridge_info_widgets = [] for bridge in ifconfig.iterifs(bridge=True): try: if_name = subprocess.check_output( "brctl show %s|grep %s" % (bridge.name, bridge.name), shell=True).split("\t")[-1].strip() bridge_info_widgets.append(urwid.Pile([ urwid.Divider("-"), urwid.Columns([ ("weight", 1, urwid.Pile([ urwid.Text(u"Name: %s" % if_name), urwid.Text(u"Status: %s" % ("up" if ifconfig.Interface(if_name).is_up() else "down")), ])), ("weight", 2, urwid.Pile([ urwid.Text(u"Bridge: %s" % bridge.name), urwid.Text(u"Address: %s" % bridge.get_ip()), urwid.Text(u"Netmask: %s" % bridge.get_netmask()), urwid.Text(u"Gateway: %s" % self.config_gateway(bridge.name)), ])), ]) ])) except subprocess.CalledProcessError: continue return bridge_info_widgets