From e3e0d8d72e21f58c23ddf51d5af9d9200ee5037a Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Thu, 7 Aug 2008 20:16:29 +0000 Subject: Implement GetCurrentEntry api for Statistics and DBStats (prereq for portable bcfg2-admin pull) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4869 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugins/Statistics.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/lib/Server/Plugins/Statistics.py') diff --git a/src/lib/Server/Plugins/Statistics.py b/src/lib/Server/Plugins/Statistics.py index b7dc61179..b47ee4410 100644 --- a/src/lib/Server/Plugins/Statistics.py +++ b/src/lib/Server/Plugins/Statistics.py @@ -4,7 +4,7 @@ __revision__ = '$Revision$' from lxml.etree import XML, SubElement, Element, XMLSyntaxError from time import asctime, localtime, time, strptime, mktime -import logging, lxml.etree, os +import binascii, logging, lxml.etree, os import Bcfg2.Server.Plugin @@ -125,3 +125,21 @@ class Statistics(Bcfg2.Server.Plugin.StatisticsPlugin): def GetExtra(self, client): return [(entry.tag, entry.get('name')) for entry in self.FindCurrent(client).xpath('.//Extra/*')] + + def GetCurrentEntry(self, client, e_type, e_name): + curr = self.FindCurrent(client) + entry = curr.xpath('.//Bad/%s[@name="%s"]' % (e_type, e_name)) + cfentry = entry[-1] + + owner = cfentry.get('current_owner', cfentry.get('owner')) + group = cfentry.get('current_group', cfentry.get('group')) + perms = cfentry.get('current_perms', cfentry.get('perms')) + if 'current_bfile' in cfentry.attrib: + contents = binascii.a2b_base64(cfentry.get('current_bfile')) + elif 'current_bdiff' in cfentry.attrib: + diff = binascii.a2b_base64(cfentry.get('current_bdiff')) + contents = '\n'.join(difflib.restore(diff.split('\n'), 1)) + else: + contents = None + + return (owner, group, perms, contents) -- cgit v1.2.3-1-g7c22