summaryrefslogtreecommitdiffstats
path: root/dgbuilder/tools/dot_to_json.js
diff options
context:
space:
mode:
authorTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:37:53 -0500
committerTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:40:37 -0500
commit324ee36fe31763e507b422ab0a88e4230045e205 (patch)
treed0b04520f6657601c918ce63fd27575977624187 /dgbuilder/tools/dot_to_json.js
parentf0c97e8db427481e28c0a16b789bc73801b35e47 (diff)
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680 Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com> Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'dgbuilder/tools/dot_to_json.js')
-rw-r--r--dgbuilder/tools/dot_to_json.js138
1 files changed, 138 insertions, 0 deletions
diff --git a/dgbuilder/tools/dot_to_json.js b/dgbuilder/tools/dot_to_json.js
new file mode 100644
index 00000000..7ff80e8b
--- /dev/null
+++ b/dgbuilder/tools/dot_to_json.js
@@ -0,0 +1,138 @@
+var obj={};
+function dotToJson(str,value,obj){
+ //var objArr = path.split("."), part;
+ var objArr = str.split(".");
+ var prevStr;
+ var currObj;
+ var prevObj;
+ //console.log(str);
+ var isArray = false;
+ var prevObjIsArray = false;
+ for(var i=0;i<objArr.length -1;i++){
+ var subStr= objArr[i] ;
+ if(isArray){
+ prevObjIsArray = true;
+ }
+ isArray = false;
+ if(subStr.indexOf(']') == subStr.length -1){
+ subStr = subStr.substring(0,subStr.length -2);
+ isArray = true;
+ }
+ //console.log("subStr:" + subStr + isArray);
+ //console.dir(prevObj);
+ if(isArray){
+ if(i==0 && obj[subStr] == undefined ){
+ //console.log("i==0 && obj[subStr] ");
+ obj[subStr]=[];
+ }else if(i==0 && obj[subStr][0] == undefined ){
+ obj[subStr][0]={};
+ }else if(i==0 && obj[subStr][0] != undefined ){
+ currObj= obj[subStr][0];
+ }else{
+ if(i == 1){
+ //console.log("i==1 && obj[prevStr] ");
+ prevObj=obj[prevStr];
+ if(prevObj[subStr] != undefined && prevObj[subStr][0] == undefined){
+ prevObj[subStr] = [];
+ prevObj[subStr][0] = {};
+ currObj = prevObj[subStr][0];
+ }else if(prevObj[subStr] != undefined && prevObj[subStr][0] != undefined){
+ currObj = prevObj[subStr][0];
+ }else if(prevObj[subStr] == undefined){
+ prevObj[subStr] = [];
+ prevObj[subStr][0] = {};
+ currObj = prevObj[subStr][0];
+ }
+ }else{
+ if(prevObj[subStr] == undefined){
+ prevObj[subStr]=[];
+ prevObj[subStr][0]={};
+ currObj = prevObj[subStr][0];
+ }else{
+ currObj = prevObj[subStr][0];
+ }
+ }
+ }
+ }else{
+ if(i==0 && obj[subStr] == undefined ){
+ obj[subStr] = {};
+ currObj= obj[subStr];
+ }else if(i==0 && obj[subStr] != undefined ){
+ currObj=obj[subStr];
+ //console.log("in gkjgjkg");
+ }else{
+ if(i == 1){
+ prevObj=obj[prevStr];
+ if(prevObj[subStr] == undefined){
+ prevObj[subStr] = {};
+ currObj = prevObj[subStr];
+ }else{
+ currObj = prevObj[subStr];
+ }
+ }else{
+ if(prevObj[subStr] == undefined){
+ prevObj[subStr] = {};
+ currObj = prevObj[subStr];
+ }else{
+ currObj = prevObj[subStr];
+ }
+ }
+ }
+ }
+ prevStr=subStr;
+ if(i <objArr.length-2){
+ //console.dir(currObj);
+ prevObj=currObj;
+ }
+ }
+ var lastStr = objArr[objArr.length-1];
+ if(isArray){
+ currObj[lastStr] = value;
+ }else{
+ currObj[lastStr] = value;
+ }
+ //prevObj[lastStr] = value;
+ //console.dir(currObj);
+ return obj;
+}
+function printObj(obj){
+for( j in obj){
+ console.log(j + ":" + obj[j]);
+ if(typeof obj[j] == "object" ){
+ printObj(obj[j]);
+ }
+
+}
+}
+
+/*
+var nObj={};
+for(var i=0;i<a.length;i++){
+ dotToJson(a[i],'',nObj);
+}
+*/
+var sliValuesObj = require(process.argv[2]);
+var moduleName = process.argv[3];
+//console.dir(sliValuesObj);
+var a= sliValuesObj[moduleName + "_VALUES"];
+var rpcs= sliValuesObj[moduleName + "_RPCS"];
+var nObj={};
+nObj['moduleName'] = moduleName;
+console.log("module.exports = ");
+for(var i=0;i<a.length;i++){
+ var key =a[i].substring(0,a[i].indexOf(':'));
+ //console.log(key);
+ var value =a[i].substring(a[i].indexOf(':') +1);
+ if(value == undefined) value ="";
+ dotToJson(key,value,nObj);
+}
+
+nObj[moduleName + "_PROPS"] =[];
+for(var i=0;i<a.length;i++){
+ var key =a[i].substring(0,a[i].indexOf(':'));
+ nObj[moduleName + "_PROPS"].push(key);
+}
+
+nObj[moduleName + "_RPCS"] = rpcs;
+
+console.log(JSON.stringify(nObj,null,4));