summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Component.py2
-rw-r--r--src/lib/Server/Admin/Snapshots.py51
-rw-r--r--src/lib/Server/Admin/__init__.py34
3 files changed, 43 insertions, 44 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py
index 6ea788ba5..0a16c523f 100644
--- a/src/lib/Component.py
+++ b/src/lib/Component.py
@@ -249,7 +249,7 @@ class Component (object):
return self.implementation
get_implementation = exposed(get_implementation)
- def get_statistics (self):
+ def get_statistics (self, _):
"""Get current statistics about component execution"""
return self.instance_statistics.display()
get_statistics = exposed(get_statistics)
diff --git a/src/lib/Server/Admin/Snapshots.py b/src/lib/Server/Admin/Snapshots.py
index 576f2251f..b2536acb1 100644
--- a/src/lib/Server/Admin/Snapshots.py
+++ b/src/lib/Server/Admin/Snapshots.py
@@ -8,39 +8,6 @@ import Bcfg2.Server.Snapshots.model
from Bcfg2.Server.Snapshots.model import Snapshot, Client, Metadata, Base, \
File, Group, Package, Service
-def print_table(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
- print(borderline)
-
class Snapshots(Bcfg2.Server.Admin.Mode):
__shorthelp__ = "Interact with the Snapshots system"
__longhelp__ = (__shorthelp__)
@@ -75,11 +42,11 @@ class Snapshots(Bcfg2.Server.Admin.Mode):
for host in \
self.session.query(q_obj).filter(q_obj.active == True):
rows.append([host.name, 'Yes'])
- print_table([labels]+rows,
- justify='left',
- hdr=True,
- vdelim=" ",
- padding=1)
+ self.print_table([labels]+rows,
+ justify='left',
+ hdr=True,
+ vdelim=" ",
+ padding=1)
elif q_obj == Group:
print("Groups:")
for group in self.session.query(q_obj).all():
@@ -125,10 +92,10 @@ class Snapshots(Bcfg2.Server.Admin.Mode):
for item in q.all():
cli, cor, time, rev = item
rows.append([cli, cor, time, rev])
- print_table([labels]+rows,
- justify='left',
- hdr=True, vdelim=" ",
- padding=1)
+ self.print_table([labels]+rows,
+ justify='left',
+ hdr=True, vdelim=" ",
+ padding=1)
elif '-b' in args[1:]:
# Query a single host for bad entries
client = args[2]
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):