summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/importscript.py
diff options
context:
space:
mode:
authorHolger Weiß <holger@zedat.fu-berlin.de>2011-06-06 16:32:53 +0200
committerHolger Weiß <holger@zedat.fu-berlin.de>2011-06-06 16:32:53 +0200
commit3914d14bec1cb7c0f6a600ea8d04ee0e6abc6550 (patch)
tree777d834b7b7a29e9d66904264a8756310444ab7b /src/lib/Server/Reports/importscript.py
parent701ff48cc9561ce88e80c1de5a19f8d6cda790bb (diff)
downloadbcfg2-3914d14bec1cb7c0f6a600ea8d04ee0e6abc6550.tar.gz
bcfg2-3914d14bec1cb7c0f6a600ea8d04ee0e6abc6550.tar.bz2
bcfg2-3914d14bec1cb7c0f6a600ea8d04ee0e6abc6550.zip
Accept non-ASCII diffs
Currently, client reports don't include diffs of files which aren't US-ASCII encoded. The client transmits such files as Base64 blobs. As we'd like to change that, this commit teaches the server to properly handle non-ASCII diffs.
Diffstat (limited to 'src/lib/Server/Reports/importscript.py')
-rwxr-xr-xsrc/lib/Server/Reports/importscript.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/lib/Server/Reports/importscript.py b/src/lib/Server/Reports/importscript.py
index b6a3c2599..68774cec6 100755
--- a/src/lib/Server/Reports/importscript.py
+++ b/src/lib/Server/Reports/importscript.py
@@ -38,7 +38,7 @@ import platform
from Bcfg2.Bcfg2Py3k import ConfigParser
-def build_reason_kwargs(r_ent):
+def build_reason_kwargs(r_ent, encoding, logger):
binary_file = False
if r_ent.get('current_bfile', False):
binary_file = True
@@ -54,6 +54,12 @@ def build_reason_kwargs(r_ent):
rc_diff = r_ent.get('current_diff')
else:
rc_diff = ''
+ if not binary_file:
+ try:
+ rc_diff = rc_diff.decode(encoding)
+ except:
+ logger.error("Reason isn't %s encoded, cannot decode it" % encoding)
+ rc_diff = ''
return dict(owner=r_ent.get('owner', default=""),
current_owner=r_ent.get('current_owner', default=""),
group=r_ent.get('group', default=""),
@@ -71,7 +77,7 @@ def build_reason_kwargs(r_ent):
is_binary=binary_file)
-def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
+def load_stats(cdata, sdata, encoding, vlevel, logger, quick=False, location=''):
clients = {}
[clients.__setitem__(c.name, c) \
for c in Client.objects.all()]
@@ -129,7 +135,7 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
for (xpath, type) in pattern:
for x in statistics.findall(xpath):
counter_fields[type] = counter_fields[type] + 1
- kargs = build_reason_kwargs(x)
+ kargs = build_reason_kwargs(x, encoding, logger)
try:
rr = None
@@ -270,6 +276,11 @@ if __name__ == '__main__':
print("StatReports: Failed to parse %s" % (statpath))
raise SystemExit(1)
+ try:
+ encoding = cf.get('components', 'encoding')
+ except:
+ encoding = 'UTF-8'
+
if not clientpath:
try:
clientspath = "%s/Metadata/clients.xml" % \
@@ -288,6 +299,7 @@ if __name__ == '__main__':
update_database()
load_stats(clientsdata,
statsdata,
+ encoding,
verb,
logger,
quick=q,