示例#1
0
def genDCD(devlist, path, wavedevPath, nodeName, dmName = 'DeviceManager', folder = False, generate = True, devconf = ""):

    outputFilename_dcd = dmName + '.dcd.xml'

    doc_dcd = xml.dom.minidom.parse(wavedevPath + 'XML_gen/templates/_dcd.xml.tpl')

    deviceconfigurationNode = doc_dcd.getElementsByTagName("deviceconfiguration")[0]

    if devconf=="":
        deviceconfigurationNode.setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()))
    else:
        deviceconfigurationNode.setAttribute("id", unicode(devconf) )

    deviceconfigurationNode.setAttribute("name", unicode(dmName + "_" + nodeName) )

    devicemanagersoftpkgNode = deviceconfigurationNode.getElementsByTagName("devicemanagersoftpkg")[0]
    devicemanagersoftpkgNode.getElementsByTagName("localfile")[0].setAttribute("name", unicode('/nodes/'+nodeName+'/'+dmName+'.spd.xml'))

    baseDeviceList = []
    componentfilesNode = deviceconfigurationNode.getElementsByTagName("componentfiles")[0]
    partitioningNode = deviceconfigurationNode.getElementsByTagName("partitioning")[0]
    for n in devlist:
        if generate:
            tmpid = unicode(n.name) + u'_' + unicode(n.file_uuid)
        else:
            tmpid = unicode(n.file_uuid)

        if n.baseName not in baseDeviceList:
        # Generate the componentfile entries
            baseDeviceList.append(n.baseName)
            componentfileNode = doc_dcd.createElement("componentfile")
            componentfileNode.setAttribute("type", "SPD")
            componentfileNode.setAttribute("id", tmpid)

            localcomponentfileNode = doc_dcd.createElement("localfile")
            localcomponentfileNode.setAttribute("name", unicode(xmlpath + n.baseName + '/' + n.baseName + '.spd.xml') )

            componentfileNode.appendChild(localcomponentfileNode)
            componentfilesNode.appendChild(componentfileNode)

        # Generate the partitioning entries
        componentplacementNode = doc_dcd.createElement("componentplacement")
        componentfilerefNode = doc_dcd.createElement("componentfileref")
        componentfilerefNode.setAttribute("refid", tmpid)
        componentinstantiationNode = doc_dcd.createElement("componentinstantiation")
        componentinstantiationNode.setAttribute("id", u'DCE:' + unicode(n.uuid) )
        usagenameNode = doc_dcd.createElement("usagename")
        usagenameTextNode = doc_dcd.createTextNode(n.name)

        # Append nodes to partitioning
        usagenameNode.appendChild(usagenameTextNode)
        componentinstantiationNode.appendChild(usagenameNode)
        componentplacementNode.appendChild(componentfilerefNode)
        componentplacementNode.appendChild(componentinstantiationNode)
        partitioningNode.appendChild(componentplacementNode)

    # Create and beautify the dcd file as a temporary file
    data = doc_dcd.toxml('UTF-8')
    xmlBeautify.beautify(data,path + '.' + outputFilename_dcd + '.tmp')
    # Create and beautify the dcd file as a temporary file
    data = doc_dcd.toxml('UTF-8')
    xmlBeautify.beautify(data,path + '.' + outputFilename_dcd + '.tmp')

    # Post Processing - add some of the header lines

    preProcessed_dcd = open(path + '.' + outputFilename_dcd + '.tmp', 'r')
    postProcessed_dcd = open(path + outputFilename_dcd, 'w')

    # Specify external DTD
    line0 = preProcessed_dcd.readline()
    remaining = preProcessed_dcd.readlines()
    postProcessed_dcd.writelines(line0)
    postProcessed_dcd.writelines(u'<!DOCTYPE deviceconfiguration SYSTEM \"../../xml/dtd/deviceconfiguration.dtd\">\n')
    postProcessed_dcd.writelines(commentLine)
    postProcessed_dcd.writelines(remaining)
    postProcessed_dcd.close()

    # Remove temporary files
    os.remove(path + '.' + outputFilename_dcd + '.tmp')
示例#2
0
def genxml(complist, genPath, wavedevPath, waveName):
    if genPath[len(genPath)-1] != '/':
        genPath = genPath + '/'
    genPath = unicode(genPath)
    if len(wavedevPath) > 0 and wavedevPath[len(wavedevPath)-1] != '/':
        wavedevPath = wavedevPath + '/'
    waveformDir = unicode(genPath + waveName + '/')


    appName = unicode(waveName)
    #namingServicePrefix = u'ossie'
    outputFilename_sad = appName + u'.sad.xml'

    # Generate the individual component xml files
    for n in complist:
        if n.generate:
            component_gen.gen_scd(n, genPath, wavedevPath)
            component_gen.gen_spd(n, genPath, wavedevPath)
            component_gen.gen_prf(n, genPath, wavedevPath)

    #----------------------------------------------------------------------------
    # SAD Parser / Generator
    #

    # Use the minidom module to objectify and generate the SAD file
    try:  #if running from wavedev
        doc_sad = xml.dom.minidom.parse(wavedevPath + '/XML_gen/templates/_sad.xml.tpl')
    except:   #if not being called from wavedev, try looking for the file
        #doc_sad = xml.dom.minidom.parse('/sdr/tools/WaveDev/wavedev/XML_gen/_sad.xml.tpl')
        templates = __import__('WaveDev').__file__
        if os.path.islink (templates):
            templates = os.path.realpath (templates)
        templates = os.path.dirname (os.path.abspath (templates)) + '/wavedev/XML_gen/templates'
        doc_sad = xml.dom.minidom.parse(templates + '/_sad.xml.tpl')

    doc_sad.getElementsByTagName("softwareassembly")[0].setAttribute("name", u'OSSIE::' + appName )
    doc_sad.getElementsByTagName("softwareassembly")[0].setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()) )

    # get root nodes for componentfiles, partitioning, assemblycontroller, and connections tags
    componentfilesNode = doc_sad.getElementsByTagName("componentfiles")[0]
    partitioningNode = doc_sad.getElementsByTagName("partitioning")[0]
    assemblycontrollerNode = doc_sad.getElementsByTagName("assemblycontroller")[0]
    connectionsNode = doc_sad.getElementsByTagName("connections")[0]

    baseComponentList = []
    for n in complist:
        # Generate the componentfile entries
        #tmpid = unicode(n.name) + u'_' + unicode(uuidgen.uuidgen())
        tmpid = unicode(n.baseName) + u'_' + unicode(n.file_uuid)

        if n.baseName not in baseComponentList:
            baseComponentList.append(n.baseName)

            # create component file tag node
            componentfileNode = doc_sad.createElement("componentfile")
            componentfileNode.setAttribute("type", "SPD")
            componentfileNode.setAttribute("id", tmpid)

            # create localfile tag node
            localfileNode = doc_sad.createElement("localfile")
            localfileNode.setAttribute("name", unicode(xmlpath + n.baseName + '/' + n.xmlName + '.spd.xml') )

            # append nodes to .sad.xml file
            componentfileNode.appendChild(localfileNode)
            componentfilesNode.appendChild(componentfileNode)

        # Generate the partitioning elements
        componentplacementNode = doc_sad.createElement("componentplacement")
        componentfilerefNode = doc_sad.createElement("componentfileref")
        componentinstantiationNode = doc_sad.createElement("componentinstantiation")
        usagenameNode = doc_sad.createElement("usagename")
        usagenameTextNode = doc_sad.createTextNode(unicode(n.name))
        usagenameNode.appendChild(usagenameTextNode)
        findcomponentNode = doc_sad.createElement("findcomponent")

        # Set attributes appropriately
        componentfilerefNode.setAttribute("refid", tmpid)
        n.instanceUUID = uuidgen.uuidgen()
        componentinstantiationNode.setAttribute("id", u'DCE:' + unicode(n.instanceUUID))

        # Check for overloaded properties
        overload_flag = False
        for tmp_prop in n.properties:
            if tmp_prop.elementType == "Simple":
                if tmp_prop.value != tmp_prop.defaultValue:
                    overload_flag = True
            if tmp_prop.elementType == "SimpleSequence":
                try:
                    if tmp_prop.values != tmp_prop.defaultValues:
                        overload_flag = True
                except:
                    pass

        if overload_flag:
            componentpropertiesNode = doc_sad.createElement("componentproperties")
            for tmp_prop in n.properties:
                if tmp_prop.elementType == "Simple":
                    if tmp_prop.value != tmp_prop.defaultValue:
                        simplerefNode = doc_sad.createElement("simpleref")
                        simplerefNode.setAttribute("refid", unicode(tmp_prop.id))
                        simplerefNode.setAttribute("name", unicode(tmp_prop.name) )
                        simplerefNode.setAttribute("description", unicode(tmp_prop.description))
                        simplerefNode.setAttribute("value", unicode(tmp_prop.value))
                        componentpropertiesNode.appendChild(simplerefNode)

                if tmp_prop.elementType == "SimpleSequence":
                    ssflag = False
                    try:
                        if tmp_prop.values != tmp_prop.defaultValues:
                            ssflag = True
                    except:
                        pass

                    if ssflag:
                        simplesequencerefNode = doc_sad.createElement("simplesequenceref")
                        simplesequencerefNode.setAttribute("refid", unicode(tmp_prop.id) )
                        simplesequencerefNode.setAttribute("name", unicode(tmp_prop.name) )
                        simplesequencerefNode.setAttribute("description", unicode(tmp_prop.description) )
                        valuesNode = doc_sad.createElement("values")

                        for tmp_v2 in tmp_prop.values:
                            valueNode = doc_sad.createElement("value")
                            valuetextNode = doc_sad.createTextNode(tmp_v2)
                            valueNode.appendChild(valuetextNode)
                            valuesNode.appendChild(valueNode)

                        simplesequencerefNode.appendChild(valuesNode)
                        componentpropertiesNode.appendChild(simplesequencerefNode)

            # if there are overloaded properties, add to .sad.xml file
            componentinstantiationNode.appendChild(componentpropertiesNode)


        #NSname = u'DomainName1/' + namingServicePrefix + unicode(n.name) + u'Resource'
#        NSname = u'DomainName1/' + unicode(n.name)
        NSname = unicode(n.name)

        namingserviceNode = doc_sad.createElement("namingservice")
        namingserviceNode.setAttribute("name", NSname)
        findcomponentNode.appendChild(namingserviceNode)

        #TODO: append child nodes to componentplacement
        componentinstantiationNode.appendChild(usagenameNode)
        componentinstantiationNode.appendChild(findcomponentNode)
        componentplacementNode.appendChild(componentfilerefNode)
        componentplacementNode.appendChild(componentinstantiationNode)

        partitioningNode.appendChild(componentplacementNode)

        # Generate the connections entries
        for i in n.connections:
            cname = unicode(n.name)
            devFlag = False

#            print "Processing connection : "
#            print "  component name  : " + cname
#            print "  local comp type : " + n.type
#            print "  local port type : " + i.localPort.type
#            print "  local port name : " + unicode(i.localPort.name)
#            print "  remote comp type: " + i.remoteComp.type
#            print "  remote port type: " + i.remotePort.type
#            print "  remote port name: " + unicode(i.remotePort.name)

            if i.localPort.type == 'Uses':
                uname = unicode(i.localPort.name)
                pname = unicode(i.remotePort.name)
#                c1name = u'DomainName1/' + cname
#                c2name = u'DomainName1/' + unicode(i.remoteComp.name)
                c1name = cname
                c2name = unicode(i.remoteComp.name)
                if i.remoteComp.type.lower() == "device" \
                or i.remoteComp.type.lower() == "executabledevice" \
                or i.remoteComp.type.lower() == "aggregatedevice":
                    dev_pname = u'DomainName1/' + pname
                    devFlag = True
            else:
                pname = unicode(i.localPort.name)
                uname = unicode(i.remotePort.name)
 #               c2name = u'DomainName1/' + cname
 #               c1name = u'DomainName1/' + unicode(i.remoteComp.name)
                c2name = cname
                c1name = unicode(i.remoteComp.name)
                if n.type.lower() == "device" \
                or n.type.lower() == "executabledevice" \
                or n.type.lower() == "aggregatedevice":
                    dev_pname = u'DomainName1/' + pname
                    devFlag = True

            connectinterfaceNode = doc_sad.createElement("connectinterface")
            connectinterfaceNode.setAttribute("id",u'DCE:' + unicode(uuidgen.uuidgen()))

            usesportNode = doc_sad.createElement("usesport")
            usesidentifierNode = doc_sad.createElement("usesidentifier")
            usesidentifierTextNode = doc_sad.createTextNode(uname)
            findbyUsesNode = doc_sad.createElement("findby")
            namingserviceUsesNode = doc_sad.createElement("namingservice")
            # TODO: this is a dirty hack that needs to be fixed!
            if c1name == "USRP1":
                c1name = "DomainName1/USRP1"
            namingserviceUsesNode.setAttribute("name", c1name)

            # Append child nodes
            usesidentifierNode.appendChild(usesidentifierTextNode)
            findbyUsesNode.appendChild(namingserviceUsesNode)
            usesportNode.appendChild(usesidentifierNode)
            usesportNode.appendChild(findbyUsesNode)

            if devFlag != True:
                providesportNode = doc_sad.createElement("providesport")
                providesidentifierNode = doc_sad.createElement("providesidentifier")
                providesidentifierTextNode = doc_sad.createTextNode(pname)
                findbyProvidesNode = doc_sad.createElement("findby")
                namingserviceProvidesNode = doc_sad.createElement("namingservice")
                namingserviceProvidesNode.setAttribute("name", c2name)

                # Make connections
                providesidentifierNode.appendChild(providesidentifierTextNode)
                findbyProvidesNode.appendChild(namingserviceProvidesNode)
                providesportNode.appendChild(providesidentifierNode)
                providesportNode.appendChild(findbyProvidesNode)
                connectinterfaceNode.appendChild(providesportNode)
                connectinterfaceNode.appendChild(usesportNode)

            else:
                findbyProvidesNode = doc_sad.createElement("findby")
                namingserviceProvidesNode = doc_sad.createElement("namingservice")
                namingserviceProvidesNode.setAttribute("name", dev_pname)

                # Make connections
                # TODO: validate this XML
                findbyProvidesNode.appendChild(namingserviceProvidesNode)
                connectinterfaceNode.appendChild(findbyProvidesNode)
                connectinterfaceNode.appendChild(usesportNode)

            # Append connectinterface to connections
            connectionsNode.appendChild(connectinterfaceNode)

        # Specify the uuid for the Assembly Controller
        if n.AssemblyController == True:
            assemblycontroller_id = u'DCE:' + unicode(n.instanceUUID)
            assemblycontrollerNode.getElementsByTagName("componentinstantiationref")[0].setAttribute("refid", assemblycontroller_id)

    # Create and beautify the SAD file as a temporary file
    data = doc_sad.toxml('UTF-8')
    xmlBeautify.beautify(data,waveformDir + '.' + outputFilename_sad + '.tmp')

    # Post Processing - add some of the header lines


    preProcessed_sad = open(waveformDir + '.' + outputFilename_sad + '.tmp', 'r')
    postProcessed_sad = open(waveformDir + outputFilename_sad, 'w')

    # Specify external DTD
    line0 = preProcessed_sad.readline()
    remaining = preProcessed_sad.readlines()
    postProcessed_sad.writelines(line0)
    postProcessed_sad.writelines(u'<!DOCTYPE softwareassembly SYSTEM \"../../xml/dtd/softwareassembly.dtd\">\n')
    postProcessed_sad.writelines(commentLine)
    postProcessed_sad.writelines(remaining)
    postProcessed_sad.close()

    # Remove temporary files
    os.remove(waveformDir + '.' + outputFilename_sad + '.tmp')
示例#3
0
def genDCD(devlist,
           path,
           wavedevPath,
           nodeName,
           dmName='DeviceManager',
           folder=False,
           generate=True,
           devconf=""):

    outputFilename_dcd = dmName + '.dcd.xml'

    doc_dcd = xml.dom.minidom.parse(wavedevPath +
                                    'XML_gen/templates/_dcd.xml.tpl')

    deviceconfigurationNode = doc_dcd.getElementsByTagName(
        "deviceconfiguration")[0]

    if devconf == "":
        deviceconfigurationNode.setAttribute(
            "id", u'DCE:' + unicode(uuidgen.uuidgen()))
    else:
        deviceconfigurationNode.setAttribute("id", unicode(devconf))

    deviceconfigurationNode.setAttribute("name",
                                         unicode(dmName + "_" + nodeName))

    devicemanagersoftpkgNode = deviceconfigurationNode.getElementsByTagName(
        "devicemanagersoftpkg")[0]
    devicemanagersoftpkgNode.getElementsByTagName("localfile")[0].setAttribute(
        "name", unicode('/nodes/' + nodeName + '/' + dmName + '.spd.xml'))

    baseDeviceList = []
    componentfilesNode = deviceconfigurationNode.getElementsByTagName(
        "componentfiles")[0]
    partitioningNode = deviceconfigurationNode.getElementsByTagName(
        "partitioning")[0]
    for n in devlist:
        if generate:
            tmpid = unicode(n.name) + u'_' + unicode(n.file_uuid)
        else:
            tmpid = unicode(n.file_uuid)

        if n.baseName not in baseDeviceList:
            # Generate the componentfile entries
            baseDeviceList.append(n.baseName)
            componentfileNode = doc_dcd.createElement("componentfile")
            componentfileNode.setAttribute("type", "SPD")
            componentfileNode.setAttribute("id", tmpid)

            localcomponentfileNode = doc_dcd.createElement("localfile")
            localcomponentfileNode.setAttribute(
                "name",
                unicode(xmlpath + n.baseName + '/' + n.baseName + '.spd.xml'))

            componentfileNode.appendChild(localcomponentfileNode)
            componentfilesNode.appendChild(componentfileNode)

        # Generate the partitioning entries
        componentplacementNode = doc_dcd.createElement("componentplacement")
        componentfilerefNode = doc_dcd.createElement("componentfileref")
        componentfilerefNode.setAttribute("refid", tmpid)
        componentinstantiationNode = doc_dcd.createElement(
            "componentinstantiation")
        componentinstantiationNode.setAttribute("id",
                                                u'DCE:' + unicode(n.uuid))
        usagenameNode = doc_dcd.createElement("usagename")
        usagenameTextNode = doc_dcd.createTextNode(n.name)

        # Append nodes to partitioning
        usagenameNode.appendChild(usagenameTextNode)
        componentinstantiationNode.appendChild(usagenameNode)
        componentplacementNode.appendChild(componentfilerefNode)
        componentplacementNode.appendChild(componentinstantiationNode)
        partitioningNode.appendChild(componentplacementNode)

    # Create and beautify the dcd file as a temporary file
    data = doc_dcd.toxml('UTF-8')
    xmlBeautify.beautify(data, path + '.' + outputFilename_dcd + '.tmp')
    # Create and beautify the dcd file as a temporary file
    data = doc_dcd.toxml('UTF-8')
    xmlBeautify.beautify(data, path + '.' + outputFilename_dcd + '.tmp')

    # Post Processing - add some of the header lines

    preProcessed_dcd = open(path + '.' + outputFilename_dcd + '.tmp', 'r')
    postProcessed_dcd = open(path + outputFilename_dcd, 'w')

    # Specify external DTD
    line0 = preProcessed_dcd.readline()
    remaining = preProcessed_dcd.readlines()
    postProcessed_dcd.writelines(line0)
    postProcessed_dcd.writelines(
        u'<!DOCTYPE deviceconfiguration SYSTEM \"../../xml/dtd/deviceconfiguration.dtd\">\n'
    )
    postProcessed_dcd.writelines(commentLine)
    postProcessed_dcd.writelines(remaining)
    postProcessed_dcd.close()

    # Remove temporary files
    os.remove(path + '.' + outputFilename_dcd + '.tmp')
示例#4
0
def gen_spd(comp, waveformDir, wavedevPath, isPyComp=False):
    componentName = unicode(comp.name)
    componentDescr = unicode(comp.description)

    doc_spd = xml.dom.minidom.parse(wavedevPath + '/XML_gen/templates/_spd.xml.tpl')

    #doc_spd.softpkg.name = u'ossie' + componentName + u'Resource'
    softpkgNode = doc_spd.getElementsByTagName("softpkg")[0]
    softpkgNode.setAttribute("name",componentName)
    softpkgNode.setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()) )

    # set the general resource description
    # note: this is NOT the description of the implementation
    for tmpNode in softpkgNode.childNodes:
        if tmpNode.nodeName == "description":
            tmpTextNode = doc_spd.createTextNode(componentDescr)
            tmpNode.appendChild(tmpTextNode)
            break

    # set the property file path
    propertyfilePathNode = softpkgNode.getElementsByTagName("propertyfile")[0].getElementsByTagName("localfile")[0]
    propertyfilePathNode.setAttribute("name", xmlpath + componentName  + '/' + componentName + u'.prf.xml')

    # set the descriptor file path
    descriptorPathNode = softpkgNode.getElementsByTagName("descriptor")[0].getElementsByTagName("localfile")[0]
    descriptorPathNode.setAttribute("name", xmlpath + componentName + '/' + componentName + u'.scd.xml')

    # set the implementation id
    # NOTE: this supports only one implementation
    implementationNode = softpkgNode.getElementsByTagName("implementation")[0]
    implementationNode.setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()) )
    if (isPyComp):
        #print "Gen spd fiel for python component " + componentName
        componentName = componentName + "/" + componentName + ".py"
    implementationNode.getElementsByTagName("code")[0].getElementsByTagName("localfile")[0].setAttribute( \
        "name", binpath + componentName)

    # Now do final processing and write to file
    compDir = waveformDir + comp.name + '/'
    outputFileName_spd = comp.name + '.spd.xml'
    #outputFileName_spd = comp.name + 'Resource' + '.spd.xml'

    data = doc_spd.toxml('UTF-8')
    xmlBeautify.beautify(data,compDir + '.' + outputFileName_spd + '.tmp')
    data = doc_spd.toxml('UTF-8')
    xmlBeautify.beautify(data,compDir + '.' + outputFileName_spd + '.tmp')


    preProcessed_spd = open(compDir + '.' + outputFileName_spd + '.tmp', 'r')
    postProcessed_spd = open(compDir + outputFileName_spd, 'w')

    # Specify external DTD
    line0 = preProcessed_spd.readline()
    remaining = preProcessed_spd.readlines()
    postProcessed_spd.writelines(line0)
    postProcessed_spd.writelines(u'<!DOCTYPE softpkg SYSTEM \"../dtd/softpkg.dtd\">\n')
    postProcessed_spd.writelines(commentLine)
    postProcessed_spd.writelines(remaining)
    postProcessed_spd.close()

    # Remove temporary files
    os.remove(compDir + '.' + outputFileName_spd + '.tmp')
示例#5
0
def genxml(complist, genPath, wavedevPath, waveName):
    if genPath[len(genPath) - 1] != '/':
        genPath = genPath + '/'
    genPath = unicode(genPath)
    if len(wavedevPath) > 0 and wavedevPath[len(wavedevPath) - 1] != '/':
        wavedevPath = wavedevPath + '/'
    waveformDir = unicode(genPath + waveName + '/')

    appName = unicode(waveName)
    #namingServicePrefix = u'ossie'
    outputFilename_sad = appName + u'.sad.xml'

    # Generate the individual component xml files
    for n in complist:
        if n.generate:
            component_gen.gen_scd(n, genPath, wavedevPath)
            component_gen.gen_spd(n, genPath, wavedevPath)
            component_gen.gen_prf(n, genPath, wavedevPath)

    #----------------------------------------------------------------------------
    # SAD Parser / Generator
    #

    # Use the minidom module to objectify and generate the SAD file
    try:  #if running from wavedev
        doc_sad = xml.dom.minidom.parse(wavedevPath +
                                        '/XML_gen/templates/_sad.xml.tpl')
    except:  #if not being called from wavedev, try looking for the file
        #doc_sad = xml.dom.minidom.parse('/sdr/tools/WaveDev/wavedev/XML_gen/_sad.xml.tpl')
        templates = __import__('WaveDev').__file__
        if os.path.islink(templates):
            templates = os.path.realpath(templates)
        templates = os.path.dirname(
            os.path.abspath(templates)) + '/wavedev/XML_gen/templates'
        doc_sad = xml.dom.minidom.parse(templates + '/_sad.xml.tpl')

    doc_sad.getElementsByTagName("softwareassembly")[0].setAttribute(
        "name", u'OSSIE::' + appName)
    doc_sad.getElementsByTagName("softwareassembly")[0].setAttribute(
        "id", u'DCE:' + unicode(uuidgen.uuidgen()))

    # get root nodes for componentfiles, partitioning, assemblycontroller, and connections tags
    componentfilesNode = doc_sad.getElementsByTagName("componentfiles")[0]
    partitioningNode = doc_sad.getElementsByTagName("partitioning")[0]
    assemblycontrollerNode = doc_sad.getElementsByTagName(
        "assemblycontroller")[0]
    connectionsNode = doc_sad.getElementsByTagName("connections")[0]

    baseComponentList = []
    for n in complist:
        # Generate the componentfile entries
        #tmpid = unicode(n.name) + u'_' + unicode(uuidgen.uuidgen())
        tmpid = unicode(n.baseName) + u'_' + unicode(n.file_uuid)

        if n.baseName not in baseComponentList:
            baseComponentList.append(n.baseName)

            # create component file tag node
            componentfileNode = doc_sad.createElement("componentfile")
            componentfileNode.setAttribute("type", "SPD")
            componentfileNode.setAttribute("id", tmpid)

            # create localfile tag node
            localfileNode = doc_sad.createElement("localfile")
            localfileNode.setAttribute(
                "name",
                unicode(xmlpath + n.baseName + '/' + n.xmlName + '.spd.xml'))

            # append nodes to .sad.xml file
            componentfileNode.appendChild(localfileNode)
            componentfilesNode.appendChild(componentfileNode)

        # Generate the partitioning elements
        componentplacementNode = doc_sad.createElement("componentplacement")
        componentfilerefNode = doc_sad.createElement("componentfileref")
        componentinstantiationNode = doc_sad.createElement(
            "componentinstantiation")
        usagenameNode = doc_sad.createElement("usagename")
        usagenameTextNode = doc_sad.createTextNode(unicode(n.name))
        usagenameNode.appendChild(usagenameTextNode)
        findcomponentNode = doc_sad.createElement("findcomponent")

        # Set attributes appropriately
        componentfilerefNode.setAttribute("refid", tmpid)
        n.instanceUUID = uuidgen.uuidgen()
        componentinstantiationNode.setAttribute(
            "id", u'DCE:' + unicode(n.instanceUUID))

        # Check for overloaded properties
        overload_flag = False
        for tmp_prop in n.properties:
            if tmp_prop.elementType == "Simple":
                if tmp_prop.value != tmp_prop.defaultValue:
                    overload_flag = True
            if tmp_prop.elementType == "SimpleSequence":
                try:
                    if tmp_prop.values != tmp_prop.defaultValues:
                        overload_flag = True
                except:
                    pass

        if overload_flag:
            componentpropertiesNode = doc_sad.createElement(
                "componentproperties")
            for tmp_prop in n.properties:
                if tmp_prop.elementType == "Simple":
                    if tmp_prop.value != tmp_prop.defaultValue:
                        simplerefNode = doc_sad.createElement("simpleref")
                        simplerefNode.setAttribute("refid",
                                                   unicode(tmp_prop.id))
                        simplerefNode.setAttribute("name",
                                                   unicode(tmp_prop.name))
                        simplerefNode.setAttribute(
                            "description", unicode(tmp_prop.description))
                        simplerefNode.setAttribute("value",
                                                   unicode(tmp_prop.value))
                        componentpropertiesNode.appendChild(simplerefNode)

                if tmp_prop.elementType == "SimpleSequence":
                    ssflag = False
                    try:
                        if tmp_prop.values != tmp_prop.defaultValues:
                            ssflag = True
                    except:
                        pass

                    if ssflag:
                        simplesequencerefNode = doc_sad.createElement(
                            "simplesequenceref")
                        simplesequencerefNode.setAttribute(
                            "refid", unicode(tmp_prop.id))
                        simplesequencerefNode.setAttribute(
                            "name", unicode(tmp_prop.name))
                        simplesequencerefNode.setAttribute(
                            "description", unicode(tmp_prop.description))
                        valuesNode = doc_sad.createElement("values")

                        for tmp_v2 in tmp_prop.values:
                            valueNode = doc_sad.createElement("value")
                            valuetextNode = doc_sad.createTextNode(tmp_v2)
                            valueNode.appendChild(valuetextNode)
                            valuesNode.appendChild(valueNode)

                        simplesequencerefNode.appendChild(valuesNode)
                        componentpropertiesNode.appendChild(
                            simplesequencerefNode)

            # if there are overloaded properties, add to .sad.xml file
            componentinstantiationNode.appendChild(componentpropertiesNode)

        #NSname = u'DomainName1/' + namingServicePrefix + unicode(n.name) + u'Resource'
#        NSname = u'DomainName1/' + unicode(n.name)
        NSname = unicode(n.name)

        namingserviceNode = doc_sad.createElement("namingservice")
        namingserviceNode.setAttribute("name", NSname)
        findcomponentNode.appendChild(namingserviceNode)

        #TODO: append child nodes to componentplacement
        componentinstantiationNode.appendChild(usagenameNode)
        componentinstantiationNode.appendChild(findcomponentNode)
        componentplacementNode.appendChild(componentfilerefNode)
        componentplacementNode.appendChild(componentinstantiationNode)

        partitioningNode.appendChild(componentplacementNode)

        # Generate the connections entries
        for i in n.connections:
            cname = unicode(n.name)
            devFlag = False

            #            print "Processing connection : "
            #            print "  component name  : " + cname
            #            print "  local comp type : " + n.type
            #            print "  local port type : " + i.localPort.type
            #            print "  local port name : " + unicode(i.localPort.name)
            #            print "  remote comp type: " + i.remoteComp.type
            #            print "  remote port type: " + i.remotePort.type
            #            print "  remote port name: " + unicode(i.remotePort.name)

            if i.localPort.type == 'Uses':
                uname = unicode(i.localPort.name)
                pname = unicode(i.remotePort.name)
                #                c1name = u'DomainName1/' + cname
                #                c2name = u'DomainName1/' + unicode(i.remoteComp.name)
                c1name = cname
                c2name = unicode(i.remoteComp.name)
                if i.remoteComp.type.lower() == "device" \
                or i.remoteComp.type.lower() == "executabledevice" \
                or i.remoteComp.type.lower() == "aggregatedevice":
                    dev_pname = u'DomainName1/' + pname
                    devFlag = True
            else:
                pname = unicode(i.localPort.name)
                uname = unicode(i.remotePort.name)
                #               c2name = u'DomainName1/' + cname
                #               c1name = u'DomainName1/' + unicode(i.remoteComp.name)
                c2name = cname
                c1name = unicode(i.remoteComp.name)
                if n.type.lower() == "device" \
                or n.type.lower() == "executabledevice" \
                or n.type.lower() == "aggregatedevice":
                    dev_pname = u'DomainName1/' + pname
                    devFlag = True

            connectinterfaceNode = doc_sad.createElement("connectinterface")
            connectinterfaceNode.setAttribute(
                "id", u'DCE:' + unicode(uuidgen.uuidgen()))

            usesportNode = doc_sad.createElement("usesport")
            usesidentifierNode = doc_sad.createElement("usesidentifier")
            usesidentifierTextNode = doc_sad.createTextNode(uname)
            findbyUsesNode = doc_sad.createElement("findby")
            namingserviceUsesNode = doc_sad.createElement("namingservice")
            # TODO: this is a dirty hack that needs to be fixed!
            if c1name == "USRP1":
                c1name = "DomainName1/USRP1"
            namingserviceUsesNode.setAttribute("name", c1name)

            # Append child nodes
            usesidentifierNode.appendChild(usesidentifierTextNode)
            findbyUsesNode.appendChild(namingserviceUsesNode)
            usesportNode.appendChild(usesidentifierNode)
            usesportNode.appendChild(findbyUsesNode)

            if devFlag != True:
                providesportNode = doc_sad.createElement("providesport")
                providesidentifierNode = doc_sad.createElement(
                    "providesidentifier")
                providesidentifierTextNode = doc_sad.createTextNode(pname)
                findbyProvidesNode = doc_sad.createElement("findby")
                namingserviceProvidesNode = doc_sad.createElement(
                    "namingservice")
                namingserviceProvidesNode.setAttribute("name", c2name)

                # Make connections
                providesidentifierNode.appendChild(providesidentifierTextNode)
                findbyProvidesNode.appendChild(namingserviceProvidesNode)
                providesportNode.appendChild(providesidentifierNode)
                providesportNode.appendChild(findbyProvidesNode)
                connectinterfaceNode.appendChild(providesportNode)
                connectinterfaceNode.appendChild(usesportNode)

            else:
                findbyProvidesNode = doc_sad.createElement("findby")
                namingserviceProvidesNode = doc_sad.createElement(
                    "namingservice")
                namingserviceProvidesNode.setAttribute("name", dev_pname)

                # Make connections
                # TODO: validate this XML
                findbyProvidesNode.appendChild(namingserviceProvidesNode)
                connectinterfaceNode.appendChild(findbyProvidesNode)
                connectinterfaceNode.appendChild(usesportNode)

            # Append connectinterface to connections
            connectionsNode.appendChild(connectinterfaceNode)

        # Specify the uuid for the Assembly Controller
        if n.AssemblyController == True:
            assemblycontroller_id = u'DCE:' + unicode(n.instanceUUID)
            assemblycontrollerNode.getElementsByTagName(
                "componentinstantiationref")[0].setAttribute(
                    "refid", assemblycontroller_id)

    # Create and beautify the SAD file as a temporary file
    data = doc_sad.toxml('UTF-8')
    xmlBeautify.beautify(data, waveformDir + '.' + outputFilename_sad + '.tmp')

    # Post Processing - add some of the header lines

    preProcessed_sad = open(waveformDir + '.' + outputFilename_sad + '.tmp',
                            'r')
    postProcessed_sad = open(waveformDir + outputFilename_sad, 'w')

    # Specify external DTD
    line0 = preProcessed_sad.readline()
    remaining = preProcessed_sad.readlines()
    postProcessed_sad.writelines(line0)
    postProcessed_sad.writelines(
        u'<!DOCTYPE softwareassembly SYSTEM \"../../xml/dtd/softwareassembly.dtd\">\n'
    )
    postProcessed_sad.writelines(commentLine)
    postProcessed_sad.writelines(remaining)
    postProcessed_sad.close()

    # Remove temporary files
    os.remove(waveformDir + '.' + outputFilename_sad + '.tmp')