summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/__init__.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-05-14 03:44:50 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-05-14 03:44:50 +0000
commit32252e0dff7825e581c888ffb68fb954fcacc68a (patch)
tree606277e38467d241abbd526356e2992e1f1868b9 /src/lib/Server/Admin/__init__.py
parenta3c2d24f421faef2928ec63db70633838d472032 (diff)
downloadbcfg2-32252e0dff7825e581c888ffb68fb954fcacc68a.tar.gz
bcfg2-32252e0dff7825e581c888ffb68fb954fcacc68a.tar.bz2
bcfg2-32252e0dff7825e581c888ffb68fb954fcacc68a.zip
Implement perf-reporting client
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5228 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/__init__.py')
-rw-r--r--src/lib/Server/Admin/__init__.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index 392d46d7c..31cb8fa1b 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -1,6 +1,6 @@
__revision__ = '$Revision$'
-__all__ = ['Mode', 'Client', 'Compare', 'Init', 'Minestruct',
+__all__ = ['Mode', 'Client', 'Compare', 'Init', 'Minestruct', 'Perf',
'Pull', 'Query', 'Snapshots', 'Tidy', 'Viz']
import ConfigParser
@@ -53,6 +53,38 @@ class Mode(object):
self.errExit("Could not find stats for client %s" % (client))
return hostent[0]
+ def print_table(self, rows, justify='left', hdr=True, vdelim=" ", padding=1):
+ """Pretty print a table
+
+ rows - list of rows ([[row 1], [row 2], ..., [row n]])
+ hdr - if True the first row is treated as a table header
+ vdelim - vertical delimiter between columns
+ padding - # of spaces around the longest element in the column
+ justify - may be left,center,right
+ """
+ hdelim = "="
+ justify = {'left':str.ljust,
+ 'center':str.center,
+ 'right':str.rjust}[justify.lower()]
+
+ '''
+ calculate column widths (longest item in each column
+ plus padding on both sides)
+ '''
+ cols = list(zip(*rows))
+ colWidths = [max([len(str(item))+2*padding for \
+ item in col]) for col in cols]
+ borderline = vdelim.join([w*hdelim for w in colWidths])
+
+ # print out the table
+ print(borderline)
+ for row in rows:
+ print(vdelim.join([justify(str(item), width) for \
+ (item, width) in zip(row, colWidths)]))
+ if hdr:
+ print(borderline)
+ hdr = False
+
class MetadataCore(Mode):
'''Base class for admin-modes that handle metadata'''
def __init__(self, configfile, usage):