aboutsummaryrefslogtreecommitdiffstats
path: root/src/monitor.py
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2009-10-13 10:15:41 -0300
committerEugeni Dodonov <eugeni@mandriva.com>2009-10-13 10:15:41 -0300
commit1948857385fe40b069d889dda8e988bfbad56329 (patch)
tree5bb058b60a76317404b5b37c9014d866369881f5 /src/monitor.py
parent6e1769040e7ef1388134ef87e96cc52b9beaeb85 (diff)
downloadnet_monitor-1948857385fe40b069d889dda8e988bfbad56329.tar
net_monitor-1948857385fe40b069d889dda8e988bfbad56329.tar.gz
net_monitor-1948857385fe40b069d889dda8e988bfbad56329.tar.bz2
net_monitor-1948857385fe40b069d889dda8e988bfbad56329.tar.xz
net_monitor-1948857385fe40b069d889dda8e988bfbad56329.zip
properly format traffic numbers
Diffstat (limited to 'src/monitor.py')
-rw-r--r--src/monitor.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/monitor.py b/src/monitor.py
index cef0771..4c7802b 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -23,6 +23,11 @@ class Monitor:
# wireless modes
modes = ['Auto', 'Ad-Hoc', 'Managed', 'Master', 'Repeat', 'Second', 'Monitor']
+ # constants
+ SIZE_KB=1000
+ SIZE_MB=1000**2
+ SIZE_GB=1000**3
+
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.net = {}
@@ -161,9 +166,21 @@ class Monitor:
bytes_out = 0
return bytes_in, bytes_out
- def format_size(self, size):
+ def format_size(self, size, opt=""):
"""Pretty-Formats size"""
- return size
+ # convert to float
+ size_f = size * 1.0
+ pretty_size = None
+ pretty_bytes = "%d Bytes%s" % (size, opt)
+ if size > self.SIZE_GB:
+ pretty_size = "%0.2f GB%s" % (size_f / self.SIZE_GB, opt)
+ elif size > self.SIZE_MB:
+ pretty_size = "%0.2f MB%s" % (size_f / self.SIZE_MB, opt)
+ elif size > self.SIZE_KB:
+ pretty_size = "%0.2f KB%s" % (size_f / self.SIZE_KB, opt)
+ else:
+ pretty_size = pretty_bytes
+ return pretty_size, pretty_bytes
def get_dns(self):
"""Returns list of DNS servers"""