root/WaveDev/branches/WaveDevNoAmara/wavedev/XML_gen/component_gen.py @ 4268

Revision 4268, 11.1 KB (checked in by jgaeddert, 6 years ago)

finished removing Amara from component_gen.py except for odd simplesequence of provides ports

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