summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Statistics.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2005-11-28 20:18:16 +0000
committerNarayan Desai <desai@mcs.anl.gov>2005-11-28 20:18:16 +0000
commitee908766e9704749d00845f0b14cbfa5681850fd (patch)
tree96b8b6d16c189085dc0174e46e1e995fe977d912 /src/lib/Server/Statistics.py
parentc62e5282a63c64712b9653ac3ffc1e2364f73845 (diff)
downloadbcfg2-ee908766e9704749d00845f0b14cbfa5681850fd.tar.gz
bcfg2-ee908766e9704749d00845f0b14cbfa5681850fd.tar.bz2
bcfg2-ee908766e9704749d00845f0b14cbfa5681850fd.zip
work around lxml bug
(Logical change 1.367) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1537 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Statistics.py')
-rw-r--r--src/lib/Server/Statistics.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib/Server/Statistics.py b/src/lib/Server/Statistics.py
index 5e3ef0fc8..6f7c5cd4f 100644
--- a/src/lib/Server/Statistics.py
+++ b/src/lib/Server/Statistics.py
@@ -1,8 +1,7 @@
'''This file manages the statistics collected by the BCFG2 Server'''
__revision__ = '$Revision: $'
-from lxml.etree import XML, SubElement, Element
-from xml.parsers.expat import ExpatError
+from lxml.etree import XML, SubElement, Element, XMLSyntaxError
from syslog import syslog, LOG_ERR
from time import asctime, localtime, time
@@ -21,15 +20,16 @@ class Statistics(object):
'''Produce a pretty-printed text representation of element'''
if element.text:
fmt = "%s<%%s %%s>%%s</%%s>" % (level*" ")
- data = (element.tag, (" ".join(["%s='%s'" % keyval for keyval in element.attrib.iteritems()])),
+ data = (element.tag, (" ".join(["%s='%s'" % (key, element.attrib[key]) for key in element.attrib])),
element.text, element.tag)
- if element._children:
- fmt = "%s<%%s %%s>\n" % (level*" ",) + (len(element._children) * "%s") + "%s</%%s>\n" % (level*" ")
- data = (element.tag, ) + (" ".join(["%s='%s'" % keyval for keyval in element.attrib.iteritems()]),)
- data += tuple([self.pretty_print(entry, level+2) for entry in element._children]) + (element.tag, )
+ numchild = len(element.getchildren())
+ if numchild:
+ fmt = "%s<%%s %%s>\n" % (level*" ",) + (numchild * "%s") + "%s</%%s>\n" % (level*" ")
+ data = (element.tag, ) + (" ".join(["%s='%s'" % (key, element.attrib[key]) for key in element.attrib]),)
+ data += tuple([self.pretty_print(entry, level+2) for entry in element.getchildren()]) + (element.tag, )
else:
fmt = "%s<%%s %%s/>\n" % (level * " ")
- data = (element.tag, " ".join(["%s='%s'" % keyval for keyval in element.attrib.iteritems()]))
+ data = (element.tag, " ".join(["%s='%s'" % (key, element.attrib[key]) for key in element.attrib]))
return fmt % data
def WriteBack(self, force=0):
@@ -52,7 +52,7 @@ class Statistics(object):
self.element = XML(data)
self.dirty = 0
#syslog(LOG_INFO, "Statistics: Read in statistics.xml")
- except (IOError, ExpatError):
+ except (IOError, XMLSyntaxError):
syslog(LOG_ERR, "Statistics: Failed to parse %s"%(self.filename))
self.element = Element('ConfigStatistics')
self.WriteBack()