From dbe96013c5472dcc3d33af2015373dbaf3e38ea7 Mon Sep 17 00:00:00 2001 From: Guillaume Chazarain Date: Mon, 29 Dec 2008 18:25:41 +0100 Subject: [PATCH] Add a meaningful __repr__() --- iotop/data.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iotop/data.py b/iotop/data.py index 88964f5..dc5db23 100644 --- a/iotop/data.py +++ b/iotop/data.py @@ -1,5 +1,6 @@ import errno import os +import pprint import pwd import socket import struct @@ -34,11 +35,15 @@ if not python25 or not ioaccounting: boolean2string(ioaccounting) sys.exit(1) +class DumpableObject(object): + def __repr__(self): + return '%s: %s>' % (str(type(self))[:-1], pprint.pformat(self.__dict__)) + # # Interesting fields in a taskstats output # -class Stats(object): +class Stats(DumpableObject): members_offsets = [ ('blkio_delay_total', 40), ('swapin_delay_total', 56), @@ -170,7 +175,7 @@ def safe_utf8_decode(s): except UnicodeDecodeError: return s.encode('string_escape') -class pinfo(object): +class pinfo(DumpableObject): def __init__(self, pid, options): self.mark = True self.pid = pid @@ -226,7 +231,7 @@ class pinfo(object): def ioprio_sort_key(self): return ioprio.sort_key(self.ioprio) -class ProcessList(object): +class ProcessList(DumpableObject): def __init__(self, taskstats_connection, options): # {pid: pinfo} self.processes = {} -- 2.11.4.GIT