Commits

dirkbaechle committed 446dc25

- simple fix

  • Participants
  • Parent commits be03313
  • Branches new_doc_toolchain

Comments (0)

Files changed (1)

File bin/SConsExamples.py

-#!/usr/bin/env python
-#
+# !/usr/bin/env python
+# 
 # Copyright (c) 2010 The SCons Foundation
-#
+# 
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
 # "Software"), to deal in the Software without restriction, including
 # distribute, sublicense, and/or sell copies of the Software, and to
 # permit persons to whom the Software is furnished to do so, subject to
 # the following conditions:
-#
+# 
 # The above copyright notice and this permission notice shall be included
 # in all copies or substantial portions of the Software.
-#
+# 
 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-#
-#
+# 
+# 
 # This script looks for some XML tags that describe SCons example
 # configurations and commands to execute in those configurations, and
 # uses TestCmd.py to execute the commands and insert the output from
 # those commands into the XML that we output.  This way, we can run a
 # script and update all of our example documentation output without
 # a lot of laborious by-hand checking.
-#
+# 
 # An "SCons example" looks like this, and essentially describes a set of
 # input files (program source files as well as SConscript files):
-#
+# 
 #       <scons_example name="ex1">
 #         <file name="SConstruct" printme="1">
 #           env = Environment()
 #           int main() { printf("foo.c\n"); }
 #         </file>
 #       </scons_example>
-#
+# 
 # The <file> contents within the <scons_example> tag will get written
 # into a temporary directory whenever example output needs to be
 # generated.  By default, the <file> contents are not inserted into text
 # in which case they will get inserted within a <programlisting> tag.
 # This makes it easy to define the example at the appropriate
 # point in the text where you intend to show the SConstruct file.
-#
+# 
 # Note that you should usually give the <scons_example> a "name"
 # attribute so that you can refer to the example configuration later to
 # run SCons and generate output.
-#
+# 
 # If you just want to show a file's contents without worry about running
 # SCons, there's a shorter <sconstruct> tag:
-#
+# 
 #       <sconstruct>
 #         env = Environment()
 #         env.Program('foo')
 #       </sconstruct>
-#
+# 
 # This is essentially equivalent to <scons_example><file printme="1">,
 # but it's more straightforward.
-#
+# 
 # SCons output is generated from the following sort of tag:
-#
+# 
 #       <scons_output example="ex1" os="posix">
 #         <scons_output_command suffix="1">scons -Q foo</scons_output_command>
 #         <scons_output_command suffix="2">scons -Q foo</scons_output_command>
 #       </scons_output>
-#
+# 
 # You tell it which example to use with the "example" attribute, and then
 # give it a list of <scons_output_command> tags to execute.  You can also
 # supply an "os" tag, which specifies the type of operating system this
 # example is intended to show; if you omit this, default value is "posix".
-#
+# 
 # The generated XML will show the command line (with the appropriate
 # command-line prompt for the operating system), execute the command in
 # a temporary directory with the example files, capture the standard
 # output from SCons, and insert it into the text as appropriate.
 # Error output gets passed through to your error output so you
 # can see if there are any problems executing the command.
-#
+# 
 
 import os
 import re
 import SConsDoc
 from SConsDoc import tf as stf
 
-#
+# 
 # The available types for ExampleFile entries
-#
-FT_FILE = 0     # a physical file (=<file>)
+# 
+FT_FILE = 0  # a physical file (=<file>)
 FT_FILEREF = 1  # a reference     (=<scons_example_file>)
 
 class ExampleFile:
     t.parseXmlFile(fpath)
     
     # Parse scons_examples
-    for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid, 
+    for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
         n = ''
         if stf.hasAttribute(e, 'name'):
             examples[n] = i
             
         # Parse file and directory entries
-        for f in stf.findAll(e, "file", SConsDoc.dbxid, 
+        for f in stf.findAll(e, "file", SConsDoc.dbxid,
                              t.xpath_context, t.nsmap):
             fi = ExampleFile()
             if stf.hasAttribute(f, 'name'):
                 fi.chmod = stf.getAttribute(f, 'chmod')
             fi.content = stf.getText(f)
             examples[n].files.append(fi)
-        for d in stf.findAll(e, "directory", SConsDoc.dbxid, 
+        for d in stf.findAll(e, "directory", SConsDoc.dbxid,
                              t.xpath_context, t.nsmap):
             di = ExampleFolder()
             if stf.hasAttribute(d, 'name'):
 
 
     # Parse scons_example_files
-    for f in stf.findAll(t.root, "scons_example_file", SConsDoc.dbxid, 
+    for f in stf.findAll(t.root, "scons_example_file", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
         if stf.hasAttribute(f, 'example'):
             e = stf.getAttribute(f, 'example')
         
     
     # Parse scons_output
-    for o in stf.findAll(t.root, "scons_output", SConsDoc.dbxid, 
+    for o in stf.findAll(t.root, "scons_output", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
         if stf.hasAttribute(o, 'example'):
             n = stf.getAttribute(o, 'example')
         if stf.hasAttribute(o, 'suffix'):
             eout.suffix = stf.getAttribute(o, 'suffix')
 
-        for c in stf.findAll(o, "scons_output_command", SConsDoc.dbxid, 
+        for c in stf.findAll(o, "scons_output_command", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
             oc = ExampleCommand()
             if stf.hasAttribute(c, 'edit'):
                    
     return examples
 
-generated_examples = os.path.join('doc','generated','examples')
+generated_examples = os.path.join('doc', 'generated', 'examples')
 
 def ensureExampleOutputsExist(dpath):
     """ Scan for XML files in the given directory and 
     for key, value in examples.iteritems():
         # Process all scons_output tags
         for o in value.outputs:
-            cpath = os.path.join(generated_examples, 
-                                 key+'_'+o.suffix+'.xml')
+            cpath = os.path.join(generated_examples,
+                                 key + '_' + o.suffix + '.xml')
             if not os.path.isfile(cpath):
                 # Start new XML file
                 s = stf.newXmlTree("screen")
             if r.isFileRef():
                 # Get file's content
                 content = value.getFileContents(r.name)
-                fpath = os.path.join(generated_examples, 
-                                     key+'_'+r.name.replace("/","_"))
+                fpath = os.path.join(generated_examples,
+                                     key + '_' + r.name.replace("/", "_"))
                 # Write file
                 f = open(fpath, 'w')
                 f.write("%s\n" % content)
     idx = 0
     for key, value in examples.iteritems():
         # Process all scons_output tags
-        print "%.2f%s (%d/%d) %s" % (float(idx+1)*100.0/float(total),
-                                     perc, idx+1, total, key)
+        print "%.2f%s (%d/%d) %s" % (float(idx + 1) * 100.0 / float(total),
+                                     perc, idx + 1, total, key)
         
         create_scons_output(value)
         # Process all scons_example_file tags
             if r.isFileRef():
                 # Get file's content
                 content = value.getFileContents(r.name)
-                fpath = os.path.join(generated_examples, 
-                                     key+'_'+r.name.replace("/","_"))
+                fpath = os.path.join(generated_examples,
+                                     key + '_' + r.name.replace("/", "_"))
                 # Write file
                 f = open(fpath, 'w')
                 f.write("%s\n" % content)
     t.parseXmlFile(fpath)
     
     # Parse it
-    for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid, 
+    for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
         n = ''
         if stf.hasAttribute(e, 'name'):
             print "Error: Example in file '%s' is missing a name!" % fpath
             failed_suffixes = True
     
-    for o in stf.findAll(t.root, "scons_output", SConsDoc.dbxid, 
+    for o in stf.findAll(t.root, "scons_output", SConsDoc.dbxid,
                          t.xpath_context, t.nsmap):
         n = ''
         if stf.hasAttribute(o, 'example'):
                    
     return unique
 
-################################################################
-#
+# ###############################################################
+# 
 # In the second half of this module (starting here)
 # we define the variables and functions that are required
 # to actually run the examples, collect their output and
 # write it into the files in doc/generated/examples...
 # which then get included by our UserGuide.
-#
-################################################################
+# 
+# ###############################################################
 
 sys.path.append(os.path.join(os.getcwd(), 'QMTest'))
 sys.path.append(os.path.join(os.getcwd(), 'build', 'QMTest'))
 }
 
 # The magick SCons hackery that makes this work.
-#
+# 
 # So that our examples can still use the default SConstruct file, we
 # actually feed the following into SCons via stdin and then have it
 # SConscript() the SConstruct file.  This stdin wrapper creates a set
 # Surrogates print output like the real tools and behave like them
 # without actually having to be on the right platform or have the right
 # tool installed.
-#
+# 
 # The upshot:  The wrapper transparently changes the world out from
 # under the top-level SConstruct file in an example just so we can get
 # the command output.
             except KeyError:
                 delete_keys.append(key)
             os.environ[key] = val
-    test.run(interpreter = sys.executable,
-             program = scons_py,
+    test.run(interpreter=sys.executable,
+             program=scons_py,
              # We use ToolSurrogates to capture win32 output by "building"
              # examples using a fake win32 tool chain.  Suppress the
              # warnings that come from the new revamped VS support so
              # we can build doc on (Linux) systems that don't have
              # Visual C installed.
-             arguments = '--warn=no-visual-c-missing -f - ' + ' '.join(args),
-             chdir = test.workpath('WORK'),
-             stdin = Stdin % dict)
+             arguments='--warn=no-visual-c-missing -f - ' + ' '.join(args),
+             chdir=test.workpath('WORK'),
+             stdin=Stdin % dict)
     os.environ.update(save_vals)
     for key in delete_keys:
         del(os.environ[key])
     if lines:
         while lines[-1] == '':
             lines = lines[:-1]
-    #err = test.stderr()
-    #if err:
+    # err = test.stderr()
+    # if err:
     #    sys.stderr.write(err)
     return lines
 
         for f in e.files:
             if f.isFileRef():
                 continue
-            #
+            # 
             # Left-align file's contents, starting on the first
             # non-empty line
-            #
+            # 
             data = f.content.split('\n')
             i = 0
             # Skip empty lines
                 sroot.text = content
    
         # Construct filename
-        fpath = os.path.join(generated_examples, 
-                             e.name+'_'+o.suffix+'.xml')
+        fpath = os.path.join(generated_examples,
+                             e.name + '_' + o.suffix + '.xml')
         # Expand Element tree
-        s = stf.decorateWithCommentHeader(stf.convertElementTree(sroot)[0])
+        s = stf.decorateWithHeader(stf.convertElementTree(sroot)[0])
         # Write it to file
         stf.writeTree(s, fpath)