Commit 1523c90f authored by Ismail Moumni's avatar Ismail Moumni
Browse files

adding verif-parameters

parent d330df5d
Pipeline #682 failed with stage
in 14 seconds
......@@ -3,7 +3,7 @@ import socket
import json
import os
import sys
# import database as db
import database as db
sys.path.append(os.path.realpath('../softwares/'))
......@@ -51,8 +51,8 @@ def query_valid(data: dict):
return False
# Function send_param_client send a dictionnary containing parameters
# needed to add a query to db
# Function send_param_client send a Dict containing parameters
# needed to add a query to db
# Function exmaple s = {"ARGUMENTS","Tools":"List of Tools" }
# Function input takes dictionnary and a list of tools
# Function output returns a new dictionnary containing arguments
......@@ -60,7 +60,7 @@ def query_valid(data: dict):
def send_param_client(__RDOS_Dict__: dict, __RDOS_Tools__: list):
dict_cl = {}
if len(__RDOS_Dict__) > 0:
dict_cl["outils"] = (__RDOS_Tools__)
dict_cl["tool"] = (__RDOS_Tools__)
s = {**__RDOS_Dict__, **dict_cl}
return s
......@@ -72,35 +72,19 @@ def json_to_dict(js):
return data
# def db_req(tool: str):
# tool_dict = db.getParameters(tool)
# return tool_dict
def verif_param(data: dict):
# Tuple
# s = db.getParameters(data['tool'])
s = ({"id": "", "name": ""}, {"id": "15"})
if s is not None:
try:
gen = s[0]
gen_default = s[1]
if match_query_dict(gen, data):
for a in data:
if data[a] == "":
data[a] = gen_default[a]
return data
except Exception as msg:
print("Error : " % msg)
else:
raise Exception("Error from DB")
# Function db_req sends a request to get parameters of tools from database
# Function takes a dictionnary for input
# Function return a Dict containing tool parameters and default parameters
def db_req(tool: dict):
tool_dict = db.getParameters(tool)
return tool_dict
def match_query_dict(biblio: dict, data: dict):
if biblio is not None and data is not None:
return biblio.keys() == data.keys()
else:
raise ValueError("Error Dict Value ")
raise ValueError("Error Dict Values ")
# Function match_generator_dict Matches Dictionnary with a list
......@@ -114,32 +98,33 @@ def match_generator_dict(biblio: dict, Genereator: list):
return True
def verif_param(data: dict):
# Tuple
tool = data.keys().strip('[]')
s = db.getParameters(data['tool'])
parameter = {}
query = {}
if s is not None:
gen = s[0]
gen_default = s[1]
parameter = gen_default
query = data.get(tool)
if match_query_dict(gen.get(tool), query):
for a in query:
if query[a] == "":
print(query[a])
query[a] = parameter.get(a)
return query
else:
raise Exception("Query Doesn't match")
else:
raise Exception("Error Database")
if __name__ == '__main__':
data = {
"sacha": "PokeBall",
"internet": "internet",
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
data1 = {"ll": "s", "ismail": "ss"}
print(match_query_dict(data, data))
print(verif_param({"name": ""}))
RdosServer.server_conn('127.0.0.1', 9393)
tool = 'Regal'
sa = ({'Regal': {'size': '', 'asize': '', 'outputf': '', 'number': '', 'comp': '', 'min': '', 'con': ''}}, {'size': '10', 'asize': '2', 'outputf': '', 'number': '1', 'comp': 'yes', 'min': '', 'con': ''})
# print(verif_param(d, data))
s = {'Regal': {'size': 'qsd', 'asize': '', 'outputf': 'qsd', 'number': 'ss', 'comp': 'qsd', 'min': 'sqsd', 'con': 'qsd'}}
# print(s.get('Regal'))
print(s.keys())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment