Commit 1d593cb7 authored by Ismail Moumni's avatar Ismail Moumni
Browse files

editing comments and function names

parent 959d9912
Pipeline #1422 failed with stage
in 12 seconds
...@@ -114,8 +114,8 @@ def get_generators(): ...@@ -114,8 +114,8 @@ def get_generators():
for result in myresult: for result in myresult:
generators[result[0]] = [result] generators[result[0]] = [result]
# Returns all existing generators from database in a list
def list_generator(): def get_generator_list():
database = database_connection() database = database_connection()
generators = {} generators = {}
sql_get_generators = "SELECT id, tool from generators" sql_get_generators = "SELECT id, tool from generators"
...@@ -128,15 +128,14 @@ def list_generator(): ...@@ -128,15 +128,14 @@ def list_generator():
return generators return generators
# Insert in database query send from client and returns insert status 1 if inserted # Insert in database query send from client to server and returns insert status
def db_insert(query: dict): def add_job(query: dict):
if(query is not None): if(query is not None):
database = database_connection() database = database_connection()
if(db_job_check(query) != 0): if(job_check(query) != 0):
query['id'] = str(random.getrandbits(64)) query['id'] = str(random.getrandbits(64))
try: try:
values = query.values() values = query.values()
print("values received :", values)
cols = query.keys() cols = query.keys()
sql_new_job_row = "INSERT INTO jobs (%s) VALUES ('%s');" % (", ".join(cols), "','".join(values)) sql_new_job_row = "INSERT INTO jobs (%s) VALUES ('%s');" % (", ".join(cols), "','".join(values))
mycursor = database.cursor(buffered=True) mycursor = database.cursor(buffered=True)
...@@ -151,8 +150,8 @@ def db_insert(query: dict): ...@@ -151,8 +150,8 @@ def db_insert(query: dict):
# Checks existance of query ID in database and returns the status # Checks existance of query ID in database and returns the status
# db_job_check returns 1 if query exist in database else returns 0 # job_check returns 1 if query exist in database else returns 0
def db_job_check(query: dict): def job_check(query: dict):
if (query is not None): if (query is not None):
db = database_connection() db = database_connection()
try: try:
......
...@@ -59,7 +59,7 @@ def query_process(sock: socket, query: dict): ...@@ -59,7 +59,7 @@ def query_process(sock: socket, query: dict):
# Function takes 2 parameters addr : IP address of client and data : Generators values # Function takes 2 parameters addr : IP address of client and data : Generators values
# Function return a valid insert query # Function return a valid insert query
def query_fields(addr, data): def query_fields(addr, data):
__RDOS_Tool__ = db.list_generator() __RDOS_Tool__ = db.get_generator_list()
sa = __RDOS_Tool__.get(list(data.keys())[0]) sa = __RDOS_Tool__.get(list(data.keys())[0])
lm = list((data.values())) lm = list((data.values()))
s = {"id": "", "idGenerator": "", "IP": "", "timeSubmitted": "", "timeExecuted": "", s = {"id": "", "idGenerator": "", "IP": "", "timeSubmitted": "", "timeExecuted": "",
...@@ -69,24 +69,22 @@ def query_fields(addr, data): ...@@ -69,24 +69,22 @@ def query_fields(addr, data):
s["IP"] = addr.getpeername()[0] s["IP"] = addr.getpeername()[0]
s["timeSubmitted"] = (str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) s["timeSubmitted"] = (str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
s["parametersJSON"] = json.dumps(lm[0]) s["parametersJSON"] = json.dumps(lm[0])
print(s)
return s return s
# Function db_new_job send a query to insert in database by socket # Function db_send_job send a query to insert in database by socket
# Function db_new_job takes a socket and dictionary for input # Function takes a socket and dictionary for input
# Function db_new_job returns a string if query send # Function returns a string if query send
def db_send_job(s: socket, req: dict): def db_send_job(s: socket, req: dict):
if(req is not None): if(req is not None):
ins = db.db_new_job(req) ins = db.add_job(req)
s.send(bytes(json.dumps(ins), "utf-8")) s.send(bytes(json.dumps(ins), "utf-8"))
print("Query send") print("Query send")
else: else:
raise Exception("Empty Query") raise Exception("Empty Query")
# Function query_valwid matches the query send from client side # Function query_valid matches the query send from client side with the the parameter dict
# with the the parameter dict
# Function input dictionary from client # Function input dictionary from client
# Function output boolean true if match else False # Function output boolean true if match else False
def query_valid(data: dict): def query_valid(data: dict):
...@@ -97,12 +95,12 @@ def query_valid(data: dict): ...@@ -97,12 +95,12 @@ def query_valid(data: dict):
return False return False
# Function json_loads changes a json file into a Dict # Function json_to_dict changes a json file into a Dict
# Function json_loads returns a dictionary # Function json_to_dict returns a dictionary
def json_to_dict(js): def json_to_dict(data):
if js is not None: if data is not None:
data = json.loads(js) result = json.loads(js)
return data return result
else: else:
raise Exception("Dictionnaire Vide!!") raise Exception("Dictionnaire Vide!!")
...@@ -118,7 +116,7 @@ def db_req(tool: dict): ...@@ -118,7 +116,7 @@ def db_req(tool: dict):
raise Exception("Dictionnaire Vide!!") raise Exception("Dictionnaire Vide!!")
# Function match_dict returns non existing fields in a dict # Function missing_keys returns non existing fields in a dict
# Function input biblio and dict # Function input biblio and dict
# Function returns a list containing missing values # Function returns a list containing missing values
def missing_keys(biblio: dict, gen: dict): def missing_keys(biblio: dict, gen: dict):
...@@ -134,7 +132,7 @@ def missing_keys(biblio: dict, gen: dict): ...@@ -134,7 +132,7 @@ def missing_keys(biblio: dict, gen: dict):
# Function match_query_dict matches two dictionaries # Function match_query_dict matches two dictionaries
# Function input takes 2 dictionaries to match # Function input takes 2 dictionaries to match
# Function output return trur if dictionaries matches else raise a value error exception # Function output return trur if dictionaries matches
def match_query_dict(biblio: dict, data: dict): def match_query_dict(biblio: dict, data: dict):
if biblio is not None and data is not None: if biblio is not None and data is not None:
return biblio.keys() == data.keys() return biblio.keys() == data.keys()
...@@ -144,7 +142,7 @@ def match_query_dict(biblio: dict, data: dict): ...@@ -144,7 +142,7 @@ def match_query_dict(biblio: dict, data: dict):
# Function check_and_complete_parameters verifies json send from client to server by matching it with database query # Function check_and_complete_parameters verifies json send from client to server by matching it with database query
# Function input takes a dictionary # Function input takes a dictionary
# Function output returns query if it matches with database query keys if not it raises an error # Function output returns query if it matches with database query keys
def check_and_complete_parameters(data: dict): def check_and_complete_parameters(data: dict):
if data is not None: if data is not None:
tool = list(data.keys())[0] tool = list(data.keys())[0]
...@@ -178,7 +176,7 @@ def check_and_replace(query: dict, default_parameters: dict): ...@@ -178,7 +176,7 @@ def check_and_replace(query: dict, default_parameters: dict):
raise Exception("Dictionnaire Vide!!") raise Exception("Dictionnaire Vide!!")
# Function db_generators returns database generators # Function db_generators returns all database generators
# Function takes a dictionary request from client side # Function takes a dictionary request from client side
# Function returns all database generators or raises an error if request doesn't match # Function returns all database generators or raises an error if request doesn't match
def db_generators(req: dict): def db_generators(req: dict):
...@@ -190,7 +188,7 @@ def db_generators(req: dict): ...@@ -190,7 +188,7 @@ def db_generators(req: dict):
else: else:
raise Exception("Dictionnaire non Valid") raise Exception("Dictionnaire non Valid")
else: else:
raise Exception("Dictionnaire Vide!!") return Exception("Dictionnaire Vide!!", req)
if __name__ == '__main__': if __name__ == '__main__':
......
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