Exemple #1
0
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)
Exemple #2
0
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()
Exemple #3
0
    def write_gen(self, filename):
        if not filename:
            return
        # Try to split off .gen filename
        if filename.count(','):
            fl = filename.split(',')
            filename = fl[0]

        # Start new XML file
        root = stf.newXmlTree("variablelist")

        for v in self.values:

            ve = stf.newNode("varlistentry")
            stf.setAttribute(ve, 'id', '%s%s' % (v.prefix, v.idfunc()))
            for t in v.xml_terms():
                stf.appendNode(ve, t)
            vl = stf.newNode("listitem")
            added = False
            if v.summary is not None:
                for s in v.summary:
                    added = True
                    stf.appendNode(vl, stf.copyNode(s))

            if v.sets:
                added = True
                vp = stf.newNode("para")
                stf.setText(vp, 'Sets: ')
                for x in v.sets[:-1]:
                    stf.appendCvLink(vp, x, ', ')
                stf.appendCvLink(vp, v.sets[-1], '.')
                stf.appendNode(vl, vp)

            if v.uses:
                added = True
                vp = stf.newNode("para")
                stf.setText(vp, 'Uses: ')
                for x in v.uses[:-1]:
                    stf.appendCvLink(vp, x, ', ')
                stf.appendCvLink(vp, v.uses[-1], '.')
                stf.appendNode(vl, vp)

            # Still nothing added to this list item?
            if not added:
                # Append an empty para
                vp = stf.newNode("para")
                stf.appendNode(vl, vp)

            stf.appendNode(ve, vl)
            stf.appendNode(root, ve)

        # Write file
        f = self.fopen(filename)
        stf.writeGenTree(root, f)
        f.close()
Exemple #4
0
 def write_gen(self, filename):
     if not filename:
         return
     # Try to split off .gen filename
     if filename.count(','):
         fl = filename.split(',')
         filename = fl[0]
         
     # Start new XML file
     root = stf.newXmlTree("variablelist")
     
     for v in self.values:
         
         ve = stf.newNode("varlistentry")
         stf.setAttribute(ve, 'id', '%s%s' % (v.prefix, v.idfunc()))
         for t in v.xml_terms():
             stf.appendNode(ve, t)
         vl = stf.newNode("listitem")
         added = False
         if v.summary is not None:
             for s in v.summary:
                 added = True
                 stf.appendNode(vl, stf.copyNode(s))
         
         if len(v.sets):
             added = True
             vp = stf.newNode("para")
             s = ['&cv-link-%s;' % x for x in v.sets]
             stf.setText(vp, 'Sets:  ' + ', '.join(s) + '.')
             stf.appendNode(vl, vp)
         if len(v.uses):
             added = True
             vp = stf.newNode("para")
             u = ['&cv-link-%s;' % x for x in v.uses]
             stf.setText(vp, 'Uses:  ' + ', '.join(u) + '.')
             stf.appendNode(vl, vp)
             
         # Still nothing added to this list item?
         if not added:
             # Append an empty para
             vp = stf.newNode("para")
             stf.appendNode(vl, vp)
             
         stf.appendNode(ve, vl)
         stf.appendNode(root, ve)
         
     # Write file        
     f = self.fopen(filename)
     stf.writeGenTree(root, f)
Exemple #5
0
    def write_gen(self, filename):
        if not filename:
            return
        # Try to split off .gen filename
        if filename.count(','):
            fl = filename.split(',')
            filename = fl[0]

        # Start new XML file
        root = stf.newXmlTree("variablelist")

        for v in self.values:

            ve = stf.newNode("varlistentry")
            stf.setAttribute(ve, 'id', '%s%s' % (v.prefix, v.idfunc()))
            for t in v.xml_terms():
                stf.appendNode(ve, t)
            vl = stf.newNode("listitem")
            added = False
            if v.summary is not None:
                for s in v.summary:
                    added = True
                    stf.appendNode(vl, stf.copyNode(s))

            # Generate the text for sets/uses lists of construction vars.
            # This used to include an entity reference which would be replaced
            # by the link to the cvar, but with lxml, dumping out the tree
            # with tostring() will encode the & introducing the entity,
            # breaking it. Instead generate the actual link. (issue #3580)
            if v.sets:
                added = True
                vp = stf.newNode("para")
                stf.setText(vp, "Sets: ")
                for setv in v.sets:
                    link = stf.newSubNode(vp, "link", linkend="cv-%s" % setv)
                    linktgt = stf.newSubNode(link, "varname")
                    stf.setText(linktgt, "$" + setv)
                    stf.setTail(link, " ")
                stf.appendNode(vl, vp)

            if v.uses:
                added = True
                vp = stf.newNode("para")
                stf.setText(vp, "Uses: ")
                for use in v.uses:
                    link = stf.newSubNode(vp, "link", linkend="cv-%s" % use)
                    linktgt = stf.newSubNode(link, "varname")
                    stf.setText(linktgt, "$" + use)
                    stf.setTail(link, " ")
                stf.appendNode(vl, vp)

            # Still nothing added to this list item?
            if not added:
                # Append an empty para
                vp = stf.newNode("para")
                stf.appendNode(vl, vp)

            stf.appendNode(ve, vl)
            stf.appendNode(root, ve)

        # Write file
        f = self.fopen(filename)
        stf.writeGenTree(root, f)
        f.close()