davemds pushed a commit to branch master.

http://git.enlightenment.org/enlightenment/modules/edgar.git/commit/?id=63b9e57ba41330d31e783608efe5c5d2ee3c78cd

commit 63b9e57ba41330d31e783608efe5c5d2ee3c78cd
Author: Dave Andreoli <[email protected]>
Date:   Sat Sep 16 08:50:15 2017 +0200

    Netspeed gadget: code cleanup
    
    and fixed received value
---
 GADGETS/netspeed/__init__.py | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/GADGETS/netspeed/__init__.py b/GADGETS/netspeed/__init__.py
index 4766973..1f698b6 100644
--- a/GADGETS/netspeed/__init__.py
+++ b/GADGETS/netspeed/__init__.py
@@ -81,6 +81,7 @@ class Gadget(e.Gadget):
 
         in_perc = int(kb_in / 1000 * 100)  # TODO CONFIGURABLE MAX
         out_perc = int(kb_out / 1000 * 100)  # TODO CONFIGURABLE MAX
+
         for obj in self._instances:
             obj.message_send(1, (0, in_perc, 0,  0, out_perc, 0))
 
@@ -91,25 +92,21 @@ class Gadget(e.Gadget):
         return ecore.ECORE_CALLBACK_RENEW
 
     def parse_proc(self):
-        tot_in = 0
-        tot_out = 0
-        for line in open("/proc/net/dev", "r").readlines()[2:]:
-            vals = line.split(None, 3)
-            tot_in += int(vals[1])
-            tot_out += int(vals[2])
-        
+        tot_in = tot_out = indiff = outdiff = 0
+        for line in open("/proc/net/dev", "r").readlines():
+            if ':' in line:
+                vals = line.split()
+                tot_in += int(vals[1])
+                tot_out += int(vals[9])
 
         curtime = time.time()
         timediff = curtime - self.last_time
         self.last_time = curtime
-        
 
-        indiff = 0
         if self.last_in > 0:
             indiff = tot_in - self.last_in
         self.last_in = tot_in
 
-        outdiff = 0
         if self.last_out > 0:
             outdiff = tot_out - self.last_out
         self.last_out = tot_out
@@ -122,6 +119,3 @@ class Gadget(e.Gadget):
         byte_per_second_out = outdiff / timediff
 
         return byte_per_second_in, byte_per_second_out
-
-    # def format_mb(self, val):
-        # return '{0:.0f} MB'.format(val / 1048576)

-- 


Reply via email to