Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Julien David
rdos
Commits
b09ab427
Commit
b09ab427
authored
Oct 07, 2020
by
Ismail Moumni
Browse files
adding check function to database insert
parent
c888c56c
Pipeline
#1315
failed with stage
in 15 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
softwares/database/database.py
View file @
b09ab427
...
...
@@ -123,12 +123,12 @@ def list_generator():
mycur
.
execute
(
sql_get_generators
)
res
=
mycur
.
fetchall
()
mycur
.
close
()
for
a
,
b
in
res
:
for
a
,
b
in
res
:
generators
[
b
]
=
a
return
generators
# Insert in database query send from client and returns insert status
# Insert in database query send from client and returns insert status
1 if inserted
def
db_insert
(
query
:
dict
):
if
(
query
is
not
None
):
database
=
database_connection
()
...
...
@@ -145,11 +145,15 @@ def db_insert(query: dict):
database
.
commit
()
mycursor
.
close
()
database
.
close
()
res
=
db_job_check
(
query
)
print
(
"res:"
,
res
)
return
res
except
mysql
.
connector
.
Error
as
err
:
print
(
"MYSQL Error :{}"
.
format
(
err
))
# 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
):
if
(
query
is
not
None
):
db
=
database_connection
()
...
...
softwares/server/server.py
View file @
b09ab427
...
...
@@ -10,10 +10,11 @@ import database as db
__RDOS_Dict__
=
{
"parameters"
:
"request"
}
# tools List
__RDOS_Tool__
=
db
.
list_generator
()
#
__RDOS_Tool__ = db.list_generator
s
()
class
RdosServer
:
__RDOS_Tool__
=
db
.
list_generators
()
# Function server_conn creates a socket and listens on port 9393
# Function input address : SERVER IP ADRESS & Port server Port
...
...
@@ -32,8 +33,7 @@ class RdosServer:
data
=
conn
.
recv
(
4096
)
query
=
(
json
.
loads
(
data
.
decode
(
'utf-8'
)))
print
(
"Requete reçu : "
,
query
)
#query = json_to_dict(req)
if
(
query
is
not
None
):
if
(
query
is
not
None
):
# Sending GENERATORS
print
(
query
)
if
(
match_query_dict
(
query
,
__RDOS_Dict__
)):
...
...
@@ -44,13 +44,17 @@ class RdosServer:
# Inserting client query in DATABASE
else
:
print
(
"check"
,
check_and_complete_parameters
(
query
))
db_server_insert
(
conn
,
query_client
(
addr
,
check_and_complete_parameters
(
query
)))
print
(
"query received : "
,
query
)
conn
.
send
(
bytes
(
json
.
dumps
(
"{'etat':'inserted'}"
),
"utf-8"
))
res
=
db_server_insert
(
conn
,
query_client
(
addr
,
check_and_complete_parameters
(
query
)))
# print("query : " , query)
if
(
res
==
1
):
conn
.
send
(
bytes
(
res
,
"utf-8"
))
else
:
conn
.
send
(
bytes
(
"query not inserted !!"
,
"utf-8"
))
conn
.
close
()
def
query_client
(
addr
,
data
):
__RDOS_Tool__
=
db
.
list_generators
()
sa
=
__RDOS_Tool__
.
get
(
list
(
data
.
keys
())[
0
])
lm
=
list
((
data
.
values
()))
s
=
{
"id"
:
""
,
"idGenerator"
:
""
,
"IP"
:
""
,
"timeSubmitted"
:
""
,
"timeExecuted"
:
""
,
"timeFinished"
:
""
,
"status"
:
""
,
"parametersJSON"
:
""
,
"directory"
:
""
,
"url"
:
""
,
"message"
:
""
,
"email"
:
""
}
...
...
Write
Preview
Markdown
is supported
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