root/WaveDev/trunk/WaveDev/XML_gen/application_gen.py @ 570

Revision 570, 6.6 KB (checked in by depriest, 8 years ago)

It all seems to be working now; added the basic xml files for DomainManager?, DeviceManager?, and GenericBox? that most waveforms will need

Line 
1import sys
2import commands
3from softcomponent_gen import componentGen
4from amara import binderytools
5
6#
7# UUID Generator
8#
9def uuidgen():
10   return commands.getoutput('uuidgen')
11
12
13def genxml(complist, waveformDir, waveName):
14   #
15   # Specification
16   #
17
18   componentList = []
19   connectionList = []
20
21   for n in complist:
22      componentList.append(unicode(n.name))
23      for i in n.connections:
24         connectionList.append([unicode(n.name) + u'to' + unicode(i.name), unicode(n.name), unicode(i.name)])
25
26   if waveformDir[len(waveformDir)-1] != '/':
27        waveformDir = waveformDir + '/'
28   waveformDir = unicode(waveformDir) + u'waveforms/'
29
30   #
31   # Generate Components
32   #
33   for n in componentList:
34      componentGen(n, u'Null', waveformDir)
35   appName = unicode(waveName)
36   namingServicePrefix = u'ossie'
37   commentLine = u'<!--Created with duct tape and toothpicks pre-alpha 0.0.1 by BrunoSchwarz-->\n<!--Powered by Python-->\n'
38 
39   numComponents = len(componentList)
40 
41 
42   #componentList = []
43   #componentList.append(u'AssemblyController')
44   #componentList.append(u'ModBPSK')
45   #componentList.append(u'Channel')
46   #componentList.append(u'Channel2')
47   #componentList.append(u'Channel3')
48   #componentList.append(u'Channel4')
49   #componentList.append(u'Demod')
50
51   #for n in range(numComponents):
52   #   componentList.append('TestComponent' + str(n))
53   #   componentList[n] = unicode(componentName[n])
54
55
56   numConnections = len(connectionList)
57   
58   CONNECTION_NAME = 0
59   CONNECTION_USES = 1
60   CONNECTION_PROVIDES = 2
61   
62   #connectionList = []
63   #for n in range(numConnections):
64   #   connectionList.append([componentList[n] + u'to' + componentName[n+1], componentName[n], componentName[n+1]])
65   
66   extension_Resource = u'Resource'
67   extension_spd = u'.spd.xml'
68   extension_scd = u'.scd.xml'
69   extension_prf = u'.prf.xml'
70   extension_sad = u'.sad.xml'
71   extension_exe = u'.exe'
72   
73   outputFilename_sad = appName + extension_sad
74   
75   preProcessed_sad = open(waveformDir + '.' + outputFilename_sad + '.tmp', 'w')
76   postProcessed_sad = open(waveformDir + outputFilename_sad, 'w')
77   
78   #
79   # SAD Parser / Generator
80   #
81   
82   # Parse and objectify
83   
84   doc_sad = binderytools.bind_file('../XML_gen/_sad.xml.tpl')
85   
86   doc_sad.softwareassembly.name = u'OSSIE::' + appName
87   doc_sad.softwareassembly.id = u'DCE:' + unicode(uuidgen())
88 
89   #
90   # Attempt to add elemnts postponed due to whitespace and formatting problem
91   #
92   #element_componentfile = doc_sad.xml_element(u'componentfile', attributes={u'type': u'SPD', u'id': u'Default'})
93   
94   componentfile = [componentfile for componentfile in doc_sad.softwareassembly.componentfiles.componentfile]
95   
96   for n in range(numComponents):
97   #   doc_sad.softwareassembly.componentfiles.xml_append(element_componentfile)
98   #   doc_sad.softwareassembly.componentfiles.componentfile[2].xml_children.append(doc_sad.xml_element(u'localfile', attributes={u'name': u'test'}))
99      componentfile[n].id = componentList[n] + u'ResourceFile'
100      componentfile[n].localfile.name = u'/waveforms/' \
101                                        + componentList[n] \
102                                        + extension_Resource \
103                                        + extension_spd
104   
105   for n in range(10 - numComponents):
106      componentfile[numComponents].xml_clear()
107      del doc_sad.softwareassembly.componentfiles.componentfile[numComponents]
108   
109   #
110   # Assembly Controller
111   #
112   
113   assemblycontroller_id = u'DCE:' + unicode(uuidgen())
114   doc_sad.softwareassembly.assemblycontroller.componentinstantiationref.refid = assemblycontroller_id
115   
116   #
117   # Partitioning
118   #
119 
120   componentplacement = [componentplacement for componentplacement in doc_sad.softwareassembly.partitioning.componentplacement]
121   
122   
123   for n in range(numComponents):
124      componentplacement[n].componentfileref.refid = componentList[n] + u'ResourceFile'
125      componentplacement[n].componentinstantiation.id = u'DCE:' + unicode(uuidgen())
126      componentplacement[n].componentinstantiation.usagename = componentList[n]
127      componentplacement[n].componentinstantiation.findcomponent.namingservice.name = u'/DomainName1/' \
128                                                                                      + namingServicePrefix \
129                                                                                      + componentList[n] \
130                                                                                      + u'Resource'
131   
132   for n in range(10 - numComponents):
133        componentplacement[numComponents].xml_clear()
134        del doc_sad.softwareassembly.partitioning.componentplacement[numComponents]
135     
136   # 
137   #   Set matching Assembly Controller id
138   # 
139   componentplacement[0].componentinstantiation.id = assemblycontroller_id
140     
141   # 
142   # Connections
143   # 
144     
145   connectinterface = [connectinterface for connectinterface in doc_sad.softwareassembly.connections.connectinterface]
146     
147   for n in range(numConnections):
148      connectinterface[n].id = connectionList[n][CONNECTION_NAME]
149   #  connectinterface[n].usesport.usesidentifier = connectionList[n][CONNECTION_USES]
150      connectinterface[n].usesport.findby.namingservice.name =  u'/DomainName1/' \
151                                                                + namingServicePrefix \
152                                                                + connectionList[n][CONNECTION_USES] \
153                                                                + u'Resource'
154      connectinterface[n].findby.namingservice.name = u'/DomainName1/' \
155                                                      + namingServicePrefix \
156                                                      + connectionList[n][CONNECTION_PROVIDES] \
157                                                      + u'Resource'
158   
159   for n in range(10 - numConnections):
160      connectinterface[numConnections].xml_clear()
161      del doc_sad.softwareassembly.connections.connectinterface[numConnections]
162   
163   
164   #print doc_sad.xml(sys.stdout)
165   print >> preProcessed_sad, doc_sad.xml()
166   preProcessed_sad.close()
167   
168   #preProcessedSAD = doc_sad.xml()
169   
170   #
171   # Post Processing
172   #
173   preProcessed_sad = open(waveformDir + '.' + outputFilename_sad + '.tmp', 'r')
174   #
175   # Specify external DTD
176   #
177   line0 = preProcessed_sad.readline()
178   remaining = preProcessed_sad.readlines()
179   postProcessed_sad.writelines(line0)
180   postProcessed_sad.writelines(u'<!DOCTYPE softwareassembly SYSTEM \"dtd/softwareassembly.dtd\">\n')
181   postProcessed_sad.writelines(commentLine)
182   postProcessed_sad.writelines(remaining)
183   postProcessed_sad.close()
184   
185   #
186   # Beautify
187   #
Note: See TracBrowser for help on using the browser.