def collectSConsExampleNames(fpath): """ Return a set() of example names, used in the given file fpath. """ names = set() suffixes = {} failed_suffixes = False # Create doctree t = SConsDoc.SConsDocTree() t.parseXmlFile(fpath) # Parse it for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid, t.xpath_context, t.nsmap): n = '' if stf.hasAttribute(e, 'name'): n = stf.getAttribute(e, 'name') if n: names.add(n) if n not in suffixes: suffixes[n] = [] else: 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, t.xpath_context, t.nsmap): n = '' if stf.hasAttribute(o, 'example'): n = stf.getAttribute(o, 'example') else: print("Error: scons_output in file '%s' is missing an example name!" % fpath) failed_suffixes = True if n not in suffixes: print("Error: scons_output in file '%s' is referencing non-existent example '%s'!" % (fpath, n)) failed_suffixes = True continue s = '' if stf.hasAttribute(o, 'suffix'): s = stf.getAttribute(o, 'suffix') else: print("Error: scons_output in file '%s' (example '%s') is missing a suffix!" % (fpath, n)) failed_suffixes = True if s not in suffixes[n]: suffixes[n].append(s) else: print("Error: scons_output in file '%s' (example '%s') is using a duplicate suffix '%s'!" % (fpath, n, s)) failed_suffixes = True return names, failed_suffixes
def readExampleInfos(fpath, examples): """ Add the example infos for the file fpath to the global dictionary examples. """ # Create doctree t = SConsDoc.SConsDocTree() t.parseXmlFile(fpath) # Parse scons_examples for e in stf.findAll(t.root, "scons_example", SConsDoc.dbxid, t.xpath_context, t.nsmap): n = '' if stf.hasAttribute(e, 'name'): n = stf.getAttribute(e, 'name') if n and n not in examples: i = ExampleInfo() i.name = n examples[n] = i # Parse file and directory entries for f in stf.findAll(e, "file", SConsDoc.dbxid, t.xpath_context, t.nsmap): fi = ExampleFile() if stf.hasAttribute(f, 'name'): fi.name = stf.getAttribute(f, 'name') if stf.hasAttribute(f, 'chmod'): 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, t.xpath_context, t.nsmap): di = ExampleFolder() if stf.hasAttribute(d, 'name'): di.name = stf.getAttribute(d, 'name') if stf.hasAttribute(d, 'chmod'): di.chmod = stf.getAttribute(d, 'chmod') examples[n].folders.append(di) # Parse scons_example_files 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') else: continue fi = ExampleFile(FT_FILEREF) if stf.hasAttribute(f, 'name'): fi.name = stf.getAttribute(f, 'name') if stf.hasAttribute(f, 'chmod'): fi.chmod = stf.getAttribute(f, 'chmod') fi.content = stf.getText(f) examples[e].files.append(fi) # Parse scons_output 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') else: continue eout = ExampleOutput() if stf.hasAttribute(o, 'name'): eout.name = stf.getAttribute(o, 'name') if stf.hasAttribute(o, 'tools'): eout.tools = stf.getAttribute(o, 'tools') if stf.hasAttribute(o, 'os'): eout.os = stf.getAttribute(o, 'os') if stf.hasAttribute(o, 'suffix'): eout.suffix = stf.getAttribute(o, 'suffix') for c in stf.findAll(o, "scons_output_command", SConsDoc.dbxid, t.xpath_context, t.nsmap): oc = ExampleCommand() if stf.hasAttribute(c, 'edit'): oc.edit = stf.getAttribute(c, 'edit') if stf.hasAttribute(c, 'environment'): oc.environment = stf.getAttribute(c, 'environment') if stf.hasAttribute(c, 'output'): oc.output = stf.getAttribute(c, 'output') if stf.hasAttribute(c, 'cmd'): oc.cmd = stf.getAttribute(c, 'cmd') else: oc.cmd = stf.getText(c) eout.commands.append(oc) examples[n].outputs.append(eout)