diff options
Diffstat (limited to 'bin/SConsExamples.py')
-rw-r--r-- | bin/SConsExamples.py | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/bin/SConsExamples.py b/bin/SConsExamples.py index cba248b..9823a05 100644 --- a/bin/SConsExamples.py +++ b/bin/SConsExamples.py @@ -1,7 +1,7 @@ -#!/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 @@ -9,10 +9,10 @@ # 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 @@ -21,18 +21,18 @@ # 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() @@ -42,7 +42,7 @@ # 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 @@ -50,41 +50,41 @@ # 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 @@ -94,10 +94,10 @@ import time 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: @@ -155,7 +155,7 @@ def readExampleInfos(fpath, examples): 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'): @@ -166,7 +166,7 @@ def readExampleInfos(fpath, examples): 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'): @@ -175,7 +175,7 @@ def readExampleInfos(fpath, examples): 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'): @@ -186,7 +186,7 @@ def readExampleInfos(fpath, examples): # 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') @@ -202,7 +202,7 @@ def readExampleInfos(fpath, examples): # 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') @@ -219,7 +219,7 @@ def readExampleInfos(fpath, examples): 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'): @@ -252,7 +252,7 @@ def readAllExampleInfos(dpath): 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 @@ -268,8 +268,8 @@ def ensureExampleOutputsExist(dpath): 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") @@ -282,8 +282,8 @@ def ensureExampleOutputsExist(dpath): 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) @@ -305,8 +305,8 @@ def createAllExampleOutputs(dpath): 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 @@ -314,8 +314,8 @@ def createAllExampleOutputs(dpath): 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) @@ -334,7 +334,7 @@ def collectSConsExampleNames(fpath): 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'): @@ -347,7 +347,7 @@ def collectSConsExampleNames(fpath): 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'): @@ -399,15 +399,15 @@ def exampleNamesAreUnique(dpath): 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')) @@ -430,7 +430,7 @@ Prompt = { } # 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 @@ -438,7 +438,7 @@ Prompt = { # 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. @@ -676,16 +676,16 @@ def command_scons(args, c, test, dict): 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]) @@ -697,8 +697,8 @@ def command_scons(args, c, test, dict): if lines: while lines[-1] == '': lines = lines[:-1] - #err = test.stderr() - #if err: + # err = test.stderr() + # if err: # sys.stderr.write(err) return lines @@ -783,10 +783,10 @@ def create_scons_output(e): 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 @@ -883,10 +883,10 @@ def create_scons_output(e): 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) |