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
Line 
1## Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
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
20
21import xml.dom.minidom
22from xml.dom.minidom import Node
23from importResource import getSimpleProperty, getSimpleSequenceProperty
24
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):
35
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
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)
55
56    #
57    # Build the node from the DCD
58    #
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)")
63        return None
64
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")
71
72    #
73    componentplacementNodeList = doc_dcd.getElementsByTagName("componentplacement")
74    for componentplacementNode in componentplacementNodeList:
75        newComp = CC.Component(type='executabledevice')
76        newComp.name = componentplacementNode.getElementsByTagName("usagename")[0].firstChild.data
77
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
87        local_SPD = ""
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
94                break
95        pathSPD = parent.installPath + "dev/" + local_SPD
96        if not os.path.exists(pathSPD):
97            errorMsg(parent, "Warning! Could not find " + pathSPD + ".\nCannot import node " + Nname)
98            return None
99
100        doc_spd = xml.dom.minidom.parse(pathSPD)
101        softpkgNode = doc_spd.getElementsByTagName("softpkg")[0]
102        newComp.baseName = softpkgNode.getAttribute("name")
103        #pathSCD = "/sdr/sca/xml/"+newComp.baseName+"/"+doc_spd.softpkg.descriptor.localfile.name
104        localfileNode = softpkgNode.getElementsByTagName("localfile")[0]
105        pathSCD = parent.installPath + "dev"  + localfileNode.getAttribute("name")
106
107        doc_scd = xml.dom.minidom.parse(pathSCD)
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       
118        # Get the Ports
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:
129                errorMsg(parent, "No repid found in ProvidesPort")
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:
141                errorMsg(parent, "No repid fond in UsesPort")
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)
147
148        # Make sure that xml and code are not generated for this resource
149        newComp.generate = False
150
151        # Store the name of the file without the suffix (.scd.xml)
152        newComp.xmlName =  os.path.splitext(os.path.splitext(os.path.basename(pathSCD))[0])[0]
153
154        newNode.Devices.append(newComp)
155
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)
174        #            continue
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)
182        #            continue
183        #        newComp.properties.append(p)
184
185    return newNode
186
187
188
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
197
198    except:
199        errorMsg(parent,"Can't read the Interface information for port: " + name)
200        return None
201
202
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):
208        tmpf = path + '/' + Rname + suf
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):
218    """Strips out the DOCTYPE checking because the dtd files are positioned
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."""
222
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.