diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-28 13:25:23 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-28 13:25:23 -0400 |
commit | 0987e2a52629607a9868201085e9ba5b995f8fb8 (patch) | |
tree | 741b060282121636cb70fcb3825e322fa5906d35 /src/lib/Bcfg2/Server/Lint/Validate.py | |
parent | b8b15234bcf3fc4edecf219e2c3331e9eee54b17 (diff) | |
download | bcfg2-0987e2a52629607a9868201085e9ba5b995f8fb8.tar.gz bcfg2-0987e2a52629607a9868201085e9ba5b995f8fb8.tar.bz2 bcfg2-0987e2a52629607a9868201085e9ba5b995f8fb8.zip |
bcfg2-lint: ensure all XML properties files are parseable
Diffstat (limited to 'src/lib/Bcfg2/Server/Lint/Validate.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Lint/Validate.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lib/Bcfg2/Server/Lint/Validate.py b/src/lib/Bcfg2/Server/Lint/Validate.py index 37bc230d1..a5f41c7af 100644 --- a/src/lib/Bcfg2/Server/Lint/Validate.py +++ b/src/lib/Bcfg2/Server/Lint/Validate.py @@ -83,17 +83,12 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin): else: self.LintError("properties-schema-not-found", "No schema found for %s" % filename) + # ensure that it at least parses + self.parse(filename) - def validate(self, filename, schemafile, schema=None): - """validate a file against the given lxml.etree.Schema. - return True on success, False on failure """ - if schema is None: - # if no schema object was provided, instantiate one - schema = self._load_schema(schemafile) - if not schema: - return False + def parse(self, filename): try: - datafile = lxml.etree.parse(filename) + return lxml.etree.parse(filename) except SyntaxError: lint = Popen(["xmllint", filename], stdout=PIPE, stderr=STDOUT) self.LintError("xml-failed-to-parse", @@ -106,6 +101,15 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin): "Failed to open file %s" % filename) return False + def validate(self, filename, schemafile, schema=None): + """validate a file against the given lxml.etree.Schema. + return True on success, False on failure """ + if schema is None: + # if no schema object was provided, instantiate one + schema = self._load_schema(schemafile) + if not schema: + return False + datafile = self.parse(filename) if not schema.validate(datafile): cmd = ["xmllint"] if self.files is None: |