Exemple #1
0
    def xml_terms(self):
        if self.arguments is None:
            a = stf.newNode("arguments")
            stf.setText(a, '()')
            arguments = [a]
        else:
            arguments = self.arguments
        tlist = []
        for arg in arguments:
            signature = 'both'
            if stf.hasAttribute(arg, 'signature'):
                signature = stf.getAttribute(arg, 'signature')
            s = stf.getText(arg).strip()
            if signature in ('both', 'global'):
                t = stf.newNode("term")
                syn = stf.newNode("literal")
                stf.setText(syn, '%s%s' % (self.name, s))
                stf.appendNode(t, syn)
                tlist.append(t)
            if signature in ('both', 'env'):
                t = stf.newNode("term")
                syn = stf.newNode("literal")
                stf.setText(syn, 'env.%s%s' % (self.name, s))
                stf.appendNode(t, syn)
                tlist.append(t)

        if not tlist:
            tlist.append(stf.newNode("term"))
        return tlist
Exemple #2
0
    def xml_terms(self):
        if self.arguments is None:
            a = stf.newNode("arguments")
            stf.setText(a, '()')
            arguments = [a]
        else:
            arguments = self.arguments
        tlist = []
        for arg in arguments:
            signature = 'both'
            if stf.hasAttribute(arg, 'signature'):
                signature = stf.getAttribute(arg, 'signature')
            s = stf.getText(arg).strip()
            if signature in ('both', 'global'):
                t = stf.newNode("term")
                syn = stf.newNode("literal")
                stf.setText(syn, '%s%s' % (self.name, s))
                stf.appendNode(t, syn)
                tlist.append(t)
            if signature in ('both', 'env'):
                t = stf.newNode("term")
                syn = stf.newNode("literal")
                stf.setText(syn, 'env.%s%s' % (self.name, s))
                stf.appendNode(t, syn)
                tlist.append(t)

        if not tlist:
            tlist.append(stf.newNode("term"))
        return tlist
Exemple #3
0
    def xml_terms(self):
        """emit xml for an scons function

        The signature attribute controls whether to emit the
        global function, the environment method, or both.
        """
        if self.arguments is None:
            a = stf.newNode("arguments")
            stf.setText(a, '()')
            arguments = [a]
        else:
            arguments = self.arguments
        tlist = []
        for arg in arguments:
            signature = 'both'
            if stf.hasAttribute(arg, 'signature'):
                signature = stf.getAttribute(arg, 'signature')
            sig = stf.getText(arg).strip()[1:-1]  # strip (), temporarily
            if signature in ('both', 'global'):
                # build term for global function
                gterm = stf.newNode("term")
                func = stf.newSubNode(gterm, Function.tag)
                stf.setText(func, self.name)
                if sig:
                    # if there are parameters, use that entity
                    stf.setTail(func, "(")
                    s = stf.newSubNode(gterm, "parameter")
                    stf.setText(s, sig)
                    stf.setTail(s, ")")
                else:
                    stf.setTail(func, "()")
                tlist.append(gterm)
            if signature in ('both', 'env'):
                # build term for env. method
                mterm = stf.newNode("term")
                inst = stf.newSubNode(mterm, "replaceable")
                stf.setText(inst, "env")
                stf.setTail(inst, ".")
                # we could use <function> here, but it's a "method"
                meth = stf.newSubNode(mterm, "methodname")
                stf.setText(meth, self.name)
                if sig:
                    # if there are parameters, use that entity
                    stf.setTail(meth, "(")
                    s = stf.newSubNode(mterm, "parameter")
                    stf.setText(s, sig)
                    stf.setTail(s, ")")
                else:
                    stf.setTail(meth, "()")
                tlist.append(mterm)

        if not tlist:
            tlist.append(stf.newNode("term"))
        return tlist
Exemple #4
0
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)
Exemple #5
0
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)