root/ossiedev/trunk/tools/WaveDev/wavedev/importNode.py @ 10753

Revision 10753, 9.2 KB (checked in by Snyder.Jason, 2 years ago)

modified importNode to assign the correct component type to each component in a node. previously, all were executabledevices by default

  • Property svn:eol-style set to native
RevLine 
[5886]1## Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
[3013]2##
3## This file is part of the OSSIE Waveform Developer.
4##
5## OSSIE Waveform Developer is free software; you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 2 of the License, or
8## (at your option) any later version.
9##
10## OSSIE Waveform Developer is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with OSSIE Waveform Developer; if not, write to the Free Software
17## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19import os, sys
[4275]20
21import xml.dom.minidom
22from xml.dom.minidom import Node
23from importResource import getSimpleProperty, getSimpleSequenceProperty
24
[3013]25import ComponentClass as CC
26from errorMsg import *
27
28availableTypes = ["boolean", "char", "double", "float", "short", "long",
29                    "objref", "octet", "string", "ulong","ushort"]
30availableKinds = ["allocation", "configure", "test", "execparam", "factoryparam"]
31availableActions = ["eq", "ne", "gt", "lt", "ge", "le", "external"]
32availableModes = ["readonly", "readwrite", "writeonly"]
33
34def getNode(inpath,Nname,parent):
[4275]35
[8046]36    scdPath = inpath + "DeviceManager" + ".scd.xml"
37    spdPath = inpath + "DeviceManager" + ".spd.xml"
38    prfPath = inpath + "DeviceManager" + ".prf.xml"
39    dcdPath = inpath + "DeviceManager" + ".dcd.xml"
40
[4321]41    # import the node description from the node's .spd.xml file
42    doc_node_spd = xml.dom.minidom.parse(spdPath)
43    softpkgNode = doc_node_spd.getElementsByTagName("softpkg")[0]
44    Ndescription = ''
45    for n in softpkgNode.childNodes:
46        if n.nodeName == "description":
47            nDescriptionNode = doc_node_spd.getElementsByTagName("description")
48            try:
49                Ndescription = nDescriptionNode[0].firstChild.data
50            except:
51                pass
52            break
53
54    newNode = CC.Node(name=Nname, path=inpath, description=Ndescription, generate=False)
[8046]55
[3013]56    #
[8046]57    # Build the node from the DCD
[3013]58    #
[4275]59    doc_dcd = xml.dom.minidom.parse(dcdPath)
60    partitioningNodeList = doc_dcd.getElementsByTagName('partitioning')
61    if len(partitioningNodeList) != 1:
62        errorMsg(parent,"Invalid file: " + dcdPath + " (partitioning)")
[3013]63        return None
[8046]64
[4275]65    try:
66        deviceconfigurationNode = doc_dcd.getElementsByTagName('deviceconfiguration')[0]
67    except:
68        errorMsg(parent,"Invalid file: " + dcdPath + " (deviceconfiguration)")
69        return None
70    newNode.id = deviceconfigurationNode.getAttribute("id")
[8046]71
72    #
[4275]73    componentplacementNodeList = doc_dcd.getElementsByTagName("componentplacement")
74    for componentplacementNode in componentplacementNodeList:
[3013]75        newComp = CC.Component(type='executabledevice')
[4275]76        newComp.name = componentplacementNode.getElementsByTagName("usagename")[0].firstChild.data
[3316]77
[4275]78        # componentinstantiation
79        # strip off the DCE: part of the id becuase it will get added back in later
80        tmpUUID = componentplacementNode.getElementsByTagName("componentinstantiation")[0].getAttribute("id")
81        newComp.uuid = str( tmpUUID ).strip("DCE:")
82
83        # componentfileref
84        tmpNode = componentplacementNode.getElementsByTagName("componentfileref")
85        newComp.file_uuid = str( tmpNode[0].getAttribute("refid") ).strip("DCE:") # is this strip necessary?  -JDG
86
[3348]87        local_SPD = ""
[4275]88        componentfileNodeList = doc_dcd.getElementsByTagName("componentfile")
89        for componentfileNode in componentfileNodeList:
90            if componentfileNode.getAttribute("id") == newComp.file_uuid:
91                localfileNodeList = componentfileNode.getElementsByTagName("localfile")
92                local_SPD = localfileNodeList[0].getAttribute("name")
93                del localfileNodeList
[3013]94                break
[9580]95        pathSPD = parent.installPath + "dev/" + local_SPD
[5426]96        if not os.path.exists(pathSPD):
97            errorMsg(parent, "Warning! Could not find " + pathSPD + ".\nCannot import node " + Nname)
98            return None
99
[4275]100        doc_spd = xml.dom.minidom.parse(pathSPD)
101        softpkgNode = doc_spd.getElementsByTagName("softpkg")[0]
102        newComp.baseName = softpkgNode.getAttribute("name")
[3013]103        #pathSCD = "/sdr/sca/xml/"+newComp.baseName+"/"+doc_spd.softpkg.descriptor.localfile.name
[4275]104        localfileNode = softpkgNode.getElementsByTagName("localfile")[0]
[9580]105        pathSCD = parent.installPath + "dev"  + localfileNode.getAttribute("name")
[4275]106
107        doc_scd = xml.dom.minidom.parse(pathSCD)
[10753]108       
109        #The new component is first created as an executable
110        #device but that may not be true
111        #grab the componenttype node from the scd file...
112        typeNode = doc_scd.getElementsByTagName("componenttype")
113        #... the pull out the actual value...
114        compType = typeNode[0].firstChild.toxml()
115        #... and assign it to the component
116        newComp.type = compType
117       
[3013]118        # Get the Ports
[4275]119        portsNodes = doc_scd.getElementsByTagName("ports")
120        for node in portsNodes:
121            providesPortsNodes = node.getElementsByTagName("provides")
122            usesPortsNodes = node.getElementsByTagName("uses")
123
124        # Provides ports
125        for node in providesPortsNodes:
126            tmpName = node.getAttribute("providesname")
127            tmpInt = getInterface( node.getAttribute("repid"), tmpName )
128            if tmpInt == None:
[9580]129                errorMsg(parent, "No repid found in ProvidesPort")
[4275]130                return None
131            portTypeNodeList = node.getElementsByTagName("porttype")
132            tmpType = portTypeNodeList[0].getAttribute("type")
133            newPort = CC.Port(tmpName,tmpInt,type='Provides',portType=tmpType)
134            newComp.ports.append(newPort)
135
136        # Uses ports
137        for node in usesPortsNodes:
138            tmpName = node.getAttribute("usesname")
139            tmpInt = getInterface( node.getAttribute("repid"), tmpName )
140            if tmpInt == None:
[9580]141                errorMsg(parent, "No repid fond in UsesPort")
[4275]142                return None
143            portTypeNodeList = node.getElementsByTagName("porttype")
144            tmpType = portTypeNodeList[0].getAttribute("type")
145            newPort = CC.Port(tmpName,tmpInt,type='Uses',portType=tmpType)
146            newComp.ports.append(newPort)
[8046]147
[3013]148        # Make sure that xml and code are not generated for this resource
[8046]149        newComp.generate = False
150
[3013]151        # Store the name of the file without the suffix (.scd.xml)
[4275]152        newComp.xmlName =  os.path.splitext(os.path.splitext(os.path.basename(pathSCD))[0])[0]
[8046]153
[3013]154        newNode.Devices.append(newComp)
[8046]155
[3013]156        #
157        # Import the properties from the PRF file
158        #
159        # If there are no properties, just return the component as is
160        #if pathPRF == None:
161        #    return newComp
162        #
163        #doc_prf = amara.parse(stripDoctype(prfPath))
164        ##doc_prf = binderytools.bind_file(prfPath)
165        #if not hasattr(doc_prf,'properties'):
166        #    errorMsg(parent,"Invalid file: " + prfPath)
167        #    return None
168        #
169        #if hasattr(doc_prf.properties,"simple"):
170        #    for s in doc_prf.properties.simple:
171        #        p = getSimpleProperty(s)
172        #        if p == None:
173        #            #errorMsg(parent,"Invalid file: " + prfPath)
[8046]174        #            continue
[3013]175        #        newComp.properties.append(p)
176        #
177        #if hasattr(doc_prf.properties,"simplesequence"):
178        #    for s in doc_prf.properties.simplesequence:
179        #        p = getSimpleSequenceProperty(s)
180        #        if p == None:
181        #            #errorMsg(parent,"Invalid file: " + prfPath)
[8046]182        #            continue
[3013]183        #        newComp.properties.append(p)
[8046]184
[3013]185    return newNode
186
[8046]187
188
[3013]189def getInterface(repid,name):
190    try:
191        repid = repid.strip('IDL:')
192        repid = repid[:repid.rfind(':')]
193        tmpNS = repid[:repid.find('/')]
194        tmpName = repid[repid.find('/')+1:]
195        newInt = CC.Interface(tmpName,nameSpace=tmpNS)
196        return newInt
[8046]197
[3013]198    except:
199        errorMsg(parent,"Can't read the Interface information for port: " + name)
200        return None
[8046]201
202
[3013]203def findFile(path,Rname,suf):
204    tmpf = None
205    if os.path.isfile(path + '/' + Rname +'Resource'+suf):
206        tmpf = path + '/' + Rname +'Resource' + suf
207    elif os.path.isfile(path + '/' + Rname + suf):
[8046]208        tmpf = path + '/' + Rname + suf
[3013]209    else:
210        tmpFiles = os.listdir(path)
211        for f in tmpFiles:
212            if len(f)>=8 and f[-8:] == suf:
213                tmpf = path + '/' + f
214                break
215    return tmpf
216
217def stripDoctype(xmlfile):
[8046]218    """Strips out the DOCTYPE checking because the dtd files are positioned
[3013]219       in a relative location to the SCA (OSSIE) filesystem, so when Amara
220       trys to validate against them, it bails out looking for the file.
221       Returns a string representation of the xml file without the DOCTYPE line."""
[8046]222
[3013]223    file = open(xmlfile, 'r')
224    xml = ''
225    line = file.readline()
226    while len(line) > 0:
227        if "DOCTYPE" in line:
228            break
229        xml += line
230        line = file.readline()
231    xml += file.read()
232
233    return xml
234
Note: See TracBrowser for help on using the browser.