blob: 15259be360445a25a769c33696012787bfeac881 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301#
2# Copyright (c) 2019, Infosys Ltd.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17import json, sys, os
18from os.path import join
19import utils
20
21with open('dataModels/stateMachineAppModel.json') as jsonFile:
22 stateMachineAppModelJSON = json.load(jsonFile)
23with open('dataModels/ctxtManagerAppModel.json') as jsonFile:
24 contextMgrAppModelJSON = json.load(jsonFile)
25
26def processTemplate(templateIp):
27 from template import Template
28
29 utils.outputFileName = ''
30 if utils.outputFileKeyword != '':
31 utils.outputFileName = utils.getFileName(templateIp[utils.outputFileKeyword])
32 if utils.outputFile != '':
33 utils.outputFileName = utils.outputFileName + utils.outputFile
34
35 utils.outputFileName = utils.outputFileName + utils.outputFileExt
36
37 tt = Template({'EVAL_PYTHON':1, 'AUTO_RESET':1})
38 op = tt.process(utils.ttFileName, {'TemplateInputVar' : templateIp})
39 utils.WriteFile(utils.outputDir, utils.outputFileName, op, utils.mode)
40
41def getTemplateIn(appModelItems, depth):
42 depthChanged = False
43
44 if (depth == 0):
45 print(appModelItems)
46 processTemplate(appModelItems)
47 return
48
49 if depthChanged == False:
50 depth = depth - 1
51 depthChanged = True
52
53 for item in appModelItems:
54 getTemplateIn(item, depth)
55
56def genCppCode(genModel, appModelJSON):
57 for item in genModel:
58 keyWord = item["appModelKeyword"]
59 depth = item["appModelValueDepth"]
60 utils.ttFileName = item["templateFile"]
61 utils.outputDir = item["outputPath"]
62 utils.outputFile = item["outputFile"]
63 utils.outputFileKeyword = item["outputFileKey"]
64 utils.outputFileExt = item["outputFileExt"]
65 utils.mode = item["mode"]
66
67 if not os.path.exists(utils.outputDir):
68 os.makedirs(utils.outputDir)
69
70 appModelItems = utils.get_key_values(appModelJSON, keyWord)
71 getTemplateIn(appModelItems, depth)
72
73with open('dataModels/generationItem.json') as JSONFile:
74 GenItemJSON = json.load(JSONFile)
75 if 'Model1' in GenItemJSON:
76 genCppCode(GenItemJSON['Model1'], stateMachineAppModelJSON)
77 if "Model2" in GenItemJSON:
78 genCppCode(GenItemJSON['Model2'], contextMgrAppModelJSON)
79