1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
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",
|