mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
bbf: update python scripts to python3
This commit is contained in:
parent
421dc03778
commit
3183933dad
3 changed files with 343 additions and 343 deletions
|
|
@ -162,18 +162,18 @@ def load_param(dmobject):
|
|||
def printOBJPARAM(obj, supported, protocols, types):
|
||||
fp = open('./.tmp', 'a')
|
||||
if CUSTOM_PREFIX in obj:
|
||||
print >> fp, "%s::%s::%s::%s::" % (obj, protocols, "Yes", types)
|
||||
print("%s::%s::%s::%s::" % (obj, protocols, "Yes", types), file=fp)
|
||||
else:
|
||||
print >> fp, "%s::%s::%s::%s::" % (obj, protocols, supported, types)
|
||||
print("%s::%s::%s::%s::" % (obj, protocols, supported, types), file=fp)
|
||||
fp.close()
|
||||
|
||||
def printusage():
|
||||
print "Usage: " + sys.argv[0] + " <json data model>"
|
||||
print "Examples:"
|
||||
print " - " + sys.argv[0] + " tr181.json"
|
||||
print " ==> Generate excel file in tr181.xls"
|
||||
print " - " + sys.argv[0] + " tr104.json"
|
||||
print " ==> Generate excel file in tr104.xls"
|
||||
print("Usage: " + sys.argv[0] + " <json data model>")
|
||||
print("Examples:")
|
||||
print(" - " + sys.argv[0] + " tr181.json")
|
||||
print(" ==> Generate excel file in tr181.xls")
|
||||
print(" - " + sys.argv[0] + " tr104.json")
|
||||
print(" ==> Generate excel file in tr104.xls")
|
||||
|
||||
def object_parse_childs( dmobject , value ):
|
||||
hasobj = objhaschild(value)
|
||||
|
|
@ -283,12 +283,12 @@ with open(sys.argv[1]) as file:
|
|||
|
||||
for obj, value in data.items():
|
||||
if obj == None:
|
||||
print "Wrong JSON Data model format!"
|
||||
print("Wrong JSON Data model format!")
|
||||
exit(1)
|
||||
|
||||
generatecfromobj(excel_file, obj, value)
|
||||
|
||||
if (os.path.isfile(excel_file)):
|
||||
print "%s excel file generated" % excel_file
|
||||
print("%s excel file generated" % excel_file)
|
||||
else:
|
||||
print "No Excel file generated!"
|
||||
print("No Excel file generated!")
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ def getuniquekeys( value, option ):
|
|||
buf = buf + "\"%s\"" % key + ", "
|
||||
buf = buf + "NULL" + "}"
|
||||
return buf
|
||||
return None
|
||||
return None
|
||||
|
||||
def getargsparam( value ):
|
||||
if isinstance(value, dict):
|
||||
|
|
@ -161,7 +161,7 @@ def printGlobalstrCommon( str_exp ):
|
|||
else:
|
||||
common = "tr181/common.c"
|
||||
fp = open(common, 'a')
|
||||
print >> fp, "%s" % str_exp
|
||||
print("%s" % str_exp, file=fp)
|
||||
fp.close()
|
||||
|
||||
def get_mapping_obj( mappingobj ):
|
||||
|
|
@ -354,124 +354,124 @@ def generate_validate_value(dmparam, value):
|
|||
|
||||
def printheaderObjCommon( objname ):
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
print >> fp, "/* *** %s *** */" % objname
|
||||
print("/* *** %s *** */" % objname, file=fp)
|
||||
fp.close()
|
||||
|
||||
def cprintheaderOBJS( objname ):
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
print >> fp, "DMOBJ %s[] = {" % ("t" + getname(objname) + "Obj")
|
||||
print >> fp, "/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/"
|
||||
print("DMOBJ %s[] = {" % ("t" + getname(objname) + "Obj"), file=fp)
|
||||
print("/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/", file=fp)
|
||||
fp.close()
|
||||
|
||||
def hprintheaderOBJS( objname ):
|
||||
fp = open('./.objparamarray.h', 'a')
|
||||
print >> fp, "extern DMOBJ %s[];" % ("t" + getname(objname) + "Obj")
|
||||
print("extern DMOBJ %s[];" % ("t" + getname(objname) + "Obj"), file=fp)
|
||||
fp.close()
|
||||
|
||||
def cprinttopfile (fp, filename):
|
||||
print >> fp, "/*"
|
||||
print >> fp, " * Copyright (C) 2020 iopsys Software Solutions AB"
|
||||
print >> fp, " *"
|
||||
print >> fp, " * This program is free software; you can redistribute it and/or modify"
|
||||
print >> fp, " * it under the terms of the GNU Lesser General Public License version 2.1"
|
||||
print >> fp, " * as published by the Free Software Foundation"
|
||||
print >> fp, " *"
|
||||
print >> fp, " * Author: <Name> <Surname> <name.surname@iopsys.eu>"
|
||||
print >> fp, " */"
|
||||
print >> fp, ""
|
||||
print >> fp, "#include \"%s.h\"" % filename.lower()
|
||||
print >> fp, ""
|
||||
print("/*", file=fp)
|
||||
print(" * Copyright (C) 2020 iopsys Software Solutions AB", file=fp)
|
||||
print(" *", file=fp)
|
||||
print(" * This program is free software; you can redistribute it and/or modify", file=fp)
|
||||
print(" * it under the terms of the GNU Lesser General Public License version 2.1", file=fp)
|
||||
print(" * as published by the Free Software Foundation", file=fp)
|
||||
print(" *", file=fp)
|
||||
print(" * Author: <Name> <Surname> <name.surname@iopsys.eu>", file=fp)
|
||||
print(" */", file=fp)
|
||||
print("", file=fp)
|
||||
print("#include \"%s.h\"" % filename.lower(), file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
def hprinttopfile (fp, filename):
|
||||
print >> fp, "/*"
|
||||
print >> fp, " * Copyright (C) 2020 iopsys Software Solutions AB"
|
||||
print >> fp, " *"
|
||||
print >> fp, " * This program is free software; you can redistribute it and/or modify"
|
||||
print >> fp, " * it under the terms of the GNU Lesser General Public License version 2.1"
|
||||
print >> fp, " * as published by the Free Software Foundation"
|
||||
print >> fp, " *"
|
||||
print >> fp, " * Author: <Name> <Surname> <name.surname@iopsys.eu>"
|
||||
print >> fp, " */"
|
||||
print >> fp, ""
|
||||
print >> fp, "#ifndef __%s_H" % filename.upper()
|
||||
print >> fp, "#define __%s_H" % filename.upper()
|
||||
print >> fp, ""
|
||||
print >> fp, "#include <libbbf_api/dmcommon.h>"
|
||||
print >> fp, ""
|
||||
print("/*", file=fp)
|
||||
print(" * Copyright (C) 2020 iopsys Software Solutions AB", file=fp)
|
||||
print(" *", file=fp)
|
||||
print(" * This program is free software; you can redistribute it and/or modify", file=fp)
|
||||
print(" * it under the terms of the GNU Lesser General Public License version 2.1", file=fp)
|
||||
print(" * as published by the Free Software Foundation", file=fp)
|
||||
print(" *", file=fp)
|
||||
print(" * Author: <Name> <Surname> <name.surname@iopsys.eu>", file=fp)
|
||||
print(" */", file=fp)
|
||||
print("", file=fp)
|
||||
print("#ifndef __%s_H" % filename.upper(), file=fp)
|
||||
print("#define __%s_H" % filename.upper(), file=fp)
|
||||
print("", file=fp)
|
||||
print("#include <libbbf_api/dmcommon.h>", file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
def hprintfootfile (fp, filename):
|
||||
print >> fp, ""
|
||||
print >> fp, "#endif //__%s_H" % filename.upper()
|
||||
print >> fp, ""
|
||||
print("", file=fp)
|
||||
print("#endif //__%s_H" % filename.upper(), file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
def cprintAddDelObj( faddobj, fdelobj, name, mappingobj, dmobject ):
|
||||
fp = open('./.objadddel.c', 'a')
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char **instance)" % faddobj
|
||||
print >> fp, "{"
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char **instance)" % faddobj, file=fp)
|
||||
print("{", file=fp)
|
||||
if mappingobj != None:
|
||||
type, file, sectiontype, dmmapfile, path, ref = get_mapping_obj(mappingobj)
|
||||
if type == "uci":
|
||||
print >> fp, " char *inst, *value, *v;"
|
||||
print >> fp, " struct uci_section *dmmap = NULL, *s = NULL;"
|
||||
print >> fp, ""
|
||||
print >> fp, " check_create_dmmap_package(\"%s\");" % dmmapfile
|
||||
print >> fp, " inst = get_last_instance_bbfdm(\"%s\", \"%s\", \"%s\");" % (dmmapfile, sectiontype, name+"instance")
|
||||
print >> fp, " dmuci_add_section(\"%s\", \"%s\", &s, &value);" % (file, sectiontype)
|
||||
print >> fp, " //dmuci_set_value_by_section(s, \"option\", \"value\");"
|
||||
print >> fp, ""
|
||||
print >> fp, " dmuci_add_section_bbfdm(\"%s\", \"%s\", &dmmap, &v);" % (dmmapfile, sectiontype)
|
||||
print >> fp, " dmuci_set_value_by_section(dmmap, \"section_name\", section_name(s));"
|
||||
print >> fp, " *instance = update_instance(inst, 4, dmmap, \"%s\");" % (name+"instance")
|
||||
print(" char *inst, *value, *v;", file=fp)
|
||||
print(" struct uci_section *dmmap = NULL, *s = NULL;", file=fp)
|
||||
print("", file=fp)
|
||||
print(" check_create_dmmap_package(\"%s\");" % dmmapfile, file=fp)
|
||||
print(" inst = get_last_instance_bbfdm(\"%s\", \"%s\", \"%s\");" % (dmmapfile, sectiontype, name+"instance"), file=fp)
|
||||
print(" dmuci_add_section(\"%s\", \"%s\", &s, &value);" % (file, sectiontype), file=fp)
|
||||
print(" //dmuci_set_value_by_section(s, \"option\", \"value\");", file=fp)
|
||||
print("", file=fp)
|
||||
print(" dmuci_add_section_bbfdm(\"%s\", \"%s\", &dmmap, &v);" % (dmmapfile, sectiontype), file=fp)
|
||||
print(" dmuci_set_value_by_section(dmmap, \"section_name\", section_name(s));", file=fp)
|
||||
print(" *instance = update_instance(inst, 4, dmmap, \"%s\");" % (name+"instance"), file=fp)
|
||||
else:
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)" % fdelobj
|
||||
print >> fp, "{"
|
||||
print(" //TODO", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)" % fdelobj, file=fp)
|
||||
print("{", file=fp)
|
||||
if mappingobj != None:
|
||||
if type == "uci":
|
||||
print >> fp, " struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;"
|
||||
print >> fp, " int found = 0;"
|
||||
print >> fp, ""
|
||||
print >> fp, " switch (del_action) {"
|
||||
print(" struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;", file=fp)
|
||||
print(" int found = 0;", file=fp)
|
||||
print("", file=fp)
|
||||
print(" switch (del_action) {", file=fp)
|
||||
if mappingobj != None:
|
||||
if type == "uci":
|
||||
print >> fp, " case DEL_INST:"
|
||||
print >> fp, " get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name((struct uci_section *)data), &dmmap_section);" % (dmmapfile, sectiontype)
|
||||
print >> fp, " if (dmmap_section != NULL)"
|
||||
print >> fp, " dmuci_delete_by_section(dmmap_section, NULL, NULL);"
|
||||
print >> fp, " dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " case DEL_ALL:"
|
||||
print >> fp, " uci_foreach_sections(\"%s\", \"%s\", s) {" % (file, sectiontype)
|
||||
print >> fp, " if (found != 0) {"
|
||||
print >> fp, " get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (dmmapfile, sectiontype)
|
||||
print >> fp, " if (dmmap_section != NULL)"
|
||||
print >> fp, " dmuci_delete_by_section(dmmap_section, NULL, NULL);"
|
||||
print >> fp, " dmuci_delete_by_section(ss, NULL, NULL);"
|
||||
print >> fp, " }"
|
||||
print >> fp, " ss = s;"
|
||||
print >> fp, " found++;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " if (ss != NULL) {"
|
||||
print >> fp, " get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (dmmapfile, sectiontype)
|
||||
print >> fp, " if (dmmap_section != NULL)"
|
||||
print >> fp, " dmuci_delete_by_section(dmmap_section, NULL, NULL);"
|
||||
print >> fp, " dmuci_delete_by_section(ss, NULL, NULL);"
|
||||
print >> fp, " }"
|
||||
print >> fp, " break;"
|
||||
print(" case DEL_INST:", file=fp)
|
||||
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name((struct uci_section *)data), &dmmap_section);" % (dmmapfile, sectiontype), file=fp)
|
||||
print(" if (dmmap_section != NULL)", file=fp)
|
||||
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
|
||||
print(" dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" case DEL_ALL:", file=fp)
|
||||
print(" uci_foreach_sections(\"%s\", \"%s\", s) {" % (file, sectiontype), file=fp)
|
||||
print(" if (found != 0) {", file=fp)
|
||||
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (dmmapfile, sectiontype), file=fp)
|
||||
print(" if (dmmap_section != NULL)", file=fp)
|
||||
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
|
||||
print(" dmuci_delete_by_section(ss, NULL, NULL);", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" ss = s;", file=fp)
|
||||
print(" found++;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" if (ss != NULL) {", file=fp)
|
||||
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (dmmapfile, sectiontype), file=fp)
|
||||
print(" if (dmmap_section != NULL)", file=fp)
|
||||
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
|
||||
print(" dmuci_delete_by_section(ss, NULL, NULL);", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" break;", file=fp)
|
||||
else:
|
||||
print >> fp, " case DEL_INST:"
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " case DEL_ALL:"
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print(" case DEL_INST:", file=fp)
|
||||
print(" //TODO", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" case DEL_ALL:", file=fp)
|
||||
print(" //TODO", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
fp.close()
|
||||
|
||||
def cprintBrowseObj( fbrowse, name, mappingobj, dmobject ):
|
||||
|
|
@ -482,60 +482,60 @@ def cprintBrowseObj( fbrowse, name, mappingobj, dmobject ):
|
|||
if mappingobj != None:
|
||||
type, res1, res2, res3, res4, res5 = get_mapping_obj(mappingobj)
|
||||
if type == "uci" :
|
||||
print >> fp, "/*#%s!%s:%s/%s/%s*/" % (dmobject, type.upper(), res1, res2, res3)
|
||||
print("/*#%s!%s:%s/%s/%s*/" % (dmobject, type.upper(), res1, res2, res3), file=fp)
|
||||
elif type == "ubus" :
|
||||
print >> fp, "/*#%s!%s:%s/%s/%s,%s/%s*/" % (dmobject, type.upper(), res1, res2, res3, res4, res5)
|
||||
print("/*#%s!%s:%s/%s/%s,%s/%s*/" % (dmobject, type.upper(), res1, res2, res3, res4, res5), file=fp)
|
||||
|
||||
print >> fp, "static int %s(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)" % fbrowse
|
||||
print >> fp, "{"
|
||||
print("static int %s(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)" % fbrowse, file=fp)
|
||||
print("{", file=fp)
|
||||
|
||||
# Mapping exist
|
||||
if mappingobj != None:
|
||||
|
||||
############################## UCI ########################################
|
||||
if type == "uci" :
|
||||
print >> fp, " char *inst = NULL, *max_inst = NULL;"
|
||||
print >> fp, " struct dmmap_dup *p;"
|
||||
print >> fp, " LIST_HEAD(dup_list);"
|
||||
print >> fp, ""
|
||||
print >> fp, " synchronize_specific_config_sections_with_dmmap(\"%s\", \"%s\", \"%s\", &dup_list);" % (res1, res2, res3)
|
||||
print >> fp, " list_for_each_entry(p, &dup_list, list) {"
|
||||
print >> fp, ""
|
||||
print >> fp, " inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,"
|
||||
print >> fp, " p->dmmap_section, \"%s\", \"%s\", \"%s\", \"%s\");" % (name+"instance", name+"alias", res3, res2)
|
||||
print >> fp, ""
|
||||
print >> fp, " if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " free_dmmap_config_dup_list(&dup_list);"
|
||||
print(" char *inst = NULL, *max_inst = NULL;", file=fp)
|
||||
print(" struct dmmap_dup *p;", file=fp)
|
||||
print(" LIST_HEAD(dup_list);", file=fp)
|
||||
print("", file=fp)
|
||||
print(" synchronize_specific_config_sections_with_dmmap(\"%s\", \"%s\", \"%s\", &dup_list);" % (res1, res2, res3), file=fp)
|
||||
print(" list_for_each_entry(p, &dup_list, list) {", file=fp)
|
||||
print("", file=fp)
|
||||
print(" inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,", file=fp)
|
||||
print(" p->dmmap_section, \"%s\", \"%s\", \"%s\", \"%s\");" % (name+"instance", name+"alias", res3, res2), file=fp)
|
||||
print("", file=fp)
|
||||
print(" if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" free_dmmap_config_dup_list(&dup_list);", file=fp)
|
||||
|
||||
|
||||
############################## UBUS ########################################
|
||||
elif type == "ubus" :
|
||||
print >> fp, " json_object *res = NULL, *obj = NULL, *arrobj = NULL;"
|
||||
print >> fp, " char *inst = NULL, *max_inst = NULL;"
|
||||
print >> fp, " int id = 0, i = 0;"
|
||||
print >> fp, ""
|
||||
print(" json_object *res = NULL, *obj = NULL, *arrobj = NULL;", file=fp)
|
||||
print(" char *inst = NULL, *max_inst = NULL;", file=fp)
|
||||
print(" int id = 0, i = 0;", file=fp)
|
||||
print("", file=fp)
|
||||
if res3 == None and res4 == None:
|
||||
print >> fp, " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{}, 0, &res);" % (res1, res2)
|
||||
print(" dmubus_call(\"%s\", \"%s\", UBUS_ARGS{}, 0, &res);" % (res1, res2), file=fp)
|
||||
else:
|
||||
print >> fp, " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", \"%s\", String}}, 1, &res);" % (res1, res2, res3, res4)
|
||||
print >> fp, " if (res) {"
|
||||
print >> fp, " dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, \"%s\") {" % res5
|
||||
print >> fp, ""
|
||||
print >> fp, " inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);"
|
||||
print >> fp, ""
|
||||
print >> fp, " if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " }"
|
||||
print(" dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", \"%s\", String}}, 1, &res);" % (res1, res2, res3, res4), file=fp)
|
||||
print(" if (res) {", file=fp)
|
||||
print(" dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, \"%s\") {" % res5, file=fp)
|
||||
print("", file=fp)
|
||||
print(" inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);", file=fp)
|
||||
print("", file=fp)
|
||||
print(" if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" }", file=fp)
|
||||
|
||||
# Mapping doesn't exist
|
||||
else:
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print(" //TODO", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
# Close file
|
||||
fp.close()
|
||||
|
|
@ -712,77 +712,77 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
|
|||
tmpgetvalue = get_value
|
||||
tmpsetvalue = set_value
|
||||
elif count == 2 and i == 2:
|
||||
print >> fp, "/*#%s!%s&%s*/" % (parentname+dmparam, tmpmapping, mapping)
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, "%s" % tmpgetvalue
|
||||
print >> fp, "%s" % get_value
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("/*#%s!%s&%s*/" % (parentname+dmparam, tmpmapping, mapping), file=fp)
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print("%s" % tmpgetvalue, file=fp)
|
||||
print("%s" % get_value, file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
if setvalue != "NULL":
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, "%s" % tmpsetvalue
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print("%s" % tmpsetvalue, file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
else:
|
||||
print >> fp, "/*#%s!%s*/" % (parentname+dmparam, mapping)
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, "%s" % get_value
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("/*#%s!%s*/" % (parentname+dmparam, mapping), file=fp)
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print("%s" % get_value, file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
if setvalue != "NULL":
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, "%s" % set_value
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print("%s" % set_value, file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
|
||||
# Mapping doesn't exist
|
||||
else:
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)" % getvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print(" //TODO", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
if setvalue != "NULL":
|
||||
print >> fp, "static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue
|
||||
print >> fp, "{"
|
||||
print >> fp, " switch (action) {"
|
||||
print >> fp, " case VALUECHECK:"
|
||||
print >> fp, "%s" % validate_value
|
||||
print >> fp, " break;"
|
||||
print >> fp, " case VALUESET:"
|
||||
print >> fp, " //TODO"
|
||||
print >> fp, " break;"
|
||||
print >> fp, " }"
|
||||
print >> fp, " return 0;"
|
||||
print >> fp, "}"
|
||||
print >> fp, ""
|
||||
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)" % setvalue, file=fp)
|
||||
print("{", file=fp)
|
||||
print(" switch (action) {", file=fp)
|
||||
print(" case VALUECHECK:", file=fp)
|
||||
print("%s" % validate_value, file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" case VALUESET:", file=fp)
|
||||
print(" //TODO", file=fp)
|
||||
print(" break;", file=fp)
|
||||
print(" }", file=fp)
|
||||
print(" return 0;", file=fp)
|
||||
print("}", file=fp)
|
||||
print("", file=fp)
|
||||
|
||||
# Close file
|
||||
fp.close()
|
||||
|
||||
def cprintheaderPARAMS( objname ):
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
print >> fp, "DMLEAF %s[] = {" % ("t" + getname(objname) + "Params")
|
||||
print >> fp, "/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/"
|
||||
print("DMLEAF %s[] = {" % ("t" + getname(objname) + "Params"), file=fp)
|
||||
print("/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/", file=fp)
|
||||
fp.close()
|
||||
|
||||
def hprintheaderPARAMS( objname ):
|
||||
fp = open('./.objparamarray.h', 'a')
|
||||
print >> fp, "extern DMLEAF %s[];" % ("t" + getname(objname) + "Params")
|
||||
print("extern DMLEAF %s[];" % ("t" + getname(objname) + "Params"), file=fp)
|
||||
fp.close()
|
||||
|
||||
def printPARAMline( parentname, dmparam, value ):
|
||||
|
|
@ -809,14 +809,14 @@ def printPARAMline( parentname, dmparam, value ):
|
|||
cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, parentname, dmparam, value)
|
||||
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
print >> fp, "{\"%s\", %s, %s, %s, %s, NULL, NULL, %s}," % (dmparam, access, ptype, getvalue, setvalue, bbfdm)
|
||||
print("{\"%s\", %s, %s, %s, %s, NULL, NULL, %s}," % (dmparam, access, ptype, getvalue, setvalue, bbfdm), file=fp)
|
||||
fp.close()
|
||||
|
||||
def printtailArray( ):
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
print >> fp, "{0}"
|
||||
print >> fp, "};"
|
||||
print >> fp, ""
|
||||
print("{0}", file=fp)
|
||||
print("};", file=fp)
|
||||
print("", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printOBJline( dmobject, value ):
|
||||
|
|
@ -826,7 +826,7 @@ def printOBJline( dmobject, value ):
|
|||
accessobj = getoptionparam(value, "access")
|
||||
mappingobj = getoptionparam(value, "mapping")
|
||||
bbfdm = getprotocolsparam(value, "protocols")
|
||||
uniquekeys = getuniquekeys(value, "uniqueKeys")
|
||||
uniquekeys = getuniquekeys(value, "uniqueKeys")
|
||||
|
||||
if accessobj:
|
||||
access = "&DMWRITE"
|
||||
|
|
@ -855,25 +855,25 @@ def printOBJline( dmobject, value ):
|
|||
paramarray = "NULL"
|
||||
|
||||
fp = open('./.objparamarray.c', 'a')
|
||||
if uniquekeys:
|
||||
print >> fp, "{\"%s\", %s, %s, %s, NULL, %s, NULL, NULL, NULL, %s, %s, NULL, %s, %s}," % (getlastname(dmobject), access, faddobj, fdelobj, fbrowse, objchildarray, paramarray, bbfdm, uniquekeys)
|
||||
else:
|
||||
print >> fp, "{\"%s\", %s, %s, %s, NULL, %s, NULL, NULL, NULL, %s, %s, NULL, %s}," % (getlastname(dmobject), access, faddobj, fdelobj, fbrowse, objchildarray, paramarray, bbfdm)
|
||||
if uniquekeys:
|
||||
print("{\"%s\", %s, %s, %s, NULL, %s, NULL, NULL, NULL, %s, %s, NULL, %s, %s}," % (getlastname(dmobject), access, faddobj, fdelobj, fbrowse, objchildarray, paramarray, bbfdm, uniquekeys), file=fp)
|
||||
else:
|
||||
print("{\"%s\", %s, %s, %s, NULL, %s, NULL, NULL, NULL, %s, %s, NULL, %s}," % (getlastname(dmobject), access, faddobj, fdelobj, fbrowse, objchildarray, paramarray, bbfdm), file=fp)
|
||||
fp.close()
|
||||
|
||||
def printusage():
|
||||
print "Usage: " + sys.argv[0] + " <json data model>" + " [Object path]"
|
||||
print "Examples:"
|
||||
print " - " + sys.argv[0] + " tr181.json"
|
||||
print " ==> Generate the C code of all data model in tr181/ folder"
|
||||
print " - " + sys.argv[0] + " tr104.json"
|
||||
print " ==> Generate the C code of all data model in tr104/ folder"
|
||||
print " - " + sys.argv[0] + " tr181.json" + " Device.DeviceInfo."
|
||||
print " ==> Generate the C code of DeviceInfo object in tr181/ folder"
|
||||
print " - " + sys.argv[0] + " tr181.json" + " Device.WiFi."
|
||||
print " ==> Generate the C code of WiFi object in tr181/ folder"
|
||||
print " - " + sys.argv[0] + " tr104.json" + " Device.Services.VoiceService.{i}.Capabilities."
|
||||
print " ==> Generate the C code of Services.VoiceService.{i}.Capabilities. object in tr104/ folder"
|
||||
print("Usage: " + sys.argv[0] + " <json data model>" + " [Object path]")
|
||||
print("Examples:")
|
||||
print(" - " + sys.argv[0] + " tr181.json")
|
||||
print(" ==> Generate the C code of all data model in tr181/ folder")
|
||||
print(" - " + sys.argv[0] + " tr104.json")
|
||||
print(" ==> Generate the C code of all data model in tr104/ folder")
|
||||
print(" - " + sys.argv[0] + " tr181.json" + " Device.DeviceInfo.")
|
||||
print(" ==> Generate the C code of DeviceInfo object in tr181/ folder")
|
||||
print(" - " + sys.argv[0] + " tr181.json" + " Device.WiFi.")
|
||||
print(" ==> Generate the C code of WiFi object in tr181/ folder")
|
||||
print(" - " + sys.argv[0] + " tr104.json" + " Device.Services.VoiceService.{i}.Capabilities.")
|
||||
print(" ==> Generate the C code of Services.VoiceService.{i}.Capabilities. object in tr104/ folder")
|
||||
|
||||
def object_parse_childs( dmobject , value, nextlevel ):
|
||||
hasobj = objhaschild(value)
|
||||
|
|
@ -930,9 +930,9 @@ def generatecfromobj( pobj, pvalue, pdir, nextlevel ):
|
|||
try:
|
||||
exists = os.path.isfile("./.objbrowse.c")
|
||||
if exists:
|
||||
print >> dmfpc, "/*************************************************************"
|
||||
print >> dmfpc, "* ENTRY METHOD"
|
||||
print >> dmfpc, "**************************************************************/"
|
||||
print("/*************************************************************", file=dmfpc)
|
||||
print("* ENTRY METHOD", file=dmfpc)
|
||||
print("**************************************************************/", file=dmfpc)
|
||||
tmpf = open("./.objbrowse.c", "r")
|
||||
tmpd = tmpf.read()
|
||||
tmpf.close()
|
||||
|
|
@ -942,9 +942,9 @@ def generatecfromobj( pobj, pvalue, pdir, nextlevel ):
|
|||
try:
|
||||
exists = os.path.isfile("./.objadddel.c")
|
||||
if exists:
|
||||
print >> dmfpc, "/*************************************************************"
|
||||
print >> dmfpc, "* ADD & DEL OBJ"
|
||||
print >> dmfpc, "**************************************************************/"
|
||||
print("/*************************************************************", file=dmfpc)
|
||||
print("* ADD & DEL OBJ", file=dmfpc)
|
||||
print("**************************************************************/", file=dmfpc)
|
||||
tmpf = open("./.objadddel.c", "r")
|
||||
tmpd = tmpf.read()
|
||||
tmpf.close()
|
||||
|
|
@ -954,9 +954,9 @@ def generatecfromobj( pobj, pvalue, pdir, nextlevel ):
|
|||
try:
|
||||
exists = os.path.isfile("./.getstevalue.c")
|
||||
if exists:
|
||||
print >> dmfpc, "/*************************************************************"
|
||||
print >> dmfpc, "* GET & SET PARAM"
|
||||
print >> dmfpc, "**************************************************************/"
|
||||
print("/*************************************************************", file=dmfpc)
|
||||
print("* GET & SET PARAM", file=dmfpc)
|
||||
print("**************************************************************/", file=dmfpc)
|
||||
tmpf = open("./.getstevalue.c", "r")
|
||||
tmpd = tmpf.read()
|
||||
tmpf.close()
|
||||
|
|
@ -964,9 +964,9 @@ def generatecfromobj( pobj, pvalue, pdir, nextlevel ):
|
|||
except:
|
||||
pass
|
||||
try:
|
||||
print >> dmfpc, "/**********************************************************************************************************************************"
|
||||
print >> dmfpc, "* OBJ & PARAM DEFINITION"
|
||||
print >> dmfpc, "***********************************************************************************************************************************/"
|
||||
print("/**********************************************************************************************************************************", file=dmfpc)
|
||||
print("* OBJ & PARAM DEFINITION", file=dmfpc)
|
||||
print("***********************************************************************************************************************************/", file=dmfpc)
|
||||
tmpf = open("./.objparamarray.c", "r")
|
||||
tmpd = tmpf.read()
|
||||
tmpf.close()
|
||||
|
|
@ -1020,7 +1020,7 @@ else:
|
|||
|
||||
for obj, value in data.items():
|
||||
if obj == None:
|
||||
print "Wrong JSON Data model format!"
|
||||
print("Wrong JSON Data model format!")
|
||||
exit(1)
|
||||
|
||||
# Generate the object file if it is defined by "sys.argv[2]" argument
|
||||
|
|
@ -1049,6 +1049,6 @@ for obj, value in data.items():
|
|||
generatecfromobj(obj1, value1, gendir, 0)
|
||||
|
||||
if (os.path.isdir(gendir)):
|
||||
print "Source code generated under \"./%s\" folder" % gendir
|
||||
print("Source code generated under \"./%s\" folder" % gendir)
|
||||
else:
|
||||
print "No source code generated!"
|
||||
print("No source code generated!")
|
||||
|
|
|
|||
|
|
@ -307,110 +307,110 @@ def getuniquekeys (dmobject):
|
|||
def printopenobject (obj):
|
||||
fp = open('./.json_tmp', 'a')
|
||||
if "tr-104" in sys.argv[1]:
|
||||
print >> fp, "\"Device.Services.%s\" : {" % obj.get('name').replace(" ", "")
|
||||
print("\"Device.Services.%s\" : {" % obj.get('name').replace(" ", ""), file=fp)
|
||||
else:
|
||||
print >> fp, "\"%s\" : {" % obj.get('name').replace(" ", "")
|
||||
print("\"%s\" : {" % obj.get('name').replace(" ", ""), file=fp)
|
||||
fp.close()
|
||||
|
||||
def printopenfile ():
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "{"
|
||||
print("{", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printclosefile ():
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "}"
|
||||
print("}", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printOBJMaPPING (mapping):
|
||||
fp = open('./.json_tmp', 'a')
|
||||
config_type = mapping.split(":")
|
||||
config = config_type[1].split("/")
|
||||
print >> fp, "\"mapping\": {"
|
||||
print >> fp, "\"type\": \"%s\"," % config_type[0].lower()
|
||||
print >> fp, "\"%s\": {" % config_type[0].lower()
|
||||
print("\"mapping\": {", file=fp)
|
||||
print("\"type\": \"%s\"," % config_type[0].lower(), file=fp)
|
||||
print("\"%s\": {" % config_type[0].lower(), file=fp)
|
||||
|
||||
# UCI
|
||||
if config_type[0] == "UCI":
|
||||
print >> fp, "\"file\": \"%s\"," % config[0]
|
||||
print >> fp, "\"section\": {"
|
||||
print >> fp, "\"type\": \"%s\"" % config[1]
|
||||
print >> fp, "},"
|
||||
print >> fp, "\"dmmapfile\": \"%s\"" % config[2]
|
||||
print("\"file\": \"%s\"," % config[0], file=fp)
|
||||
print("\"section\": {", file=fp)
|
||||
print("\"type\": \"%s\"" % config[1], file=fp)
|
||||
print("},", file=fp)
|
||||
print("\"dmmapfile\": \"%s\"" % config[2], file=fp)
|
||||
|
||||
# UBUS
|
||||
elif config_type[0] == "UBUS":
|
||||
print >> fp, "\"object\": \"%s\"," % config[0]
|
||||
print >> fp, "\"method\": \"%s\"," % config[1]
|
||||
print >> fp, "\"args\": {"
|
||||
print("\"object\": \"%s\"," % config[0], file=fp)
|
||||
print("\"method\": \"%s\"," % config[1], file=fp)
|
||||
print("\"args\": {", file=fp)
|
||||
if config[2] != "":
|
||||
args = config[2].split(",")
|
||||
print >> fp, "\"%s\": \"%s\"" % (args[0], args[1])
|
||||
print >> fp, "}"
|
||||
print >> fp, "\"key\": \"%s\"" % config[3]
|
||||
print("\"%s\": \"%s\"" % (args[0], args[1]), file=fp)
|
||||
print("}", file=fp)
|
||||
print("\"key\": \"%s\"" % config[3], file=fp)
|
||||
|
||||
print >> fp, "}\n}"
|
||||
print("}\n}", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printPARAMMaPPING (mapping):
|
||||
fp = open('./.json_tmp', 'a')
|
||||
lst = mapping.split("&")
|
||||
print >> fp, "\"mapping\": ["
|
||||
print("\"mapping\": [", file=fp)
|
||||
for i in range(len(lst)):
|
||||
config_type = lst[i].split(":")
|
||||
config = config_type[1].split("/")
|
||||
|
||||
print >> fp, "{"
|
||||
print >> fp, "\"type\": \"%s\"," % config_type[0].lower()
|
||||
print("{", file=fp)
|
||||
print("\"type\": \"%s\"," % config_type[0].lower(), file=fp)
|
||||
|
||||
# SYSFS || PROCFS
|
||||
if config_type[0] == "SYSFS" or config_type[0] == "PROCFS":
|
||||
print >> fp, "\"file\": \"%s\"" % config_type[1]
|
||||
print("\"file\": \"%s\"" % config_type[1], file=fp)
|
||||
|
||||
# UCI, UBUS, CLI
|
||||
else:
|
||||
# Only for UCI, UBUS, CLI
|
||||
print >> fp, "\"%s\": {" % config_type[0].lower()
|
||||
print("\"%s\": {" % config_type[0].lower(), file=fp)
|
||||
|
||||
# UCI
|
||||
if config_type[0] == "UCI":
|
||||
print >> fp, "\"file\": \"%s\"," % config[0]
|
||||
print >> fp, "\"section\": {"
|
||||
print("\"file\": \"%s\"," % config[0], file=fp)
|
||||
print("\"section\": {", file=fp)
|
||||
var = config[1].split(",")
|
||||
if len(var) == 1:
|
||||
print >> fp, "\"type\": \"%s\"" % var[0]
|
||||
print("\"type\": \"%s\"" % var[0], file=fp)
|
||||
elif len(var) > 1 and "@i" in var[1]:
|
||||
print >> fp, "\"type\": \"%s\"," % var[0]
|
||||
print >> fp, "\"index\": \"%s\"" % var[1]
|
||||
print("\"type\": \"%s\"," % var[0], file=fp)
|
||||
print("\"index\": \"%s\"" % var[1], file=fp)
|
||||
elif len(var) > 1:
|
||||
print >> fp, "\"type\": \"%s\"," % var[0]
|
||||
print >> fp, "\"name\": \"%s\"" % var[1]
|
||||
print >> fp, "}"
|
||||
print("\"type\": \"%s\"," % var[0], file=fp)
|
||||
print("\"name\": \"%s\"" % var[1], file=fp)
|
||||
print("}", file=fp)
|
||||
if len(var) > 1:
|
||||
print >> fp, "\"option\": {"
|
||||
print >> fp, "\"name\": \"%s\"" % config[2]
|
||||
print >> fp, "}"
|
||||
print("\"option\": {", file=fp)
|
||||
print("\"name\": \"%s\"" % config[2], file=fp)
|
||||
print("}", file=fp)
|
||||
|
||||
# UBUS
|
||||
elif config_type[0] == "UBUS":
|
||||
print >> fp, "\"object\": \"%s\"," % config[0]
|
||||
print >> fp, "\"method\": \"%s\"," % config[1]
|
||||
print >> fp, "\"args\": {"
|
||||
print("\"object\": \"%s\"," % config[0], file=fp)
|
||||
print("\"method\": \"%s\"," % config[1], file=fp)
|
||||
print("\"args\": {", file=fp)
|
||||
if config[2] != "":
|
||||
args = config[2].split(",")
|
||||
print >> fp, "\"%s\": \"%s\"" % (args[0], args[1])
|
||||
print >> fp, "}"
|
||||
print >> fp, "\"key\": \"%s\"" % config[3]
|
||||
print("\"%s\": \"%s\"" % (args[0], args[1]), file=fp)
|
||||
print("}", file=fp)
|
||||
print("\"key\": \"%s\"" % config[3], file=fp)
|
||||
|
||||
# CLI
|
||||
elif config_type[0] == "CLI":
|
||||
print >> fp, "\"command\": \"%s\"," % config[0]
|
||||
print >> fp, "\"args\": \"%s\"" % config[1]
|
||||
print("\"command\": \"%s\"," % config[0], file=fp)
|
||||
print("\"args\": \"%s\"" % config[1], file=fp)
|
||||
|
||||
print >> fp, "}"
|
||||
print("}", file=fp)
|
||||
|
||||
print >> fp, "}"
|
||||
print >> fp, "]\n}"
|
||||
print("}", file=fp)
|
||||
print("]\n}", file=fp)
|
||||
fp.close()
|
||||
|
||||
def removelastline ():
|
||||
|
|
@ -457,18 +457,18 @@ def printOBJ( dmobject, hasobj, hasparam, bbfdm_type ):
|
|||
fbrowse = "false"
|
||||
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "\"type\" : \"object\","
|
||||
print >> fp, "\"protocols\" : [%s]," % bbfdm_type
|
||||
print("\"type\" : \"object\",", file=fp)
|
||||
print("\"protocols\" : [%s]," % bbfdm_type, file=fp)
|
||||
if uniquekeys != None:
|
||||
print >> fp, "\"uniqueKeys\" : [%s]," % uniquekeys
|
||||
print("\"uniqueKeys\" : [%s]," % uniquekeys, file=fp)
|
||||
if (dmobject.get('access') == "readOnly"):
|
||||
print >> fp, "\"access\" : false,"
|
||||
print("\"access\" : false,", file=fp)
|
||||
else:
|
||||
print >> fp, "\"access\" : true,"
|
||||
print("\"access\" : true,", file=fp)
|
||||
if hasparam or hasobj:
|
||||
print >> fp, "\"array\" : %s," % fbrowse
|
||||
print("\"array\" : %s," % fbrowse, file=fp)
|
||||
else:
|
||||
print >> fp, "\"array\" : %s" % fbrowse
|
||||
print("\"array\" : %s" % fbrowse, file=fp)
|
||||
fp.close()
|
||||
if hasmapping:
|
||||
printOBJMaPPING (mapping)
|
||||
|
|
@ -478,88 +478,88 @@ def printPARAM( dmparam, dmobject, bbfdm_type ):
|
|||
islist, datatype, paramvalrange, paramenum, paramunit, parampattern, listminItem, listmaxItem, listmaxsize = getparamoption(dmparam)
|
||||
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "\"%s\" : {" % dmparam.get('name').replace(" ", "")
|
||||
print >> fp, "\"type\" : \"%s\"," % getparamtype(dmparam)
|
||||
print >> fp, "\"read\" : true,"
|
||||
print >> fp, "\"write\" : %s," % ("false" if dmparam.get('access') == "readOnly" else "true")
|
||||
print >> fp, "\"protocols\" : [%s]," % bbfdm_type
|
||||
print("\"%s\" : {" % dmparam.get('name').replace(" ", ""), file=fp)
|
||||
print("\"type\" : \"%s\"," % getparamtype(dmparam), file=fp)
|
||||
print("\"read\" : true,", file=fp)
|
||||
print("\"write\" : %s," % ("false" if dmparam.get('access') == "readOnly" else "true"), file=fp)
|
||||
print("\"protocols\" : [%s]," % bbfdm_type, file=fp)
|
||||
|
||||
# create list
|
||||
if islist == 1:
|
||||
print >> fp, "\"list\" : {"
|
||||
print("\"list\" : {", file=fp)
|
||||
|
||||
# add datatype
|
||||
print >> fp, ("\"datatype\" : \"%s\"," % datatype) if (listmaxsize != None or listminItem != None or listmaxItem != None or paramvalrange != None or paramunit != None or paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("\"datatype\" : \"%s\"" % datatype)
|
||||
print(("\"datatype\" : \"%s\"," % datatype) if (listmaxsize != None or listminItem != None or listmaxItem != None or paramvalrange != None or paramunit != None or paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("\"datatype\" : \"%s\"" % datatype), file=fp)
|
||||
|
||||
if islist == 1:
|
||||
# add maximum size of list
|
||||
if listmaxsize != None:
|
||||
print >> fp, ("\"maxsize\" : %s," % listmaxsize) if (listminItem != None or listmaxItem != None or paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("\"maxsize\" : %s" % listmaxsize)
|
||||
print(("\"maxsize\" : %s," % listmaxsize) if (listminItem != None or listmaxItem != None or paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("\"maxsize\" : %s" % listmaxsize), file=fp)
|
||||
|
||||
# add minimun and maximum item values
|
||||
if listminItem != None and listmaxItem != None:
|
||||
print >> fp, "\"item\" : {"
|
||||
print >> fp, "\"min\" : %s," % listminItem
|
||||
print >> fp, "\"max\" : %s" % listmaxItem
|
||||
print >> fp, ("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}")
|
||||
print("\"item\" : {", file=fp)
|
||||
print("\"min\" : %s," % listminItem, file=fp)
|
||||
print("\"max\" : %s" % listmaxItem, file=fp)
|
||||
print(("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}"), file=fp)
|
||||
elif listminItem != None and listmaxItem == None:
|
||||
print >> fp, "\"item\" : {"
|
||||
print >> fp, "\"min\" : %s" % listminItem
|
||||
print >> fp, ("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}")
|
||||
print("\"item\" : {", file=fp)
|
||||
print("\"min\" : %s" % listminItem, file=fp)
|
||||
print(("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}"), file=fp)
|
||||
elif listminItem == None and listmaxItem != None:
|
||||
print >> fp, "\"item\" : {"
|
||||
print >> fp, "\"max\" : %s" % listmaxItem
|
||||
print >> fp, ("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}")
|
||||
print("\"item\" : {", file=fp)
|
||||
print("\"max\" : %s" % listmaxItem, file=fp)
|
||||
print(("},") if (paramvalrange != None or paramunit != None or paramenum != None or parampattern != None) else ("}"), file=fp)
|
||||
|
||||
# add minimun and maximum values
|
||||
if paramvalrange != None:
|
||||
valranges = paramvalrange.split(";")
|
||||
print >> fp, "\"range\" : ["
|
||||
print("\"range\" : [", file=fp)
|
||||
for eachvalrange in valranges:
|
||||
valrange = eachvalrange.split(",")
|
||||
if valrange[0] != "None" and valrange[1] != "None":
|
||||
print >> fp, "{"
|
||||
print >> fp, "\"min\" : %s," % valrange[0]
|
||||
print >> fp, "\"max\" : %s" % valrange[1]
|
||||
print >> fp, ("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}")
|
||||
print("{", file=fp)
|
||||
print("\"min\" : %s," % valrange[0], file=fp)
|
||||
print("\"max\" : %s" % valrange[1], file=fp)
|
||||
print(("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}"), file=fp)
|
||||
elif valrange[0] != "None" and valrange[1] == "None":
|
||||
print >> fp, "{"
|
||||
print >> fp, "\"min\" : %s" % valrange[0]
|
||||
print >> fp, ("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}")
|
||||
print("{", file=fp)
|
||||
print("\"min\" : %s" % valrange[0], file=fp)
|
||||
print(("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}"), file=fp)
|
||||
elif valrange[0] == "None" and valrange[1] != "None":
|
||||
print >> fp, "{"
|
||||
print >> fp, "\"max\" : %s" % valrange[1]
|
||||
print >> fp, ("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}")
|
||||
print >> fp, ("],") if (paramunit != None or paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("]")
|
||||
print("{", file=fp)
|
||||
print("\"max\" : %s" % valrange[1], file=fp)
|
||||
print(("},") if (eachvalrange == valranges[len(valranges)-1]) else ("}"), file=fp)
|
||||
print(("],") if (paramunit != None or paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("]"), file=fp)
|
||||
|
||||
# add unit
|
||||
if paramunit != None:
|
||||
print >> fp, ("\"unit\" : \"%s\"," % paramunit) if (paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("\"unit\" : \"%s\"" % paramunit)
|
||||
print(("\"unit\" : \"%s\"," % paramunit) if (paramenum != None or parampattern != None or (hasmapping and islist == 0)) else ("\"unit\" : \"%s\"" % paramunit), file=fp)
|
||||
|
||||
# add enumaration
|
||||
if paramenum != None:
|
||||
print >> fp, ("\"enumerations\" : [%s]," % paramenum) if (parampattern != None or (hasmapping and islist == 0)) else ("\"enumerations\" : [%s]" % paramenum)
|
||||
print(("\"enumerations\" : [%s]," % paramenum) if (parampattern != None or (hasmapping and islist == 0)) else ("\"enumerations\" : [%s]" % paramenum), file=fp)
|
||||
|
||||
# add pattern
|
||||
if parampattern != None:
|
||||
print >> fp, ("\"pattern\" : [%s]," % parampattern.replace("\\", "\\\\")) if (hasmapping and islist == 0) else ("\"pattern\" : [%s]" % parampattern.replace("\\", "\\\\"))
|
||||
print(("\"pattern\" : [%s]," % parampattern.replace("\\", "\\\\")) if (hasmapping and islist == 0) else ("\"pattern\" : [%s]" % parampattern.replace("\\", "\\\\")), file=fp)
|
||||
|
||||
# close list
|
||||
if islist == 1:
|
||||
print >> fp, ("},") if hasmapping else ("}")
|
||||
print(("},") if hasmapping else ("}"), file=fp)
|
||||
|
||||
# add mapping
|
||||
if hasmapping:
|
||||
fp.close()
|
||||
printPARAMMaPPING(mapping)
|
||||
else:
|
||||
print >> fp, "}"
|
||||
print("}", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printCOMMAND( dmparam, dmobject, bbfdm_type ):
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "\"%s\" : {" % dmparam.get('name')
|
||||
print >> fp, "\"type\" : \"command\","
|
||||
print("\"%s\" : {" % dmparam.get('name'), file=fp)
|
||||
print("\"type\" : \"command\",", file=fp)
|
||||
inputfound = 0
|
||||
outputfound = 0
|
||||
for c in dmparam:
|
||||
|
|
@ -568,41 +568,41 @@ def printCOMMAND( dmparam, dmobject, bbfdm_type ):
|
|||
elif c.tag == "output":
|
||||
outputfound = 1
|
||||
|
||||
print >> fp, ("\"protocols\" : [\"usp\"],") if (inputfound or outputfound) else ("\"protocols\" : [\"usp\"]")
|
||||
print(("\"protocols\" : [\"usp\"],") if (inputfound or outputfound) else ("\"protocols\" : [\"usp\"]"), file=fp)
|
||||
|
||||
for c in dmparam:
|
||||
if c.tag == "input":
|
||||
print >> fp, "\"input\" : {"
|
||||
print("\"input\" : {", file=fp)
|
||||
for param in c:
|
||||
if param.tag == "parameter":
|
||||
fp.close()
|
||||
printPARAM(param, dmobject, "\"usp\"")
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "}" if outputfound else "},"
|
||||
print("}" if outputfound else "},", file=fp)
|
||||
|
||||
if c.tag == "output":
|
||||
print >> fp, "\"output\" : {"
|
||||
print("\"output\" : {", file=fp)
|
||||
for param in c:
|
||||
if param.tag == "parameter":
|
||||
fp.close()
|
||||
printPARAM(param, dmobject, "\"usp\"")
|
||||
fp = open('./.json_tmp', 'a')
|
||||
print >> fp, "}"
|
||||
print("}", file=fp)
|
||||
|
||||
print >> fp, "}"
|
||||
print("}", file=fp)
|
||||
fp.close()
|
||||
|
||||
def printusage():
|
||||
print "Usage: " + sys.argv[0] + " <tr-xxx cwmp xml data model> <tr-xxx usp xml data model> [Object path]"
|
||||
print "Examples:"
|
||||
print " - " + sys.argv[0] + " tr-181-2-13-0-cwmp-full.xml tr-181-2-13-0-usp-full.xml Device."
|
||||
print " ==> Generate the json file of the sub tree Device. in tr181.json"
|
||||
print " - " + sys.argv[0] + " tr-104-2-0-2-cwmp-full.xml tr-104-2-0-2-usp-full.xml Device.Services.VoiceService."
|
||||
print " ==> Generate the json file of the sub tree Device.Services.VoiceService. in tr104.json"
|
||||
print " - " + sys.argv[0] + " tr-106-1-2-0-full.xml Device."
|
||||
print " ==> Generate the json file of the sub tree Device. in tr106.json"
|
||||
print ""
|
||||
print "Example of xml data model file: https://www.broadband-forum.org/cwmp/tr-181-2-13-0-cwmp-full.xml"
|
||||
print("Usage: " + sys.argv[0] + " <tr-xxx cwmp xml data model> <tr-xxx usp xml data model> [Object path]")
|
||||
print("Examples:")
|
||||
print(" - " + sys.argv[0] + " tr-181-2-13-0-cwmp-full.xml tr-181-2-13-0-usp-full.xml Device.")
|
||||
print(" ==> Generate the json file of the sub tree Device. in tr181.json")
|
||||
print(" - " + sys.argv[0] + " tr-104-2-0-2-cwmp-full.xml tr-104-2-0-2-usp-full.xml Device.Services.VoiceService.")
|
||||
print(" ==> Generate the json file of the sub tree Device.Services.VoiceService. in tr104.json")
|
||||
print(" - " + sys.argv[0] + " tr-106-1-2-0-full.xml Device.")
|
||||
print(" ==> Generate the json file of the sub tree Device. in tr106.json")
|
||||
print("")
|
||||
print("Example of xml data model file: https://www.broadband-forum.org/cwmp/tr-181-2-13-0-cwmp-full.xml")
|
||||
exit(1)
|
||||
|
||||
def getobjectpointer( objname ):
|
||||
|
|
@ -751,10 +751,10 @@ def generatejsonfromobj(pobj, pdir):
|
|||
f = open("./.json_tmp", "r")
|
||||
obj = json.load(f, object_pairs_hook=OrderedDict)
|
||||
dump = json.dumps(obj, indent=4)
|
||||
tabs = re.sub('\n +', lambda match: '\n' + '\t' * (len(match.group().strip('\n')) / 4), dump)
|
||||
tabs = re.sub('\n +', lambda match: '\n' + '\t' * int(len(match.group().strip('\n')) / 4), dump)
|
||||
|
||||
try:
|
||||
print >> dmfp, "%s" % tabs
|
||||
print("%s" % tabs, file=dmfp)
|
||||
dmfp.close()
|
||||
except:
|
||||
pass
|
||||
|
|
@ -782,7 +782,7 @@ for child in model1:
|
|||
model1 = child
|
||||
|
||||
if model1.tag != "model":
|
||||
print "Wrong %s XML Data model format!" % sys.argv[1]
|
||||
print("Wrong %s XML Data model format!" % sys.argv[1])
|
||||
exit(1)
|
||||
|
||||
dmroot1 = None
|
||||
|
|
@ -800,7 +800,7 @@ if dmroot1 == None:
|
|||
break
|
||||
|
||||
if dmroot1 == None:
|
||||
print "Wrong %s XML Data model format!" % sys.argv[1]
|
||||
print("Wrong %s XML Data model format!" % sys.argv[1])
|
||||
exit(1)
|
||||
|
||||
if "tr-181" in sys.argv[1] or "tr-104" in sys.argv[1]:
|
||||
|
|
@ -813,7 +813,7 @@ if "tr-181" in sys.argv[1] or "tr-104" in sys.argv[1]:
|
|||
model2 = child
|
||||
|
||||
if model2.tag != "model":
|
||||
print "Wrong %s XML Data model format!" % sys.argv[2]
|
||||
print("Wrong %s XML Data model format!" % sys.argv[2])
|
||||
exit(1)
|
||||
|
||||
dmroot2 = None
|
||||
|
|
@ -830,7 +830,7 @@ if "tr-181" in sys.argv[1] or "tr-104" in sys.argv[1]:
|
|||
break
|
||||
|
||||
if dmroot2 == None:
|
||||
print "Wrong %s XML Data model format!" % sys.argv[2]
|
||||
print("Wrong %s XML Data model format!" % sys.argv[2])
|
||||
exit(1)
|
||||
|
||||
Root = sys.argv[3]
|
||||
|
|
@ -848,7 +848,7 @@ else:
|
|||
objstart = getobjectpointer(Root)
|
||||
|
||||
if objstart == None:
|
||||
print "Wrong Object Name! %s" % Root
|
||||
print("Wrong Object Name! %s" % Root)
|
||||
exit(1)
|
||||
|
||||
filename = generatejsonfromobj(objstart, gendir)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue