Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rdos
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien David
rdos
Merge requests
!5
Adding json functions
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adding json functions
Adding-Json-FUNCTIONS
into
master
Overview
19
Commits
36
Pipelines
34
Changes
5
Merged
Ismail Moumni
requested to merge
Adding-Json-FUNCTIONS
into
master
4 years ago
Overview
15
Commits
36
Pipelines
34
Changes
5
Expand
0
0
Merge request reports
Compare
master
version 33
9341f38a
4 years ago
version 32
69c31724
4 years ago
version 31
982c9b38
4 years ago
version 30
1f2b01e8
4 years ago
version 29
1ee3ca19
4 years ago
version 28
53eb5fd3
4 years ago
version 27
fc74fe39
4 years ago
version 26
0ca5d143
4 years ago
version 25
d4ea05c7
4 years ago
version 24
4427d873
4 years ago
version 23
3c921e5f
4 years ago
version 22
3d1c11a9
4 years ago
version 21
eac68f6d
4 years ago
version 20
e2fc5a18
4 years ago
version 19
1c55cd4d
4 years ago
version 18
0788ddd8
4 years ago
version 17
322bf12d
4 years ago
version 16
b4b323ab
4 years ago
version 15
852c156a
4 years ago
version 14
22afc38d
4 years ago
version 13
701a3615
4 years ago
version 12
9e0f66c2
4 years ago
version 11
d82b41ee
4 years ago
version 10
fb4297dd
4 years ago
version 9
1523c90f
4 years ago
version 8
d330df5d
4 years ago
version 7
103f9d43
4 years ago
version 6
268f39cc
4 years ago
version 5
1f9f00f1
4 years ago
version 4
2bb9fba6
4 years ago
version 3
8a9bd677
4 years ago
version 2
a85102c7
4 years ago
version 1
dbc772b5
4 years ago
master (base)
and
version 31
latest version
246939d0
36 commits,
4 years ago
version 33
9341f38a
35 commits,
4 years ago
version 32
69c31724
34 commits,
4 years ago
version 31
982c9b38
33 commits,
4 years ago
version 30
1f2b01e8
32 commits,
4 years ago
version 29
1ee3ca19
31 commits,
4 years ago
version 28
53eb5fd3
30 commits,
4 years ago
version 27
fc74fe39
29 commits,
4 years ago
version 26
0ca5d143
28 commits,
4 years ago
version 25
d4ea05c7
27 commits,
4 years ago
version 24
4427d873
26 commits,
4 years ago
version 23
3c921e5f
25 commits,
4 years ago
version 22
3d1c11a9
24 commits,
4 years ago
version 21
eac68f6d
23 commits,
4 years ago
version 20
e2fc5a18
22 commits,
4 years ago
version 19
1c55cd4d
21 commits,
4 years ago
version 18
0788ddd8
20 commits,
4 years ago
version 17
322bf12d
19 commits,
4 years ago
version 16
b4b323ab
18 commits,
4 years ago
version 15
852c156a
17 commits,
4 years ago
version 14
22afc38d
16 commits,
4 years ago
version 13
701a3615
15 commits,
4 years ago
version 12
9e0f66c2
14 commits,
4 years ago
version 11
d82b41ee
13 commits,
4 years ago
version 10
fb4297dd
12 commits,
4 years ago
version 9
1523c90f
11 commits,
4 years ago
version 8
d330df5d
10 commits,
4 years ago
version 7
103f9d43
9 commits,
4 years ago
version 6
268f39cc
8 commits,
4 years ago
version 5
1f9f00f1
7 commits,
4 years ago
version 4
2bb9fba6
6 commits,
4 years ago
version 3
8a9bd677
5 commits,
4 years ago
version 2
a85102c7
4 commits,
4 years ago
version 1
dbc772b5
3 commits,
4 years ago
5 files
+
197
−
33
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
softwares/server/server.py
+
136
−
23
Options
#
A
uthors
: Julien D
avid
& Ismail MOUMNI
#
a
uthors: Julien D
AVID
& Ismail MOUMNI
import
socket
import
json
import
os
import
sys
import
database.database
as
db
sys
.
path
.
append
(
os
.
path
.
realpath
(
'
../softwares/
'
))
# SERVER PORT
__RDOS_Port__
=
9393
# Creating Socket IP4 TCP
def
server_conn
(
address
,
PORT
):
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
serv
:
# BINDING
serv
.
bind
((
address
,
PORT
))
# Listening to 1 CLient
serv
.
listen
()
# Accepting the connection from client and getting client IP
conn
,
addr
=
serv
.
accept
()
with
conn
:
# Sending
conn
.
send
(
bytes
(
"
Bonjour !!
"
,
"
utf-8
"
))
print
(
'
Connexion acceptée depuis l IP :
'
,
addr
)
# Receiving Data from Client
data
=
conn
.
recv
(
1024
)
print
(
data
)
serv
.
close
()
__RDOS_Dict__
=
{}
# tools List
__RDOS_Tool__
=
[]
class
RdosServer
:
# Function server_conn creates a socket and listens on port 9393
# Function input address : SERVER IP ADRESS & Port server Port
# Function output query send from client to server
def
server_conn
(
address
,
PORT
):
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
serv
:
serv
.
bind
((
address
,
PORT
))
# Listening to 5 CLients
serv
.
listen
(
5
)
# accepting the connection from client and getting client IP
conn
,
addr
=
serv
.
accept
()
while
True
:
if
conn
:
print
(
'
Connexion acceptee depuis l IP :
'
,
addr
)
# Receiving Data from Client
data
=
conn
.
recv
(
4096
)
query
=
(
json
.
loads
(
data
.
decode
(
'
utf-8
'
)))
print
(
query
)
match
=
verif_param
(
query
)
if
match
==
query
:
print
(
"
ok
"
)
conn
.
send
(
bytes
(
json
.
dumps
(
match
),
"
utf-8
"
))
else
:
print
(
'
Erreur query :
'
)
conn
.
send
(
bytes
(
json
.
dumps
(
match
),
"
utf-8
"
))
# Function query_valwid 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
):
if
'
parameters
'
in
data
:
if
(
data
[
'
parameters
'
]
!=
''
)
&
(
len
(
data
)
<=
2
):
return
True
else
:
return
False
# 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 dictionary and a list of tools
# Function output returns a new dictionary containing arguments
# # for db query and list of tools
def
send_param_client
(
__RDOS_Dict__
:
dict
,
__RDOS_Tools__
:
list
):
req
=
db
.
getParameters
()
return
req
# Function json_loads changes a json file into a Dict
# Function json_loads returns a dictionary
def
json_to_dict
(
js
):
data
=
json
.
loads
(
js
)
return
data
# Function db_req sends a request to get parameters of tools from database
# Function takes a dictionary 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
# 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
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 Values
"
)
# Function match_generator_dict Matches dictionary with a list
# Function input 2 arguments dictionary and query from Server
# Function output true if dictionary keys match list elements else false
def
match_generator_dict
(
biblio
:
dict
,
Genereator
:
list
):
for
a
in
Genereator
:
for
b
in
biblio
.
keys
():
if
a
!=
b
:
return
False
return
True
# Function verif_param 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
def
verif_param
(
data
:
dict
):
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__
'
:
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())
data_test1 =
'
{
"
parameters
"
:
"
request
"
}
'
data_load = json.loads(data_test1)
print(query_valid(data_load) is True)
'''
Loading