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