Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Julien David
rdos
Commits
1d593cb7
Commit
1d593cb7
authored
Oct 13, 2020
by
Ismail Moumni
Browse files
editing comments and function names
parent
959d9912
Pipeline
#1422
failed with stage
in 12 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
softwares/database/database.py
View file @
1d593cb7
...
...
@@ -114,8 +114,8 @@ def get_generators():
for
result
in
myresult
:
generators
[
result
[
0
]]
=
[
result
]
def
lis
t_generator
():
# Returns all existing generators from database in a list
def
ge
t_generator
_list
():
database
=
database_connection
()
generators
=
{}
sql_get_generators
=
"SELECT id, tool from generators"
...
...
@@ -128,15 +128,14 @@ def list_generator():
return
generators
# Insert in database query send from client and returns insert status
1 if inserted
def
db_insert
(
query
:
dict
):
# Insert in database query send from client
to server
and returns insert status
def
add_job
(
query
:
dict
):
if
(
query
is
not
None
):
database
=
database_connection
()
if
(
db_
job_check
(
query
)
!=
0
):
if
(
job_check
(
query
)
!=
0
):
query
[
'id'
]
=
str
(
random
.
getrandbits
(
64
))
try
:
values
=
query
.
values
()
print
(
"values received :"
,
values
)
cols
=
query
.
keys
()
sql_new_job_row
=
"INSERT INTO jobs (%s) VALUES ('%s');"
%
(
", "
.
join
(
cols
),
"','"
.
join
(
values
))
mycursor
=
database
.
cursor
(
buffered
=
True
)
...
...
@@ -151,8 +150,8 @@ def db_insert(query: dict):
# Checks existance of query ID in database and returns the status
#
db_
job_check returns 1 if query exist in database else returns 0
def
db_
job_check
(
query
:
dict
):
# job_check returns 1 if query exist in database else returns 0
def
job_check
(
query
:
dict
):
if
(
query
is
not
None
):
db
=
database_connection
()
try
:
...
...
softwares/server/server.py
View file @
1d593cb7
...
...
@@ -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 return a valid insert query
def
query_fields
(
addr
,
data
):
__RDOS_Tool__
=
db
.
lis
t_generator
()
__RDOS_Tool__
=
db
.
ge
t_generator
_list
()
sa
=
__RDOS_Tool__
.
get
(
list
(
data
.
keys
())[
0
])
lm
=
list
((
data
.
values
()))
s
=
{
"id"
:
""
,
"idGenerator"
:
""
,
"IP"
:
""
,
"timeSubmitted"
:
""
,
"timeExecuted"
:
""
,
...
...
@@ -69,24 +69,22 @@ def query_fields(addr, data):
s
[
"IP"
]
=
addr
.
getpeername
()[
0
]
s
[
"timeSubmitted"
]
=
(
str
(
datetime
.
datetime
.
now
().
strftime
(
"%Y-%m-%d %H:%M:%S"
)))
s
[
"parametersJSON"
]
=
json
.
dumps
(
lm
[
0
])
print
(
s
)
return
s
# Function db_
new
_job send a query to insert in database by socket
# Function
db_new_job
takes a socket and dictionary for input
# Function
db_new_job
returns a string if query send
# Function db_
send
_job send a query to insert in database by socket
# Function takes a socket and dictionary for input
# Function returns a string if query send
def
db_send_job
(
s
:
socket
,
req
:
dict
):
if
(
req
is
not
None
):
ins
=
db
.
db_new
_job
(
req
)
ins
=
db
.
add
_job
(
req
)
s
.
send
(
bytes
(
json
.
dumps
(
ins
),
"utf-8"
))
print
(
"Query send"
)
else
:
raise
Exception
(
"Empty Query"
)
# Function query_valwid matches the query send from client side
# with the the parameter dict
# Function query_valid matches the query send from client side with the the parameter dict
# Function input dictionary from client
# Function output boolean true if match else False
def
query_valid
(
data
:
dict
):
...
...
@@ -97,12 +95,12 @@ def query_valid(data: dict):
return
False
# Function json_
loads
changes a json file into a Dict
# Function json_
loads
returns a dictionary
def
json_to_dict
(
js
):
if
js
is
not
None
:
data
=
json
.
loads
(
js
)
return
data
# Function json_
to_dict
changes a json file into a Dict
# Function json_
to_dict
returns a dictionary
def
json_to_dict
(
data
):
if
data
is
not
None
:
result
=
json
.
loads
(
js
)
return
result
else
:
raise
Exception
(
"Dictionnaire Vide!!"
)
...
...
@@ -118,7 +116,7 @@ def db_req(tool: dict):
raise
Exception
(
"Dictionnaire Vide!!"
)
# Function m
atch_dict
returns non existing fields in a dict
# Function m
issing_keys
returns non existing fields in a dict
# Function input biblio and dict
# Function returns a list containing missing values
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 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
):
if
biblio
is
not
None
and
data
is
not
None
:
return
biblio
.
keys
()
==
data
.
keys
()
...
...
@@ -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 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
):
if
data
is
not
None
:
tool
=
list
(
data
.
keys
())[
0
]
...
...
@@ -178,7 +176,7 @@ def check_and_replace(query: dict, default_parameters: dict):
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 returns all database generators or raises an error if request doesn't match
def
db_generators
(
req
:
dict
):
...
...
@@ -190,7 +188,7 @@ def db_generators(req: dict):
else
:
raise
Exception
(
"Dictionnaire non Valid"
)
else
:
r
aise
Exception
(
"Dictionnaire Vide!!"
)
r
eturn
Exception
(
"Dictionnaire Vide!!"
,
req
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment