Commits

dirkbaechle committed 5ba470f

- added Docbook Tool to the sources
- added SConstruct for the MAN pages

Comments (0)

Files changed (1357)

 except:
     has_lxml = False
 
+try:
+  from lxml import etree
+except ImportError:
+  try:
+    # Python 2.5
+    import xml.etree.cElementTree as etree
+  except ImportError:
+    try:
+      # Python 2.5
+      import xml.etree.ElementTree as etree
+    except ImportError:
+      try:
+        # normal cElementTree install
+        import cElementTree as etree
+      except ImportError:
+        try:
+          # normal ElementTree install
+          import elementtree.ElementTree as etree
+        except ImportError:
+          print("Failed to import ElementTree from any known place")
+          sys.exit(1)
 
 re_entity = re.compile("\&([^;]+);")
-
-entity_header = """<!DOCTYPE sconsdoc [
-<!ENTITY % scons SYSTEM 'scons.mod'>
-%scons;
-<!ENTITY % builders-mod SYSTEM 'builders.mod'>
-%builders-mod;
-<!ENTITY % functions-mod SYSTEM 'functions.mod'>
-%functions-mod;
-<!ENTITY % tools-mod SYSTEM 'tools.mod'>
-%tools-mod;
-<!ENTITY % variables-mod SYSTEM 'variables.mod'>
-%variables-mod;
-]>"""
+re_entity_header = re.compile("<!DOCTYPE\s+sconsdoc\s+[^\]]+\]>")
 
 # Namespace for the SCons Docbook XSD
 dbxsd="http://www.scons.org/dbxsd/v1.0"
+# Namespace for schema instances
+xsi = "http://www.w3.org/2001/XMLSchema-instance"
 
-xml_header = """<?xml version="1.0" encoding="UTF-8"?>
-<!--
+# Header comment with copyright
+copyright_comment = """
 __COPYRIGHT__
 
 This file is processed by the bin/SConsDoc.py module.
 See its __doc__ string for a discussion of the format.
--->
+"""
+# Header comment for automatically generated files
+generated_comment = """
+    THIS IS AN AUTOMATICALLY-GENERATED FILE.  DO NOT EDIT.
+  """
 
-%s
+def xml_tree(root, comment=generated_comment):
+    """ Return a XML file tree with the correct namespaces set,
+        the element root as top entry and the given header comment.
+    """
+    NSMAP = {None: dbxsd,
+             'xsi' : xsi}
 
-<sconsdoc xmlns="http://www.scons.org/dbxsd/v1.0"
-          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-          xsi:schemaLocation="%s scons.xsd">
-""" % (entity_header, dbxsd)
+    t = etree.Element(root,
+                      nsmap = NSMAP,
+                      attrib = {"{"+xsi+"}schemaLocation" : "%s scons.xsd" % dbxsd})
+
+    c = etree.Comment(comment)
+    t.append(c)
+
+    # print etree.tostring(t, xml_declaration=True, encoding="UTF-8", pretty_print=True)
+
+    return t
 
 def remove_entities(content):
     # Cut out entity inclusions
-    content = content.replace(entity_header, "")
+    content = re_entity_header.sub("", content, re.M)
     # Cut out entities themselves
     content = re_entity.sub(lambda match: match.group(1), content)
     
         # to conflicts when installed together with libxml2.