diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Plugin.py | 2 | ||||
-rw-r--r-- | src/lib/Server/Plugins/DBStats.py | 21 | ||||
-rw-r--r-- | src/lib/Server/Plugins/Statistics.py | 20 |
3 files changed, 39 insertions, 4 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 4d95fce49..6e3bc3a7c 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -111,7 +111,7 @@ class StatisticsPlugin(Plugin): return [] def GetCurrentEntry(self, client, e_type, e_name): - return None + raise PluginExecutionError # the rest of the file contains classes for coherent file caching diff --git a/src/lib/Server/Plugins/DBStats.py b/src/lib/Server/Plugins/DBStats.py index 6e9be82d0..abe8f17f7 100644 --- a/src/lib/Server/Plugins/DBStats.py +++ b/src/lib/Server/Plugins/DBStats.py @@ -1,7 +1,7 @@ import Bcfg2.Server.Plugin import Bcfg2.Server.Reports.importscript from Bcfg2.Server.Reports.reports.models import Client -import lxml.etree, time +import difflib, lxml.etree, time class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin): __name__ = 'DBStats' @@ -28,4 +28,21 @@ class DBStats(Bcfg2.Server.Plugin.StatisticsPlugin): return [(a.kind, a.name) for a in c_inst.current_interaction.extra_items.all()] - + def GetCurrentEntry(self, client, e_type, e_name): + c_inst = Client.objects.filter(name=client)[0] + entry = c_inst.current_interaction.bad_items.filter(kind=e_type, + name=e_name)[0] + ret = [] + data = ('owner', 'group', 'perms') + for t in data: + if getattr(entry.reason, "current_%s" % t) == '': + ret.append(getattr(entry.reason, t)) + else: + ret.append(getattr(entry.reason, "current_%s" % t)) + + if entry.reason.current_diff != '': + ret.append('\n'.join(difflib.restore(\ + entry.reason.current_diff.split('\n'), 1))) + else: + ret.append(None) + return ret 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) |