summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Server/Metadata.py13
-rw-r--r--src/lib/Server/Plugins/Account.py9
-rw-r--r--src/lib/Server/Plugins/Hostbase.py3
-rw-r--r--src/lib/Server/Plugins/Vhost.py6
-rw-r--r--src/lib/Server/Statistics.py18
5 files changed, 28 insertions, 21 deletions
diff --git a/src/lib/Server/Metadata.py b/src/lib/Server/Metadata.py
index a4f3779d4..e83715fbe 100644
--- a/src/lib/Server/Metadata.py
+++ b/src/lib/Server/Metadata.py
@@ -115,15 +115,16 @@ class MetadataStore(SingleXMLFileBacked):
'''Produce a pretty-printed text representation of element'''
if element.text:
fmt = "%s<%%s %%s>%%s</%%s>" % (level*" ")
- data = (element.tag, (" ".join(["%s='%s'" % x for x 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'" % x for x in element.attrib.iteritems()]),)
- data += tuple([self.pretty_print(x, level+2) for x 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'" % x for x 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):
diff --git a/src/lib/Server/Plugins/Account.py b/src/lib/Server/Plugins/Account.py
index f30039d33..d728566a4 100644
--- a/src/lib/Server/Plugins/Account.py
+++ b/src/lib/Server/Plugins/Account.py
@@ -33,7 +33,8 @@ class Account(Plugin):
fname = entry.attrib['name'].split('/')[-1]
entry.text = self.repository.entries["static.%s" % (fname)].data
entry.text += self.repository.entries["dyn.%s" % (fname)].data
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0644'})
+ perms = {'owner':'root', 'group':'root', 'perms':'0644'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
def gen_limits_cb(self, entry, metadata):
'''Build limits entries based on current ACLs'''
@@ -41,7 +42,8 @@ class Account(Plugin):
superusers = self.repository.entries["superusers"].data.split()
useraccess = [line.split(':') for line in self.repository.entries["useraccess"].data.split()]
users = [user for (user, host) in useraccess if host == metadata.hostname.split('.')[0]]
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0600'})
+ perms = {'owner':'root', 'group':'root', 'perms':'0600'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
entry.text += "".join(["%s hard maxlogins 1024\n" % uname for uname in superusers + users])
if "*" not in users:
entry.text += "* hard maxlogins 0\n"
@@ -55,4 +57,5 @@ class Account(Plugin):
for user in superusers:
if self.repository.entries.has_key("%s.key" % user):
entry.text += self.repository.entries["%s.key" % user].data
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0600'})
+ perms = {'owner':'root', 'group':'root', 'perms':'0600'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
diff --git a/src/lib/Server/Plugins/Hostbase.py b/src/lib/Server/Plugins/Hostbase.py
index 3612486ea..9a488fc74 100644
--- a/src/lib/Server/Plugins/Hostbase.py
+++ b/src/lib/Server/Plugins/Hostbase.py
@@ -61,7 +61,8 @@ class Hostbase(Plugin, DataNexus):
fname = entry.get('name').split('/')[-1]
if not self.filedata.has_key(fname):
raise PluginExecutionError
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'644'})
+ perms = {'owner':'root', 'group':'root', 'perms':'644'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
entry.text = self.filedata[fname]
def rebuildState(self, event):
diff --git a/src/lib/Server/Plugins/Vhost.py b/src/lib/Server/Plugins/Vhost.py
index 56d4e68f8..43c1b8ca5 100644
--- a/src/lib/Server/Plugins/Vhost.py
+++ b/src/lib/Server/Plugins/Vhost.py
@@ -67,7 +67,8 @@ class VhostFile(SingleXMLFileBacked):
entry.text = 'NO_START=0\n'
else:
entry.text = 'NO_START=1\n'
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0644'})
+ perms = {'owner':'root', 'group':'root', 'perms':'0644'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
def generateApacheSvc(self, entry, metadata):
'''Enable apache service on webservices, disable on others'''
@@ -96,7 +97,8 @@ class VhostFile(SingleXMLFileBacked):
line = line.replace("XXchoiceXX", choice)
config += line
entry.text = base64.encodestring(config)
- entry.attrib.update({'owner':'root', 'group':'root', 'perms':'0644', 'encoding':'base64'})
+ perms = {'owner':'root', 'group':'root', 'perms':'0644', 'encoding':'base64'}
+ [entry.attrib.__setitem__(key, value) for (key, value) in perms.iteritems()]
class Vhost(Plugin):
'''This Structure is good for the pile of independent configs needed for most actual systems'''
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()