aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2009-10-14 15:13:17 -0300
committerEugeni Dodonov <eugeni@mandriva.com>2009-10-14 15:13:17 -0300
commitb0f06ce593fcaa891027cf9a6e5cc54841e2dabe (patch)
tree619256897757eb153f0b0e861d61539d30987a3b
parent2fb95723476133b4798285f2abd0bd7604065cfc (diff)
downloadnet_monitor-b0f06ce593fcaa891027cf9a6e5cc54841e2dabe.tar
net_monitor-b0f06ce593fcaa891027cf9a6e5cc54841e2dabe.tar.gz
net_monitor-b0f06ce593fcaa891027cf9a6e5cc54841e2dabe.tar.bz2
net_monitor-b0f06ce593fcaa891027cf9a6e5cc54841e2dabe.tar.xz
net_monitor-b0f06ce593fcaa891027cf9a6e5cc54841e2dabe.zip
Support selecting initial interface.
-rwxr-xr-xsrc/net_monitor38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/net_monitor b/src/net_monitor
index 5292406..45b47bb 100755
--- a/src/net_monitor
+++ b/src/net_monitor
@@ -272,7 +272,7 @@ class LoadGraph:
self.__colors[key] = value
class MonitorGui:
- def __init__(self):
+ def __init__(self, default_iface=None):
self.window = gtk.Window()
self.window.set_title(_("Network monitor"))
self.window.set_default_size(640, 440)
@@ -297,6 +297,7 @@ class MonitorGui:
sorted_ifaces.sort()
net=self.monitor.readnet()
+ select_page=0
for iface in sorted_ifaces:
data_in, data_out = self.monitor.get_traffic(iface,net)
self.ifaces[iface] = {'data_in': 0,
@@ -312,7 +313,9 @@ class MonitorGui:
'address': "",
}
iface_stat = self.build_iface_stat(iface)
- self.notebook.append_page(iface_stat, gtk.Label(iface))
+ cur_page = self.notebook.append_page(iface_stat, gtk.Label(iface))
+ if default_iface and iface == default_iface:
+ select_page = cur_page
if self.check_network_accounting(iface):
self.enabled_ifaces.append(iface)
@@ -329,6 +332,10 @@ class MonitorGui:
self.window.show_all()
+ # do we have to select a default interface?
+ if select_page:
+ self.notebook.set_current_page(select_page)
+
def update_tray_info(self):
"""Updates tray information"""
dns_servers = self.monitor.get_dns()
@@ -692,6 +699,31 @@ class MonitorGui:
pixbuf = loader.get_pixbuf()
return pixbuf
+# {{{ usage
+def usage():
+ """Prints help message"""
+ print """net_monitor: Mandriva network monitoring tool.
+
+Arguments to net_monitor:
+ -h, --help displays this helpful message.
+ -i, --defaultintf <iface> start monitoring the specified interface
+"""
+# }}}
+
if __name__ == "__main__":
- monitor = MonitorGui()
+ # default monitoring interface
+ iface = None
+ # parse command line
+ try:
+ opt, args = getopt.getopt(sys.argv[1:], 'hi:', ['help', 'defaultintf'])
+ except getopt.error:
+ usage()
+ sys.exit(1)
+ for o in opt:
+ if o[0] == '-h' or o[0] == '--help':
+ usage()
+ sys.exit(0)
+ elif o[0] == '-i' or o[0] == '--defaultintf':
+ iface = o[1]
+ monitor = MonitorGui(default_iface=iface)
gtk.main()