mirror of
https://github.com/Ponce/slackbuilds
synced 2024-12-01 01:00:03 +01:00
1ae08f499b
Signed-off-by: Dave Woodfall <dave@slackbuilds.org> Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
174 lines
5.1 KiB
Diff
174 lines
5.1 KiB
Diff
Description: Update upstream source to Python 3.
|
|
Based on fixes at https://github.com/kenduest/speedometer/
|
|
Author: Giovani Augusto Ferreira <giovani@debian.org>
|
|
Last-Update: 2019-12-08
|
|
|
|
Index: speedometer/speedometer.py
|
|
===================================================================
|
|
--- speedometer.orig/speedometer.py
|
|
+++ speedometer/speedometer.py
|
|
@@ -1,4 +1,4 @@
|
|
-#!/usr/bin/python
|
|
+#!/usr/bin/python3
|
|
|
|
# speedometer.py
|
|
# Copyright (C) 2001-2011 Ian Ward
|
|
@@ -21,6 +21,8 @@ import os
|
|
import string
|
|
import math
|
|
import re
|
|
+import psutil
|
|
+import six
|
|
|
|
__usage__ = """Usage: speedometer [options] tap [[-c] tap]...
|
|
Monitor network traffic or speed/progress of a file transfer. At least one
|
|
@@ -76,6 +78,10 @@ units_per_second = 'bytes'
|
|
chart_minimum = 2**5
|
|
chart_maximum = 2**32
|
|
|
|
+if six.PY3:
|
|
+ def long(*args,**kwargs):
|
|
+ return int(*args,**kwargs)
|
|
+
|
|
graph_scale = None
|
|
def update_scale():
|
|
"""
|
|
@@ -400,7 +406,8 @@ class SpeedGraph:
|
|
self.log = []
|
|
self.bar = []
|
|
|
|
- def get_data(self, (maxcol,maxrow)):
|
|
+ def get_data(self, max_col_row):
|
|
+ maxcol, maxrow = max_col_row
|
|
bar = self.bar[-maxcol:]
|
|
if len(bar) < maxcol:
|
|
bar = [[0]]*(maxcol-len(bar)) + bar
|
|
@@ -409,8 +416,8 @@ class SpeedGraph:
|
|
def selectable(self):
|
|
return False
|
|
|
|
- def render(self, (maxcol, maxrow), focus=False):
|
|
-
|
|
+ def render(self, max_col_row, focus=False):
|
|
+ maxcol, maxrow = max_col_row
|
|
left = max(0, len(self.log)-maxcol)
|
|
pad = maxcol-(len(self.log)-left)
|
|
|
|
@@ -445,8 +452,8 @@ class SpeedGraph:
|
|
for i in range(left+max(0, ldist-pad),len(l)-rdist+1):
|
|
li = l[i]
|
|
if li == 0: continue
|
|
- if i and l[i-1]>=li: continue
|
|
- if l[i+1]>li: continue
|
|
+ if i and l[i-1] != None and l[i-1]>=li: continue
|
|
+ if li is None or l[i+1]>li: continue
|
|
highs.append((li, -i))
|
|
|
|
highs.sort()
|
|
@@ -471,7 +478,7 @@ class SpeedGraph:
|
|
|
|
|
|
def speed_scale(s):
|
|
- if s <= 0: return 0
|
|
+ if s is None or s <= 0: return 0
|
|
if logarithmic_scale:
|
|
s = math.log(s, 2)
|
|
s = min(graph_range(), max(0, s-graph_min()))
|
|
@@ -498,7 +505,7 @@ def readable_speed(speed):
|
|
if speed == None or speed < 0: speed = 0
|
|
|
|
units = "B/s ", "KiB/s", "MiB/s", "GiB/s", "TiB/s"
|
|
- step = 1L
|
|
+ step = long(1)
|
|
|
|
for u in units:
|
|
|
|
@@ -511,7 +518,7 @@ def readable_speed(speed):
|
|
if speed/step < 1024:
|
|
return "%4d " %(speed/step) + u
|
|
|
|
- step = step * 1024L
|
|
+ step = step * long(1024)
|
|
|
|
return "%4d " % (speed/(step/1024)) + units[-1]
|
|
|
|
@@ -524,7 +531,7 @@ def readable_speed_bits(speed):
|
|
|
|
speed = speed * 8
|
|
units = "b/s ", "Kib/s", "Mib/s", "Gib/s", "Tib/s"
|
|
- step = 1L
|
|
+ step = long(1)
|
|
|
|
for u in units:
|
|
|
|
@@ -537,7 +544,7 @@ def readable_speed_bits(speed):
|
|
if speed/step < 1024:
|
|
return "%4d " %(speed/step) + u
|
|
|
|
- step = step * 1024L
|
|
+ step = step * long(1024)
|
|
|
|
return "%4d " % (speed/(step/1024)) + units[-1]
|
|
|
|
@@ -607,18 +614,12 @@ def network_feed(device,rxtx):
|
|
r = re.compile(r"^\s*" + re.escape(device) + r":(.*)$", re.MULTILINE)
|
|
|
|
def networkfn(devre=r,rxtx=rxtx):
|
|
- f = open('/proc/net/dev')
|
|
- dev_lines = f.read()
|
|
- f.close()
|
|
- match = devre.search(dev_lines)
|
|
- if not match:
|
|
- return None
|
|
-
|
|
- parts = match.group(1).split()
|
|
if rxtx == 'RX':
|
|
- return long(parts[0])
|
|
+ val=psutil.net_io_counters(pernic=True)[device].bytes_recv
|
|
else:
|
|
- return long(parts[8])
|
|
+ val=psutil.net_io_counters(pernic=True)[device].bytes_sent
|
|
+
|
|
+ return long(val)
|
|
|
|
return networkfn
|
|
|
|
@@ -728,7 +729,7 @@ def time_as_units(seconds):
|
|
# (multiplicative factor, suffix)
|
|
units = (1,"s"), (60,"m"), (60,"h"), (24,"d"), (7,"w"), (52,"y")
|
|
|
|
- scale = 1L
|
|
+ scale = long(1)
|
|
topunit = -1
|
|
# find the top unit to use
|
|
for mul, suf in units:
|
|
@@ -757,7 +758,7 @@ def readable_time(seconds, columns=None)
|
|
for value, suf in time_as_units(seconds):
|
|
new_out = out
|
|
if out: new_out = new_out + ' '
|
|
- new_out = new_out + `value` + suf
|
|
+ new_out = new_out + value + suf
|
|
if columns and len(new_out) > columns: break
|
|
out = new_out
|
|
|
|
@@ -1091,6 +1092,6 @@ def wait_all(cols):
|
|
if __name__ == "__main__":
|
|
try:
|
|
console()
|
|
- except KeyboardInterrupt, err:
|
|
+ except KeyboardInterrupt as err:
|
|
pass
|
|
|
|
Index: speedometer/setup.py
|
|
===================================================================
|
|
--- speedometer.orig/setup.py
|
|
+++ speedometer/setup.py
|
|
@@ -35,7 +35,7 @@ setup_d = {
|
|
'scripts': ['speedometer.py'],
|
|
'entry_points': {
|
|
'console_scripts': ['speedometer = speedometer:console'],},
|
|
- 'install_requires': ['urwid >= 0.9.9.1'],
|
|
+ 'install_requires': ['urwid >= 0.9.9.1', 'psutil', 'six'],
|
|
'license':"LGPL",
|
|
'keywords':"network bandwidth monitor system speed download file progress console",
|
|
'platforms':"Linux",
|