test: Fix pep8 errors on tools

This commit is contained in:
vdutta 2021-08-24 20:59:05 +05:30
parent ec78e61128
commit 49a0528eb2
6 changed files with 58 additions and 58 deletions

View file

@ -114,7 +114,7 @@ def clean_supported_dm_list():
LIST_SUPPORTED_DM.clear()
def fill_list_supported_dm():
fp = open(DATA_MODEL_FILE, 'r')
fp = open(DATA_MODEL_FILE, 'r', encoding='utf-8')
Lines = fp.readlines()
for line in Lines:
@ -122,7 +122,7 @@ def fill_list_supported_dm():
def fill_data_model_file():
fp = open(DATA_MODEL_FILE, 'a')
fp = open(DATA_MODEL_FILE, 'a', encoding='utf-8')
for value in LIST_SUPPORTED_DM:
print("%s" % value, file=fp)
fp.close()
@ -138,7 +138,7 @@ def generate_datamodel_tree(filename):
table_name = ""
parent_obj = ""
fp = open(filename, 'r')
fp = open(filename, 'r', encoding='utf-8')
for line in fp:
if "DMOBJ" in line:
@ -225,7 +225,7 @@ def generate_dynamic_datamodel_tree(filename):
obj_found = 0
fp = open(filename, 'r')
fp = open(filename, 'r', encoding='utf-8')
for line in fp:
if "DM_MAP_OBJ" in line:
@ -289,7 +289,7 @@ def generate_dynamic_json_datamodel_tree(filename):
if filename.endswith('.json') is False:
return
json_file = open(filename, "r")
json_file = open(filename, "r", encoding='utf-8')
data = json.loads(json_file.read(), object_pairs_hook=OrderedDict)
for obj, value in data.items():

View file

@ -115,7 +115,7 @@ def get_mapping_param(mappingobj):
def printGlobalstrCommon(str_exp):
fp = open(DMC_DIR + "/common.c", 'a')
fp = open(DMC_DIR + "/common.c", 'a', encoding='utf-8')
print("%s" % str_exp, file=fp)
fp.close()
@ -327,20 +327,20 @@ def generate_validate_value(dmparam, value):
def printheaderObjCommon(objname):
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("/* *** %s *** */" % objname, file=fp)
fp.close()
def cprintheaderOBJS(objname):
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("DMOBJ %s[] = {" % ("t" + getname(objname) + "Obj"), file=fp)
print("/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/", file=fp)
fp.close()
def hprintheaderOBJS(objname):
fp = open('./.objparamarray.h', 'a')
fp = open('./.objparamarray.h', 'a', encoding='utf-8')
print("extern DMOBJ %s[];" % ("t" + getname(objname) + "Obj"), file=fp)
fp.close()
@ -385,7 +385,7 @@ def hprintfootfile(fp, filename):
def cprintAddDelObj(faddobj, fdelobj, name, mappingobj, _dmobject):
fp = open('./.objadddel.c', 'a')
fp = open('./.objadddel.c', 'a', encoding='utf-8')
print("static int %s(char *refparam, struct dmctx *ctx, void *data, char **instance)" %
faddobj, file=fp)
print("{", file=fp)
@ -468,7 +468,7 @@ def cprintAddDelObj(faddobj, fdelobj, name, mappingobj, _dmobject):
def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
# Open file
fp = open('./.objbrowse.c', 'a')
fp = open('./.objbrowse.c', 'a', encoding='utf-8')
# Mapping Parameter
if mappingobj is not None:
@ -543,7 +543,7 @@ def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, parentname, dmparam, value):
# Open file
fp = open('./.getstevalue.c', 'a')
fp = open('./.getstevalue.c', 'a', encoding='utf-8')
# Generate Validate value
validate_value = ""
@ -800,7 +800,7 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
def cprintOperateCommands(getoperateargs, operate, in_args, out_args, struct_name):
# Open file
fp = open('./.operatecommands.c', 'a')
fp = open('./.operatecommands.c', 'a', encoding='utf-8')
if in_args != None or out_args != None:
############################## OPERATE ARGUMENTS ########################################
@ -846,7 +846,7 @@ def cprintOperateCommands(getoperateargs, operate, in_args, out_args, struct_nam
def cprintEvent(geteventargs, param_args, struct_name):
# Open file
fp = open('./.events.c', 'a')
fp = open('./.events.c', 'a', encoding='utf-8')
if param_args != None:
############################## OPERATE ARGUMENTS ########################################
@ -873,14 +873,14 @@ def cprintEvent(geteventargs, param_args, struct_name):
def cprintheaderPARAMS(objname):
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("DMLEAF %s[] = {" % ("t" + getname(objname) + "Params"), file=fp)
print("/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/", file=fp)
fp.close()
def hprintheaderPARAMS(objname):
fp = open('./.objparamarray.h', 'a')
fp = open('./.objparamarray.h', 'a', encoding='utf-8')
print("extern DMLEAF %s[];" % ("t" + getname(objname) + "Params"), file=fp)
fp.close()
@ -909,7 +909,7 @@ def printPARAMline(parentname, dmparam, value):
cprintGetSetValue(getvalue, setvalue, mappingparam,
instance, typeparam, parentname, dmparam, value)
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("{\"%s\", %s, %s, %s, %s, %s}," %
(dmparam, access, ptype, getvalue, setvalue, bbfdm), file=fp)
fp.close()
@ -936,7 +936,7 @@ def printCOMMANDline( parentname, dmparam, value ):
cprintOperateCommands(getoperateargs, operate, in_args, out_args, commonname.replace("()", "").lower()+"_args")
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("{\"%s\", %s, %s, %s, %s, %s}," % (dmparam, c_type, ptype, getoperateargs, operate, bbfdm), file=fp)
fp.close()
@ -953,13 +953,13 @@ def printEVENTline( parentname, dmparam, value ):
else:
geteventargs = "NULL"
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("{\"%s\", &DMREAD, %s, %s, NULL, %s}," % (dmparam, ptype, geteventargs, bbfdm), file=fp)
fp.close()
def printtailArray():
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
print("{0}", file=fp)
print("};", file=fp)
print("", file=fp)
@ -1003,7 +1003,7 @@ def printOBJline(dmobject, value):
else:
paramarray = "NULL"
fp = open('./.objparamarray.c', 'a')
fp = open('./.objparamarray.c', 'a', encoding='utf-8')
if uniquekeys:
print("{\"%s\", %s, %s, %s, NULL, %s, NULL, NULL, %s, %s, NULL, %s, %s}," % (getlastname(
dmobject), access, faddobj, fdelobj, fbrowse, objchildarray, paramarray, bbfdm, uniquekeys), file=fp)
@ -1089,8 +1089,8 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
removetmpfiles()
object_parse_childs(pobj, pvalue, nextlevel)
dmfpc = open(pdir + "/" + getname(pobj).lower() + ".c", "w")
dmfph = open(pdir + "/" + getname(pobj).lower() + ".h", "w")
dmfpc = open(pdir + "/" + getname(pobj).lower() + ".c", "w", encoding='utf-8')
dmfph = open(pdir + "/" + getname(pobj).lower() + ".h", "w", encoding='utf-8')
cprinttopfile(dmfpc, getname(pobj).lower())
hprinttopfile(dmfph, getname(pobj).lower())
@ -1102,7 +1102,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("* ENTRY METHOD", file=dmfpc)
print(
"**************************************************************/", file=dmfpc)
tmpf = open("./.objbrowse.c", "r")
tmpf = open("./.objbrowse.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1117,7 +1117,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("* ADD & DEL OBJ", file=dmfpc)
print(
"**************************************************************/", file=dmfpc)
tmpf = open("./.objadddel.c", "r")
tmpf = open("./.objadddel.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1132,7 +1132,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("* GET & SET PARAM", file=dmfpc)
print(
"**************************************************************/", file=dmfpc)
tmpf = open("./.getstevalue.c", "r")
tmpf = open("./.getstevalue.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1145,7 +1145,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("/*************************************************************", file=dmfpc)
print("* OPERATE COMMANDS", file=dmfpc)
print("**************************************************************/", file=dmfpc)
tmpf = open("./.operatecommands.c", "r")
tmpf = open("./.operatecommands.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1158,7 +1158,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("/*************************************************************", file=dmfpc)
print("* EVENTS", file=dmfpc)
print("**************************************************************/", file=dmfpc)
tmpf = open("./.events.c", "r")
tmpf = open("./.events.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1169,7 +1169,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
print("/**********************************************************************************************************************************", file=dmfpc)
print("* OBJ & PARAM DEFINITION", file=dmfpc)
print("***********************************************************************************************************************************/", file=dmfpc)
tmpf = open("./.objparamarray.c", "r")
tmpf = open("./.objparamarray.c", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfpc.write(tmpd)
@ -1177,7 +1177,7 @@ def generatecfromobj(pobj, pvalue, pdir, nextlevel):
pass
try:
tmpf = open("./.objparamarray.h", "r")
tmpf = open("./.objparamarray.h", "r", encoding='utf-8')
tmpd = tmpf.read()
tmpf.close()
dmfph.write(tmpd)
@ -1215,7 +1215,7 @@ for index in range(sys.argv[1].count(',') + 1):
JSON_FILE = bbf.ARRAY_JSON_FILES.get(dm_name[index], None)
if JSON_FILE is not None:
j_file = open(JSON_FILE, "r")
j_file = open(JSON_FILE, "r", encoding='utf-8')
data = json.loads(j_file.read(), object_pairs_hook=OrderedDict)
for dm_obj, dm_value in data.items():

View file

@ -244,7 +244,7 @@ def generatelistfromfile(dmobject):
pathfile = pathfilename if x == 0 else pathiopsyswrtfilename
exists = os.path.isfile(pathfile)
if exists:
filec = open(pathfile, "r")
filec = open(pathfile, "r", encoding='utf-8')
for linec in filec:
if "/*#" in linec:
listmapping.append(linec)
@ -326,7 +326,7 @@ def getuniquekeys(dmobject):
def printopenobject(obj):
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
if "tr-104" in sys.argv[1] or "tr-135" in sys.argv[1]:
print("\"Device.Services.%s\" : {" % obj.get(
'name').replace(" ", ""), file=fp)
@ -336,19 +336,19 @@ def printopenobject(obj):
def printopenfile():
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("{", file=fp)
fp.close()
def printclosefile():
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("}", file=fp)
fp.close()
def printOBJMaPPING(mapping):
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
config_type = mapping.split(":")
config = config_type[1].split("/")
print("\"mapping\": {", file=fp)
@ -379,7 +379,7 @@ def printOBJMaPPING(mapping):
def printPARAMMaPPING(mapping):
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
lst = mapping.split("&")
print("\"mapping\": [", file=fp)
for i in range(len(lst)):
@ -441,19 +441,19 @@ def printPARAMMaPPING(mapping):
def removelastline():
file = open("./.json_tmp")
file = open("./.json_tmp", encoding='utf-8')
lines = file.readlines()
lines = lines[:-1]
file.close()
w = open("./.json_tmp", 'w')
w = open("./.json_tmp", 'w', encoding='utf-8')
w.writelines(lines)
w.close()
printclosefile()
def replace_data_in_file(data_in, data_out):
file_r = open("./.json_tmp", "rt")
file_w = open("./.json_tmp_1", "wt")
file_r = open("./.json_tmp", "rt", encoding='utf-8')
file_w = open("./.json_tmp_1", "wt", encoding='utf-8')
text = ''.join(file_r).replace(data_in, data_out)
file_w.write(text)
file_r.close()
@ -487,7 +487,7 @@ def printOBJ(dmobject, hasobj, hasparam, bbfdm_type):
else:
fbrowse = "false"
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("\"type\" : \"object\",", file=fp)
print("\"version\" : \"%s\"," % dmobject.get('version'), file=fp)
print("\"protocols\" : [%s]," % bbfdm_type, file=fp)
@ -511,7 +511,7 @@ def printPARAM(dmparam, dmobject, bbfdm_type):
islist, datatype, paramvalrange, paramenum, paramunit, parampattern, listminItem, listmaxItem, listmaxsize = getparamoption(
dmparam)
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("\"%s\" : {" % dmparam.get('name').replace(" ", ""), file=fp)
print("\"type\" : \"%s\"," % getparamtype(dmparam), file=fp)
print("\"read\" : true,", file=fp)
@ -606,7 +606,7 @@ def printPARAM(dmparam, dmobject, bbfdm_type):
def printCOMMAND(dmparam, dmobject, _bbfdm_type):
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("\"%s\" : {" % dmparam.get('name'), file=fp)
print("\"type\" : \"command\",", file=fp)
print("\"async\" : %s," %
@ -630,7 +630,7 @@ def printCOMMAND(dmparam, dmobject, _bbfdm_type):
if param.tag == "parameter":
fp.close()
printPARAM(param, dmobject, "\"usp\"")
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("}" if outputfound else "},", file=fp)
if c.tag == "output":
@ -639,7 +639,7 @@ def printCOMMAND(dmparam, dmobject, _bbfdm_type):
if param.tag == "parameter":
fp.close()
printPARAM(param, dmobject, "\"usp\"")
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("}", file=fp)
print("}", file=fp)
@ -647,7 +647,7 @@ def printCOMMAND(dmparam, dmobject, _bbfdm_type):
def printEVENT(dmparam, dmobject, _bbfdm_type):
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("\"%s\" : {" % dmparam.get('name'), file=fp)
print("\"type\" : \"event\",", file=fp)
print("\"version\" : \"%s\"," % dmparam.get('version'), file=fp)
@ -667,7 +667,7 @@ def printEVENT(dmparam, dmobject, _bbfdm_type):
printPARAM(param, dmobject, "\"usp\"")
if has_param:
fp = open('./.json_tmp', 'a')
fp = open('./.json_tmp', 'a', encoding='utf-8')
print("}", file=fp)
fp.close()
@ -832,23 +832,23 @@ def generatejsonfromobj(pobj, pdir):
chech_each_obj_with_other_obj(model1, model2)
if "tr-181" in sys.argv[1] and pobj.get("name").count(".") == 1:
dmfp = open(pdir + "/tr181.json", "a")
dmfp = open(pdir + "/tr181.json", "a", encoding='utf-8')
elif "tr-104" in sys.argv[1] and pobj.get("name").count(".") == 2:
dmfp = open(pdir + "/tr104.json", "a")
dmfp = open(pdir + "/tr104.json", "a", encoding='utf-8')
elif "tr-135" in sys.argv[1] and pobj.get("name").count(".") == 2:
dmfp = open(pdir + "/tr135.json", "a")
dmfp = open(pdir + "/tr135.json", "a", encoding='utf-8')
elif "tr-106" in sys.argv[1] and pobj.get("name").count(".") == 1:
dmfp = open(pdir + "/tr106.json", "a")
dmfp = open(pdir + "/tr106.json", "a", encoding='utf-8')
else:
dmfp = open(pdir + "/" + (getname(pobj.get('name'))
).lower() + ".json", "a")
).lower() + ".json", "a", encoding='utf-8')
printclosefile()
printclosefile()
updatejsontmpfile()
removelastline()
f = open("./.json_tmp", "r")
f = open("./.json_tmp", "r", encoding='utf-8')
obj = json.load(f, object_pairs_hook=OrderedDict)
dump = json.dumps(obj, indent=4)
tabs = re.sub('\n +', lambda match: '\n' + '\t' *

View file

@ -37,7 +37,7 @@ VENDOR_LIST = None
PLUGINS = None
OUTPUT = None
json_file = open(sys.argv[1], "r")
json_file = open(sys.argv[1], "r", encoding='utf-8')
json_data = json.loads(json_file.read())
for option, value in json_data.items():

View file

@ -104,7 +104,7 @@ def parse_object_tree(dm_name_list):
JSON_FILE = bbf.ARRAY_JSON_FILES.get(dm, None)
if JSON_FILE is not None:
file = open(JSON_FILE, "r")
file = open(JSON_FILE, "r", encoding='utf-8')
data = json.loads(file.read(), object_pairs_hook=OrderedDict)
for obj, value in data.items():

View file

@ -79,7 +79,7 @@ def generate_bbf_xml_file(output_file):
ET.SubElement(syntax, ARRAY_TYPES.get(obj[2], None))
DM_PARAM_COUNT += 1
xml_file = open(output_file, "w")
xml_file = open(output_file, "w", encoding='utf-8')
xml_file.write(pretty_format(root))
xml_file.close()
@ -178,7 +178,7 @@ def generate_hdm_xml_file(output_file):
param_type.text = str(ARRAY_TYPES.get(obj[2], None))
DM_PARAM_COUNT += 1
xml_file = open(output_file, "w")
xml_file = open(output_file, "w", encoding='utf-8')
xml_file.write(pretty_format(root))
xml_file.close()