ivDocExample.py 5.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#! /usr/bin/python

import ocarina
import lmp
import taste
#~ from taste import *
from pandoc import *

def main ():
	## load iv files
	aadlFiles = ['../projects/DemoIV.aadl', '../projects/TASTE-Dataview.aadl', '../projects/TASTE_IV_Properties.aadl', \
		'../projects/taste_properties.aadl', '../projects/data_model.aadl', '../projects/base_types.aadl', '../projects/deployment.aadl']

	ret = taste.load (aadlFiles, "interfaceview::IV::interfaceview.others")
	print 'load', ret
16 17 18 19 20 21 22 23 24 25 26

	imgDir = '../tmp'
	#~ tasteCmd = ['/home/ocarina/Documentation/TASTE/bin/TASTE', '--edit-aadl ' + '../projects/DemoIV.aadl', \
		#~ '--export-all-svg ' + imgDir]
#~ 
	#~ try:
		#~ print 'generating images'
		#~ subprocess.call(tasteCmd)
	#~ except :
		#~ print 'error in svg generation'
            
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	#~ indent = '\t'
	indent = ''
	indent2 = '\t'
	
	## start the pandoc document
	newDocument('Demo IV Documentation ', ['Jerome Legrand'], 'July the 24th 2017')
	addTOC()
	
	newPage()
	
	## ROOT
	iv = taste.getTasteRoot()
	label = taste.getComponentLabel(iv)
	headerText = 'IV ' + label
	header (headerText)
	
	comment = taste.getComment (iv)
	if comment != '':
		header('Description', 2)
		
		comment = removeFormatting(comment)
		paragraph(comment)
	
	## root attributes
	header('Attributes', 2)
	text = 'The iv ' + bold(label) + ' has the following attributes : '
	rawText(text)
54 55 56 57 58

	attributesTable = [ \
	[['name', 'center'],['value', 'center']], \
	]
			
59 60
	attributes = taste.getComponentAttributes (iv)
	for name, value in attributes.items():
61
		attributesTable.append([name , value])
62
	
63
	table(attributesTable, label + ' attributes')
64 65 66 67 68
	
	## FUNCTIONS
	newPage()
	functions = taste.getFunctions()
	for function in functions:
69 70 71 72 73
		## get the image filename and convert the svg to pdf file
		svgFile = lmp.getInstanceName(function)[0]
		svgFile = imgDir + '/' + svgFile + '.svg'
		pdfFile = svgToPdf(svgFile)
		
74 75 76 77 78
		## function header
		label = taste.getComponentLabel(function)
		headerText = 'Function ' + label
		header(headerText)
		
79 80 81 82 83
		## image
		if pdfFile != '':
			imageRef = image(pdfFile, label, label)
			rawText(label + ' ' + imageRef)
	
84 85 86 87 88 89 90 91 92 93 94 95 96
		## Description
		description = taste.getDescription (function)
		if description != '':
			header('Description', 2)
			
			description = removeFormatting(description)
			paragraph(description)

		## attributes
		header('Attributes', 2)
		text = 'The function ' + bold(label) + ' has the following attributes : '
		rawText(text)
	
97 98 99 100
		attributesTable = [ \
			[['name', 'center'],['value', 'center']], \
			]
			
101 102
		attributes = taste.getComponentAttributes (function)
		for name, value in attributes.items():
103
			attributesTable.append([name , value])
104
		
105 106
		table(attributesTable, bold(label) + ' attributes')
				
107 108 109 110 111 112 113 114 115 116 117 118
		## functions CP
		contParams = taste.getFunctionCP (function)
		if contParams != []:
			header('Context Parameters', 2)
			text = 'The function' + bold(label) + ' has the following context parameters : '
			rawText(text)
			
			contParamList = []
			for contParam in contParams:
				cpLabel = taste.getLabel(contParam)
				contParamList.append(cpLabel)
				
119
			listBlock (contParamList)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
			
		## PI/RI
		pis = taste.getFunctionFeatures (function, 'provided')
		if pis != []:
			header('Provided Interfaces', 2)
		
			text = 'The function ' + bold(label) + ' has the following pis.'
			rawText(text)
			addPIRIInfo(pis)
		
		ris = taste.getFunctionFeatures (function, 'required')
		if ris != []:
			header('Required Interfaces', 2)
		
			text = 'The function ' + bold(label) + ' has the following ris.'
			rawText(text)
			addPIRIInfo(ris)
	
	finalizeDocument()
	
	#~ printDocument ()

142
	serialize ('ivDoc.md')
143
	#~ convert('test.latex', 'latex')
144
	#~ convert('test.pdf', 'latex')
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

def addPIRIInfo(features):
	for feature in features:
		featureLabel = taste.getFeatureLabel(feature)
		
		featureCategory = taste.getCategory(feature)
		headerText = featureCategory + ' ' + featureLabel
		header(headerText, 3)
		
		description = taste.getDescription (feature)
		if description != '':
			#~ header('Description', 3)
		
			description = removeFormatting(description)
			paragraph(description)
		
		## attributes
		text = 'The ' + featureCategory + ' ' + bold(featureLabel) + ' has the following attributes : '
		rawText(text)
		
165 166 167 168
		attributesTable = [ \
			[['name', 'center'],['value', 'center']], \
			]
			
169 170
		attributes = taste.getFeatureAttributes (feature)
		for name, value in attributes.items():
171
			attributesTable.append([name , value])
172
		
173
		table(attributesTable, bold(featureLabel) + ' attributes')
174 175 176 177 178 179 180 181 182
		
		## parameters
		parameters = taste.getParameters (feature)
		if parameters != []:
			header('Parameters', 4)
			text = 'The ' + featureCategory + ' ' + bold(featureLabel) + ' has the following parameters : '
			rawText(text)
			
			for parameter in parameters:
183
				parameterList = []
184 185 186 187
				parameterLabel = taste.getParameterLabel(parameter)

				parameterList.append(parameterLabel)
				
188 189 190 191 192 193
				listBlock (parameterList)
				
				attributesTable = [ \
					[['name', 'center'],['value', 'center']], \
					]
				
194 195 196
				## attributes
				attributes = taste.getFeatureAttributes (parameter)
				for name, value in attributes.items():
197 198 199 200 201 202 203
					if name == 'source_text':
						value = url('http://path/to/asn/file', value)
					if name == 'type_source_name':
						value = url('http://path', value)
						
					attributesTable.append([name , value])
				
204 205
				## other
				direction = taste.getDirection(parameter)
206 207 208 209
				attributesTable.append(['direction' , direction])

				table(attributesTable, bold(parameterLabel) + ' attributes', tableType='grid')

210 211 212
if __name__ == "__main__":
    main ()
    #~ sys.exit (0);                       # exit