#! /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 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' #~ 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) attributesTable = [ \ [['name', 'center'],['value', 'center']], \ ] attributes = taste.getComponentAttributes (iv) for name, value in attributes.items(): attributesTable.append([name , value]) table(attributesTable, label + ' attributes') ## FUNCTIONS newPage() functions = taste.getFunctions() for function in functions: ## get the image filename and convert the svg to pdf file svgFile = lmp.getInstanceName(function)[0] svgFile = imgDir + '/' + svgFile + '.svg' pdfFile = svgToPdf(svgFile) ## function header label = taste.getComponentLabel(function) headerText = 'Function ' + label header(headerText) ## image if pdfFile != '': imageRef = image(pdfFile, label, label) rawText(label + ' ' + imageRef) ## 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) attributesTable = [ \ [['name', 'center'],['value', 'center']], \ ] attributes = taste.getComponentAttributes (function) for name, value in attributes.items(): attributesTable.append([name , value]) table(attributesTable, bold(label) + ' attributes') ## 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 (contParamList) ## 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) attributesTable = [ \ [['name', 'center'],['value', 'center']], \ ] attributes = taste.getFeatureAttributes (feature) for name, value in attributes.items(): attributesTable.append([name , value]) table(attributesTable, bold(featureLabel) + ' attributes') ## 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: parameterList = [] parameterLabel = taste.getParameterLabel(parameter) parameterList.append(parameterLabel) listBlock (parameterList) attributesTable = [ \ [['name', 'center'],['value', 'center']], \ ] ## attributes attributes = taste.getFeatureAttributes (parameter) for name, value in attributes.items(): 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]) ## other direction = taste.getDirection(parameter) attributesTable.append(['direction' , direction]) table(attributesTable, bold(parameterLabel) + ' attributes', tableType='grid') if __name__ == "__main__": main () #~ sys.exit (0); # exit