| 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 | |
|---|
| 19 | import sys |
|---|
| 20 | import commands |
|---|
| 21 | import os, copy |
|---|
| 22 | import shutil |
|---|
| 23 | |
|---|
| 24 | import xml.dom.minidom |
|---|
| 25 | from xml.dom.minidom import Node |
|---|
| 26 | |
|---|
| 27 | import xmlBeautify |
|---|
| 28 | import WaveDev.wavedev.uuidgen as uuidgen |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | xmlpath = u'/xml/' |
|---|
| 33 | binpath = u'/bin/' |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | commentLine = u'<!--Created with OSSIE WaveDev-->\n<!--Powered by Python-->\n' |
|---|
| 37 | |
|---|
| 38 | def gen_scd(comp, waveformDir, wavedevPath): |
|---|
| 39 | # Generate the componentfile entries |
|---|
| 40 | doc_scd = xml.dom.minidom.parse(wavedevPath + '/XML_gen/templates/_scd.xml.tpl') |
|---|
| 41 | |
|---|
| 42 | int_types = {} |
|---|
| 43 | |
|---|
| 44 | portsNode = doc_scd.getElementsByTagName("ports")[0] |
|---|
| 45 | |
|---|
| 46 | # add provides ports to .scd.xml file |
|---|
| 47 | for p in comp.ports: |
|---|
| 48 | if p.type == "Provides": |
|---|
| 49 | # create node for <provides> tag |
|---|
| 50 | tmp_repid = u'IDL:' + unicode(p.interface.nameSpace) + u'/' + unicode(p.interface.name) + u':1.0' |
|---|
| 51 | providesPortNode = doc_scd.createElement("provides") |
|---|
| 52 | providesPortNode.setAttribute("repid", tmp_repid) |
|---|
| 53 | providesPortNode.setAttribute("providesname", unicode(p.name)) |
|---|
| 54 | |
|---|
| 55 | # create node for <porttype/> tag |
|---|
| 56 | portTypeNode = doc_scd.createElement("porttype") |
|---|
| 57 | portTypeNode.setAttribute("type", unicode(p.portType)) |
|---|
| 58 | providesPortNode.appendChild(portTypeNode) |
|---|
| 59 | |
|---|
| 60 | # append new provides port to <ports> |
|---|
| 61 | portsNode.appendChild(providesPortNode) |
|---|
| 62 | |
|---|
| 63 | if p.interface.name not in int_types: |
|---|
| 64 | int_types[p.interface.name] = copy.deepcopy(p.interface) |
|---|
| 65 | |
|---|
| 66 | del providesPortNode, portTypeNode |
|---|
| 67 | |
|---|
| 68 | # add uses ports to .scd.xml file |
|---|
| 69 | for p in comp.ports: |
|---|
| 70 | if p.type == "Uses": |
|---|
| 71 | # create node for <uses> tag |
|---|
| 72 | tmp_repid = u'IDL:' + unicode(p.interface.nameSpace) + u'/' + unicode(p.interface.name) + u':1.0' |
|---|
| 73 | usesPortNode = doc_scd.createElement("uses") |
|---|
| 74 | usesPortNode.setAttribute("repid", tmp_repid) |
|---|
| 75 | usesPortNode.setAttribute("usesname", unicode(p.name)) |
|---|
| 76 | |
|---|
| 77 | # create node for <porttype/> tag |
|---|
| 78 | portTypeNode = doc_scd.createElement("porttype") |
|---|
| 79 | portTypeNode.setAttribute("type", unicode(p.portType)) |
|---|
| 80 | usesPortNode.appendChild(portTypeNode) |
|---|
| 81 | |
|---|
| 82 | # append new uses port to <ports> |
|---|
| 83 | portsNode.appendChild(usesPortNode) |
|---|
| 84 | |
|---|
| 85 | if p.interface.name not in int_types: |
|---|
| 86 | int_types[p.interface.name] = copy.deepcopy(p.interface) |
|---|
| 87 | |
|---|
| 88 | del usesPortNode, portTypeNode |
|---|
| 89 | |
|---|
| 90 | # Add interfaces |
|---|
| 91 | interfacesRootNode = doc_scd.getElementsByTagName("softwarecomponent")[0].getElementsByTagName("interfaces")[0] |
|---|
| 92 | for i in int_types.values(): |
|---|
| 93 | tmp_repid = u'IDL:' + unicode(i.nameSpace) + u'/' + unicode(i.name) + u':1.0' |
|---|
| 94 | interfaceNode = doc_scd.createElement("interface") |
|---|
| 95 | interfaceNode.setAttribute("repid", tmp_repid) |
|---|
| 96 | interfaceNode.setAttribute("name", unicode(i.name)) |
|---|
| 97 | interfacesRootNode.appendChild(interfaceNode) |
|---|
| 98 | del interfacesRootNode |
|---|
| 99 | |
|---|
| 100 | # Now do final processing and write to file |
|---|
| 101 | compDir = waveformDir + comp.name + '/' |
|---|
| 102 | outputFileName_scd = comp.name + '.scd.xml' |
|---|
| 103 | |
|---|
| 104 | data = doc_scd.toxml('UTF-8') |
|---|
| 105 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_scd + '.tmp') |
|---|
| 106 | |
|---|
| 107 | preProcessed_scd = open(compDir + '.' + outputFileName_scd + '.tmp', 'r') |
|---|
| 108 | postProcessed_scd = open(compDir + outputFileName_scd, 'w') |
|---|
| 109 | |
|---|
| 110 | # Specify external DTD |
|---|
| 111 | line0 = preProcessed_scd.readline() |
|---|
| 112 | remaining = preProcessed_scd.readlines() |
|---|
| 113 | postProcessed_scd.writelines(line0) |
|---|
| 114 | #postProcessed_scd.writelines(u'<!DOCTYPE softwarecomponent SYSTEM \"../../dtd/softwarecomponent.dtd\">\n') |
|---|
| 115 | postProcessed_scd.writelines(commentLine) |
|---|
| 116 | postProcessed_scd.writelines(remaining) |
|---|
| 117 | postProcessed_scd.close() |
|---|
| 118 | |
|---|
| 119 | # Remove temporary files |
|---|
| 120 | os.remove(compDir + '.' + outputFileName_scd + '.tmp') |
|---|
| 121 | data = doc_scd.toxml('UTF-8') |
|---|
| 122 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_scd + '.tmp') |
|---|
| 123 | |
|---|
| 124 | preProcessed_scd = open(compDir + '.' + outputFileName_scd + '.tmp', 'r') |
|---|
| 125 | postProcessed_scd = open(compDir + outputFileName_scd, 'w') |
|---|
| 126 | |
|---|
| 127 | # Specify external DTD |
|---|
| 128 | line0 = preProcessed_scd.readline() |
|---|
| 129 | remaining = preProcessed_scd.readlines() |
|---|
| 130 | postProcessed_scd.writelines(line0) |
|---|
| 131 | postProcessed_scd.writelines(u'<!DOCTYPE softwarecomponent SYSTEM \"../dtd/softwarecomponent.dtd\">\n') |
|---|
| 132 | postProcessed_scd.writelines(commentLine) |
|---|
| 133 | postProcessed_scd.writelines(remaining) |
|---|
| 134 | postProcessed_scd.close() |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | # Remove temporary files |
|---|
| 138 | os.remove(compDir + '.' + outputFileName_scd + '.tmp') |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | def gen_spd(comp, waveformDir, wavedevPath): |
|---|
| 143 | componentName = unicode(comp.name) |
|---|
| 144 | componentDescr = unicode(comp.description) |
|---|
| 145 | |
|---|
| 146 | doc_spd = xml.dom.minidom.parse(wavedevPath + '/XML_gen/templates/_spd.xml.tpl') |
|---|
| 147 | |
|---|
| 148 | #doc_spd.softpkg.name = u'ossie' + componentName + u'Resource' |
|---|
| 149 | softpkgNode = doc_spd.getElementsByTagName("softpkg")[0] |
|---|
| 150 | softpkgNode.setAttribute("name",componentName) |
|---|
| 151 | softpkgNode.setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()) ) |
|---|
| 152 | |
|---|
| 153 | # set the general resource description |
|---|
| 154 | # note: this is NOT the description of the implementation |
|---|
| 155 | for tmpNode in softpkgNode.childNodes: |
|---|
| 156 | if tmpNode.nodeName == "description": |
|---|
| 157 | tmpTextNode = doc_spd.createTextNode(componentDescr) |
|---|
| 158 | tmpNode.appendChild(tmpTextNode) |
|---|
| 159 | break |
|---|
| 160 | |
|---|
| 161 | # set the property file path |
|---|
| 162 | propertyfilePathNode = softpkgNode.getElementsByTagName("propertyfile")[0].getElementsByTagName("localfile")[0] |
|---|
| 163 | propertyfilePathNode.setAttribute("name", xmlpath + componentName + '/' + componentName + u'.prf.xml') |
|---|
| 164 | |
|---|
| 165 | # set the descriptor file path |
|---|
| 166 | descriptorPathNode = softpkgNode.getElementsByTagName("descriptor")[0].getElementsByTagName("localfile")[0] |
|---|
| 167 | descriptorPathNode.setAttribute("name", xmlpath + componentName + '/' + componentName + u'.scd.xml') |
|---|
| 168 | |
|---|
| 169 | # set the implementation id |
|---|
| 170 | implementationNode = softpkgNode.getElementsByTagName("implementation")[0] |
|---|
| 171 | implementationNode.setAttribute("id", u'DCE:' + unicode(uuidgen.uuidgen()) ) |
|---|
| 172 | implementationNode.getElementsByTagName("code")[0].getElementsByTagName("localfile")[0].setAttribute( \ |
|---|
| 173 | "name", binpath + componentName) |
|---|
| 174 | |
|---|
| 175 | # Now do final processing and write to file |
|---|
| 176 | compDir = waveformDir + comp.name + '/' |
|---|
| 177 | outputFileName_spd = comp.name + '.spd.xml' |
|---|
| 178 | #outputFileName_spd = comp.name + 'Resource' + '.spd.xml' |
|---|
| 179 | |
|---|
| 180 | data = doc_spd.toxml('UTF-8') |
|---|
| 181 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_spd + '.tmp') |
|---|
| 182 | data = doc_spd.toxml('UTF-8') |
|---|
| 183 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_spd + '.tmp') |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | preProcessed_spd = open(compDir + '.' + outputFileName_spd + '.tmp', 'r') |
|---|
| 187 | postProcessed_spd = open(compDir + outputFileName_spd, 'w') |
|---|
| 188 | |
|---|
| 189 | # Specify external DTD |
|---|
| 190 | line0 = preProcessed_spd.readline() |
|---|
| 191 | remaining = preProcessed_spd.readlines() |
|---|
| 192 | postProcessed_spd.writelines(line0) |
|---|
| 193 | postProcessed_spd.writelines(u'<!DOCTYPE softpkg SYSTEM \"../dtd/softpkg.dtd\">\n') |
|---|
| 194 | postProcessed_spd.writelines(commentLine) |
|---|
| 195 | postProcessed_spd.writelines(remaining) |
|---|
| 196 | postProcessed_spd.close() |
|---|
| 197 | |
|---|
| 198 | # Remove temporary files |
|---|
| 199 | os.remove(compDir + '.' + outputFileName_spd + '.tmp') |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | def gen_prf(comp, waveformDir, wavedevPath): |
|---|
| 203 | componentName = unicode(comp.name) |
|---|
| 204 | doc_prf = xml.dom.minidom.parse(wavedevPath + '/XML_gen/templates/_prf.xml.tpl') |
|---|
| 205 | |
|---|
| 206 | propertiesNode = doc_prf.getElementsByTagName("properties")[0] |
|---|
| 207 | |
|---|
| 208 | for p in comp.properties: |
|---|
| 209 | if p.elementType == "Simple": |
|---|
| 210 | e = doc_prf.createElement("simple") |
|---|
| 211 | |
|---|
| 212 | # Add the property value |
|---|
| 213 | valueNode = doc_prf.createElement("value") |
|---|
| 214 | valueText = doc_prf.createTextNode(unicode(p.value)) |
|---|
| 215 | valueNode.appendChild(valueText) |
|---|
| 216 | |
|---|
| 217 | e.appendChild(valueNode) |
|---|
| 218 | |
|---|
| 219 | elif p.elementType == "SimpleSequence": |
|---|
| 220 | e = doc_prf.createElement("simplesequence") |
|---|
| 221 | |
|---|
| 222 | # Add the property values |
|---|
| 223 | valuesNode = doc_prf.createElement("values") |
|---|
| 224 | for x in p.values: |
|---|
| 225 | valueNode = doc_prf.createElement("value") |
|---|
| 226 | valueText = doc_prf.createTextNode(x[0]) |
|---|
| 227 | valueNode.appendChild(valueText) |
|---|
| 228 | valuesNode.appendChild(valueNode) |
|---|
| 229 | |
|---|
| 230 | e.appendChild(valuesNode) |
|---|
| 231 | |
|---|
| 232 | e.setAttribute("type", unicode(p.type)) |
|---|
| 233 | e.setAttribute("id", unicode(p.id)) |
|---|
| 234 | e.setAttribute("name", unicode(p.name)) |
|---|
| 235 | e.setAttribute("mode", unicode(p.mode)) |
|---|
| 236 | |
|---|
| 237 | # Add the property description |
|---|
| 238 | descriptionNode = doc_prf.createElement("description") |
|---|
| 239 | descriptionText = doc_prf.createTextNode(unicode(p.description)) |
|---|
| 240 | descriptionNode.appendChild(descriptionText) |
|---|
| 241 | e.appendChild(descriptionNode) |
|---|
| 242 | |
|---|
| 243 | # Add the property kind |
|---|
| 244 | kindNode = doc_prf.createElement("kind") |
|---|
| 245 | kindNode.setAttribute("kindtype", unicode(p.kind)) |
|---|
| 246 | e.appendChild(kindNode) |
|---|
| 247 | |
|---|
| 248 | propertiesNode.appendChild(e) |
|---|
| 249 | |
|---|
| 250 | # Create a simplesequence of string type that lists each Provides port in the component |
|---|
| 251 | # Used for connecting to components from outside the framework (ex. control gui) |
|---|
| 252 | providesFlag = False |
|---|
| 253 | for p in comp.ports: |
|---|
| 254 | if p.type == "Provides": |
|---|
| 255 | providesFlag = True |
|---|
| 256 | if providesFlag: |
|---|
| 257 | e = doc_prf.createElement("simplesequence") |
|---|
| 258 | e.setAttribute("name", "port_list") |
|---|
| 259 | e.setAttribute("id", "port_list") |
|---|
| 260 | e.setAttribute("type", "string") |
|---|
| 261 | e.setAttribute("mode", "readonly") |
|---|
| 262 | |
|---|
| 263 | # create description |
|---|
| 264 | ts = 'Returns a sequence of strings with the names of the available Provides ports' |
|---|
| 265 | descriptionNode = doc_prf.createElement("description") |
|---|
| 266 | descriptionText = doc_prf.createTextNode(unicode(ts)) |
|---|
| 267 | descriptionNode.appendChild(descriptionText) |
|---|
| 268 | e.appendChild(descriptionNode) |
|---|
| 269 | |
|---|
| 270 | # create kind |
|---|
| 271 | kindNode = doc_prf.createElement("kind") |
|---|
| 272 | kindNode.setAttribute("kindtype","configure") |
|---|
| 273 | e.appendChild(kindNode) |
|---|
| 274 | |
|---|
| 275 | valuesNode = doc_prf.createElement("values") |
|---|
| 276 | for p in comp.ports: |
|---|
| 277 | if p.type == "Uses": |
|---|
| 278 | continue |
|---|
| 279 | ts = p.name + "::" + p.interface.nameSpace + "." + p.interface.name |
|---|
| 280 | valueNode = doc_prf.createElement("value") |
|---|
| 281 | valueText = doc_prf.createTextNode(unicode(ts)) |
|---|
| 282 | valueNode.appendChild(valueText) |
|---|
| 283 | valuesNode.appendChild(valueNode) |
|---|
| 284 | |
|---|
| 285 | e.appendChild(valuesNode) |
|---|
| 286 | |
|---|
| 287 | propertiesNode.appendChild(e) |
|---|
| 288 | |
|---|
| 289 | # Now do final processing and write to file |
|---|
| 290 | compDir = waveformDir + comp.name + '/' |
|---|
| 291 | outputFileName_prf = comp.name + '.prf.xml' |
|---|
| 292 | #outputFileName_prf = comp.name + 'Resource' + '.prf.xml' |
|---|
| 293 | |
|---|
| 294 | data = doc_prf.toxml('UTF-8') |
|---|
| 295 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_prf + '.tmp') |
|---|
| 296 | data = doc_prf.toxml('UTF-8') |
|---|
| 297 | xmlBeautify.beautify(data,compDir + '.' + outputFileName_prf + '.tmp') |
|---|
| 298 | |
|---|
| 299 | preProcessed_prf = open(compDir + '.' + outputFileName_prf + '.tmp', 'r') |
|---|
| 300 | postProcessed_prf = open(compDir + outputFileName_prf, 'w') |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | # Specify external DTD |
|---|
| 304 | line0 = preProcessed_prf.readline() |
|---|
| 305 | remaining = preProcessed_prf.readlines() |
|---|
| 306 | postProcessed_prf.writelines(line0) |
|---|
| 307 | postProcessed_prf.writelines(u'<!DOCTYPE properties SYSTEM \"../dtd/properties.dtd\">\n') |
|---|
| 308 | postProcessed_prf.writelines(commentLine) |
|---|
| 309 | postProcessed_prf.writelines(remaining) |
|---|
| 310 | postProcessed_prf.close() |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | # Remove temporary files |
|---|
| 314 | os.remove(compDir + '.' + outputFileName_prf + '.tmp') |
|---|