diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2006-08-14 15:14:17 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2006-08-14 15:14:17 +0000 |
commit | aed32c5e04799925c309a802f8c802e238ccdb4d (patch) | |
tree | ab1d2e616d045522b83c13c72dca3aa8a968975c /src | |
parent | c00b6f4350b389968ac28b3bd77d1d0d6b24be54 (diff) | |
download | bcfg2-aed32c5e04799925c309a802f8c802e238ccdb4d.tar.gz bcfg2-aed32c5e04799925c309a802f8c802e238ccdb4d.tar.bz2 bcfg2-aed32c5e04799925c309a802f8c802e238ccdb4d.zip |
* Annotate Bcfg2.Client.XML driver
* Switch Toolset.py to use XML abstraction layer
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2063 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Client/Toolset.py | 23 | ||||
-rw-r--r-- | src/lib/Client/XML.py | 3 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/lib/Client/Toolset.py b/src/lib/Client/Toolset.py index 61af1ebad..6c602cbaf 100644 --- a/src/lib/Client/Toolset.py +++ b/src/lib/Client/Toolset.py @@ -5,7 +5,9 @@ from stat import S_ISVTX, S_ISGID, S_ISUID, S_IXUSR, S_IWUSR, S_IRUSR, S_IXGRP from stat import S_IWGRP, S_IRGRP, S_IXOTH, S_IWOTH, S_IROTH, ST_MODE, S_ISDIR from stat import S_IFREG, ST_UID, ST_GID, S_ISREG, S_IFDIR, S_ISLNK -import binascii, copy, difflib, grp, logging, lxml.etree, os, popen2, pwd, stat, sys, xml.sax.saxutils +import binascii, copy, difflib, grp, logging, os, popen2, pwd, stat, sys, xml.sax.saxutils + +import Bcfg2.Client.XML def calcPerms(initial, perms): '''This compares ondisk permissions with specified ones''' @@ -62,7 +64,7 @@ class Toolset(object): self.VerifyEntry(cfile) if not self.states[cfile]: self.InstallConfigFile(cfile) - self.statistics = lxml.etree.Element("Statistics") + self.statistics = Bcfg2.Client.XML.Element("Statistics") def saferun(self, command): '''Run a command in a pipe dealing with stdout buffer overloads''' @@ -184,9 +186,10 @@ class Toolset(object): flows = [(dirty, "Bad"), (self.modified, "Modified")] for (condition, tagName) in flows: if condition: - container = lxml.etree.SubElement(stats, tagName) + container = Bcfg2.Client.XML.SubElement(stats, tagName) for ent in [key for key, val in self.states.iteritems() if not val]: - newent = lxml.etree.SubElement(container, ent.tag, name=ent.get('name', 'None')) + newent = Bcfg2.Client.XML.SubElement(container, ent.tag, + name=ent.get('name', 'None')) for field in [item for item in 'current_exists', 'current_diff' if item in ent.attrib]: newent.set(field, ent.get(field)) del ent.attrib[field] @@ -201,15 +204,15 @@ class Toolset(object): if 'severity' in ent.attrib: newent.set('severity', ent.get('severity')) if self.extra_services + self.pkgwork['remove']: - extra = lxml.etree.SubElement(stats, "Extra") - [lxml.etree.SubElement(extra, "Service", name=svc, current_status='on') + extra = Bcfg2.Client.XML.SubElement(stats, "Extra") + [Bcfg2.Client.XML.SubElement(extra, "Service", name=svc, current_status='on') for svc in self.extra_services] for pkg in self.pkgwork['remove']: if pkg in self.installed: - lxml.etree.SubElement(extra, "Package", name=pkg, - current_version=self.installed[pkg]) + Bcfg2.Client.XML.SubElement(extra, "Package", name=pkg, + current_version=self.installed[pkg]) else: - lxml.etree.SubElement(extra, "Package", name=pkg) + Bcfg2.Client.XML.SubElement(extra, "Package", name=pkg) self.logger.error("Failed to find installed version of packages %s" % (pkg)) return stats @@ -226,7 +229,7 @@ class Toolset(object): self.states[entry] = method(entry) except: self.logger.error("Failure in VerifyEntry", exc_info=1) - self.logger.error("Entry: %s" % (lxml.etree.tostring(entry))) + self.logger.error("Entry: %s" % (Bcfg2.Client.XML.tostring(entry))) def InstallEntry(self, entry): '''Dispatch call to self.Install<tagname>''' diff --git a/src/lib/Client/XML.py b/src/lib/Client/XML.py index 356886558..b0ae0f771 100644 --- a/src/lib/Client/XML.py +++ b/src/lib/Client/XML.py @@ -6,15 +6,18 @@ __revision__ = '$Revision$' try: from lxml.etree import Element, SubElement, tostring from lxml.etree import XMLSyntaxError as ParseError + driver = 'lxml' except ImportError: # lxml not available try: from xml.etree.ElementTree import Element, XML, tostring from xml.parsers.expat import ExpatError as ParseError + driver = 'etree-py' except ImportError: try: from elementtree.ElementTree import Element, XML, tostring from xml.parsers.expat import ExpatError as ParseError + driver = 'etree' except ImportError: print "Failed to load lxml, xml.etree and elementtree.ElementTree" print "Cannot continue" |