-) Use human sorting (so ie. cpu2 comes before cpu10) for CPUs to
have a nice and consistent output on GUI
-) Do just one sorting at the end of operation, not at every added
CPU entry which is useless. This improves startup time
Signed-off-by: Federico Pellegrin <fede(a)evolware.org>
---
tuna/sysfs.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tuna/sysfs.py b/tuna/sysfs.py
index 6b3e1df..bce96af 100755
--- a/tuna/sysfs.py
+++ b/tuna/sysfs.py
@@ -10,7 +10,8 @@ class cpu:
self.reload()
def __lt__(self, other):
- self.name < other.name
+ # Previously it is assumed that name[:3] == "cpu" and
name[3].isdigit(), so:
+ int(self.name[3:]) < int(other.name[3:])
def readfile(self, name):
try:
@@ -89,10 +90,11 @@ class cpus:
else:
self.sockets[socket] = [c, ]
- sockets_to_sort.append(socket)
+ if socket not in sockets_to_sort:
+ sockets_to_sort.append(socket)
- for socket in sockets_to_sort:
- self.sockets[socket].sort()
+ for socket in sockets_to_sort:
+ self.sockets[socket].sort(key=lambda x: int(x.name[3:]))
if __name__ == '__main__':
--
2.26.2