From 834fbd437ab038737b5853e2e45763d2ff2317d8 Mon Sep 17 00:00:00 2001 From: Dirk Baechle Date: Sat, 4 May 2013 00:12:43 +0200 Subject: - added first version of the SCons XSD - rewrote User Guide XML files, such that they are valid against it --- bin/SConsDoc.py | 35 ++++++++++++++++++++++++++++++++++- bin/scons-proc.py | 15 ++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py index 8889923f..e5d28cd4 100644 --- a/bin/SConsDoc.py +++ b/bin/SConsDoc.py @@ -213,6 +213,39 @@ def validate_xml(fpath, xmlschema_context): return True +def prettyprint_xml(fpath): + if not has_libxml2: + # At the moment we prefer libxml2 over lxml, the latter can lead + # to conflicts when installed together with libxml2. + if has_lxml: + # Use lxml + from lxml import etree + fin = open(fpath,'r') + tree = etree.parse(fin) + pretty_content = etree.tostring(tree, pretty_print=True) + fin.close() + + fout = open(fpath,'w') + fout.write(pretty_content) + fout.close() + else: + # Use xmllint as a last fallback + try: + import subprocess + p = subprocess.Popen(['xmllint', '-o', fpath, '--format', fpath], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + sout, serr = p.communicate() + except: + print "Can't prettyprint %s! Neither lxml/libxml2, nor xmllint found." % fpath + return False + + # Read file and resolve entities + doc = libxml2.readFile(fpath, None, libxml2.XML_PARSE_NOENT) + err = xmlschema_context.schemaValidateDoc(doc) + # Cleanup + doc.freeDoc() + + perc="%" def validate_all_xml(dpath='src', xsdfile=default_xsd): @@ -302,7 +335,7 @@ class Builder(Item): class Function(Item): def __init__(self, name): super(Function, self).__init__(name) - self.arguments = [] + self.arguments = ['()'] class Tool(Item): def __init__(self, name): diff --git a/bin/scons-proc.py b/bin/scons-proc.py index 7a56a798..3d460ab2 100644 --- a/bin/scons-proc.py +++ b/bin/scons-proc.py @@ -126,6 +126,16 @@ class SCons_XML(object): fl = filename.split(',') filename = fl[0] f = self.fopen(filename) + + # Write XML header + f.write(""" + + +""" % (SConsDoc.dbxsd, SConsDoc.dbxsd)) + f.write(Warning) + for v in self.values: f.write('\n\n' % (v.prefix, v.idfunc())) @@ -149,6 +159,9 @@ class SCons_XML(object): f.write('\n') f.write('\n') + # Write end tag + f.write('\n\n') + def write_mod(self, filename): try: description = self.values[0].description @@ -262,7 +275,7 @@ class Function(SConsThing): signature = arg.signature except AttributeError: signature = "both" - s = self.args_to_xml(arg) + s = arg # TODO: self.args_to_xml(arg) if signature in ('both', 'global'): result.append('%s%s\n' % (self.name, s)) #
if signature in ('both', 'env'): -- cgit v1.2.1