ivDocExample.py 4.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
#! /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
	
	#~ 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)
	
	attributesList = []
	attributes = taste.getComponentAttributes (iv)
	for name, value in attributes.items():
		#~ text += indent + '* ' + name + ' = ' + value + '\n'
		attributesList.append(italic(name) + ' = ' + value)
	
	listBlock (attributesList)
	
	## FUNCTIONS
	newPage()
	functions = taste.getFunctions()
	for function in functions:
		## function header
		label = taste.getComponentLabel(function)
		headerText = 'Function ' + label
		header(headerText)
		
		## 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)
	
		attributesList = []
		attributes = taste.getComponentAttributes (function)
		for name, value in attributes.items():
			attributesList.append(italic(name) + ' = ' + value)
		
		listBlock (attributesList)

		## 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)
				
			listBlock (attributesList)
			
		## 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 ()

	#~ serialize ('ivDoc.md')
	#~ convert('test.latex', 'latex')
	convert('test.pdf', 'latex')

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)
		
		attributesList = []
		attributes = taste.getFeatureAttributes (feature)
		for name, value in attributes.items():
			attributesList.append(italic(name) + ' = ' + value)
		
		listBlock (attributesList)
		
		## parameters
		parameters = taste.getParameters (feature)
		if parameters != []:
			header('Parameters', 4)
			text = 'The ' + featureCategory + ' ' + bold(featureLabel) + ' has the following parameters : '
			rawText(text)
			
			parameterList = []
			for parameter in parameters:
				parameterLabel = taste.getParameterLabel(parameter)

				parameterList.append(parameterLabel)
				
				## attributes
				paramAttList = []
				attributes = taste.getFeatureAttributes (parameter)
				for name, value in attributes.items():
					paramAttList.append(italic(name) + ' = ' + value)
					
				## other
				direction = taste.getDirection(parameter)
				paramAttList.append(italic('direction') + ' = ' + direction)
				
				if paramAttList != []:
					parameterList.append(paramAttList)
					
			listBlock (parameterList)
	
if __name__ == "__main__":
    main ()
    #~ sys.exit (0);                       # exit