def ensureExampleOutputsExist(dpath): """ Scan for XML files in the given directory and ensure that for every example output we have a corresponding output file in the 'generated/examples' folder. """ # Ensure that the output folder exists if not os.path.isdir(generated_examples): os.mkdir(generated_examples) examples = readAllExampleInfos(dpath) for key, value in examples.items(): # Process all scons_output tags for o in value.outputs: cpath = os.path.join(generated_examples, key + '_' + o.suffix + '.xml') if not os.path.isfile(cpath): # Start new XML file s = stf.newXmlTree("screen") stf.setText(s, "NO OUTPUT YET! Run the script to generate/update all examples.") # Write file stf.writeTree(s, cpath) # Process all scons_example_file tags for r in value.files: if r.isFileRef(): # Get file's content content = value.getFileContents(r.name) fpath = os.path.join(generated_examples, key + '_' + r.name.replace("/", "_")) # Write file with open(fpath, 'w') as f: f.write("%s\n" % content)
def ensureExampleOutputsExist(dpath): """ Scan for XML files in the given directory and ensure that for every example output we have a corresponding output file in the 'generated/examples' folder. """ # Ensure that the output folder exists if not os.path.isdir(generated_examples): os.mkdir(generated_examples) examples = readAllExampleInfos(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') if not os.path.isfile(cpath): # Start new XML file s = stf.newXmlTree("screen") stf.setText(s, "NO OUTPUT YET! Run the script to generate/update all examples.") # Write file stf.writeTree(s, cpath) # Process all scons_example_file tags for r in value.files: if r.isFileRef(): # Get file's content content = value.getFileContents(r.name) fpath = os.path.join(generated_examples, key + '_' + r.name.replace("/", "_")) # Write file f = open(fpath, 'w') f.write("%s\n" % content) f.close()
def create_scons_output(e): """ The real raison d'etre for this script, this is where we actually execute SCons to fetch the output. """ # Loop over all outputs for the example for o in e.outputs: # Create new test directory t = TestCmd.TestCmd(workdir='', combine=1) if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') t.rootpath = t.workpath('ROOT').replace('\\', '\\\\') for d in e.folders: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) 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 while data[i] == '': i = i + 1 lines = data[i:] i = 0 # Scan first line for the number of spaces # that this block is indented while lines[0][i] == ' ': i = i + 1 # Left-align block lines = [l[i:] for l in lines] path = f.name.replace('__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) content = '\n'.join(lines) content = content.replace('__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): if len(f.chmod): os.chmod(path, int(f.chmod, base=8)) # Regular expressions for making the doc output consistent, # regardless of reported addresses or Python version. # Massage addresses in object repr strings to a constant. address_re = re.compile(r' at 0x[0-9a-fA-F]*>') # Massage file names in stack traces (sometimes reported as absolute # paths) to a consistent relative path. engine_re = re.compile(r' File ".*/src/engine/SCons/') # Python 2.5 changed the stack trace when the module is read # from standard input from read "... line 7, in ?" to # "... line 7, in <module>". file_re = re.compile(r'^( *File ".*", line \d+, in) \?$', re.M) # Python 2.6 made UserList a new-style class, which changes the # AttributeError message generated by our NodeList subclass. nodelist_re = re.compile(r'(AttributeError:) NodeList instance (has no attribute \S+)') # Root element for our subtree sroot = stf.newEtreeNode("screen", True) curchild = None content = "" for command in o.commands: content += Prompt[o.os] if curchild is not None: if not command.output: # Append content as tail curchild.tail = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = command.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += command.output + '\n' else: if not command.output: # Add first text to root sroot.text = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = command.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += command.output + '\n' # Execute command and capture its output cmd_work = command.cmd.replace('__ROOT__', t.workpath('ROOT')) args = cmd_work.split() lines = ExecuteCommand(args, command, t, {'osname':o.os, 'tools':o.tools}) if not command.output and lines: ncontent = '\n'.join(lines) ncontent = address_re.sub(r' at 0x700000>', ncontent) ncontent = engine_re.sub(r' File "bootstrap/src/engine/SCons/', ncontent) ncontent = file_re.sub(r'\1 <module>', ncontent) ncontent = nodelist_re.sub(r"\1 'NodeList' object \2", ncontent) ncontent = ncontent.replace('__ROOT__', '') content += ncontent + '\n' # Add last piece of content if len(content): if curchild is not None: curchild.tail = content else: sroot.text = content # Construct filename fpath = os.path.join(generated_examples, e.name + '_' + o.suffix + '.xml') # Expand Element tree s = stf.decorateWithHeader(stf.convertElementTree(sroot)[0]) # Write it to file stf.writeTree(s, fpath)
def create_scons_output(e): # The real raison d'etre for this script, this is where we # actually execute SCons to fetch the output. # Loop over all outputs for the example for o in e.outputs: # Create new test directory t = TestCmd.TestCmd(workdir='', combine=1) if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') t.rootpath = t.workpath('ROOT').replace('\\', '\\\\') for d in e.folders: dir = t.workpath('WORK', d.name) if not os.path.exists(dir): os.makedirs(dir) 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 while data[i] == '': i = i + 1 lines = data[i:] i = 0 # Scan first line for the number of spaces # that this block is indented while lines[0][i] == ' ': i = i + 1 # Left-align block lines = [l[i:] for l in lines] path = f.name.replace('__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) content = '\n'.join(lines) content = content.replace('__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): if len(f.chmod): os.chmod(path, int(f.chmod, 0)) # Regular expressions for making the doc output consistent, # regardless of reported addresses or Python version. # Massage addresses in object repr strings to a constant. address_re = re.compile(r' at 0x[0-9a-fA-F]*\>') # Massage file names in stack traces (sometimes reported as absolute # paths) to a consistent relative path. engine_re = re.compile(r' File ".*/src/engine/SCons/') # Python 2.5 changed the stack trace when the module is read # from standard input from read "... line 7, in ?" to # "... line 7, in <module>". file_re = re.compile(r'^( *File ".*", line \d+, in) \?$', re.M) # Python 2.6 made UserList a new-style class, which changes the # AttributeError message generated by our NodeList subclass. nodelist_re = re.compile(r'(AttributeError:) NodeList instance (has no attribute \S+)') # Root element for our subtree sroot = stf.newEtreeNode("screen", True) curchild = None content = "" for c in o.commands: content += Prompt[o.os] if curchild is not None: if not c.output: # Append content as tail curchild.tail = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = c.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += c.output + '\n' else: if not c.output: # Add first text to root sroot.text = content content = "\n" # Add new child for userinput tag curchild = stf.newEtreeNode("userinput") d = c.cmd.replace('__ROOT__', '') curchild.text = d sroot.append(curchild) else: content += c.output + '\n' # Execute command and capture its output cmd_work = c.cmd.replace('__ROOT__', t.workpath('ROOT')) args = cmd_work.split() lines = ExecuteCommand(args, c, t, {'osname':o.os, 'tools':o.tools}) if not c.output and lines: ncontent = '\n'.join(lines) ncontent = address_re.sub(r' at 0x700000>', ncontent) ncontent = engine_re.sub(r' File "bootstrap/src/engine/SCons/', ncontent) ncontent = file_re.sub(r'\1 <module>', ncontent) ncontent = nodelist_re.sub(r"\1 'NodeList' object \2", ncontent) ncontent = ncontent.replace('__ROOT__', '') content += ncontent + '\n' # Add last piece of content if len(content): if curchild is not None: curchild.tail = content else: sroot.text = content # Construct filename fpath = os.path.join(generated_examples, e.name + '_' + o.suffix + '.xml') # Expand Element tree s = stf.decorateWithHeader(stf.convertElementTree(sroot)[0]) # Write it to file stf.writeTree(s, fpath)