Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rdos-python
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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-python
Commits
b87d82fa
Commit
b87d82fa
authored
4 years ago
by
Ismail Moumni
Browse files
Options
Downloads
Patches
Plain Diff
addding help function
parent
45347337
Branches
master
No related tags found
1 merge request
!7
addding help function
Pipeline
#1497
failed with stage
in 15 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client.py
+46
-42
46 additions, 42 deletions
client.py
with
46 additions
and
42 deletions
client.py
+
46
−
42
View file @
b87d82fa
...
...
@@ -3,8 +3,6 @@
import
socket
import
json
__RDOS_Host__
=
'
127.0.0.1
'
__RDOS_Port__
=
'
9393
'
# List to save REQUEST Parameters send FROM SERVER for query Match
__RDOS_Req__
=
{
"
parameters
"
:
"
request
"
}
__RDOS_Gen__
=
{}
...
...
@@ -12,41 +10,57 @@ __RDOS_Gen__ = {}
class
RdosClient
():
__RDOS_Host__
=
''
__RDOS_Port__
=
''
# Function client_init connects to server and sends JSON Parameters needed
# Function input Host : Server IP - Port : Server Port
# Function output returns JSON from server side contaning parameters
def
__init__
(
self
,
port
):
def
__init__
(
self
,
addr
,
port
):
self
.
__RDOS_Gen__
=
{}
self
.
__RDOS_Host__
=
addr
self
.
__RDOS_Port__
=
port
data
=
{
"
parameters
"
:
"
request
"
}
socket
=
self
.
server_conn
(
__RDOS_Host__
,
p
ort
)
socket
=
self
.
server_conn
(
self
.
__RDOS_Host__
,
self
.
___RDOS_P
ort
__
)
print
(
"
Connexion to socket :
"
)
print
((
data
))
dat
=
json
.
dumps
((
data
))
socket
.
send
(
bytes
(
json
.
dumps
(
dat
),
"
utf-8
"
))
socket
.
send
(
bytes
(
json
.
dumps
(
data
),
"
utf-8
"
))
recv
=
socket
.
recv
(
4096
)
query
=
(
json
.
loads
(
recv
.
decode
(
'
utf-8
'
)))
__RDOS_Gen__
=
query
print
(
__RDOS_Gen__
)
self
.
__RDOS_Gen__
=
{
**
query
}
# Function insert_query takes a query and send it to server for inserting a new job
# Function insert_query parameters : Dictionary
def
insert_query
(
self
,
data
:
dict
):
if
(
data
is
not
None
):
socket
=
self
.
server_conn
(
'
127.0.0.1
'
,
9393
)
socket
=
self
.
server_conn
(
self
.
__RDOS_Host__
,
self
.
__RDOS_Port__
)
req
=
json
.
dumps
((
data
))
print
(
"
data send to server :
"
,
req
)
socket
.
send
(
bytes
((
req
),
"
utf-8
"
))
recv
=
socket
.
recv
(
4096
)
query
=
(
(
recv
.
decode
(
'
utf-8
'
))
)
query
=
(
recv
.
decode
(
'
utf-8
'
))
print
(
"
data received:
"
,
query
)
else
:
raise
Exception
(
"
Dictionnaire Vide !!
"
)
def
generator_default
(
self
,
generator
):
query
=
{}
if
generator
is
not
None
:
query
[
'
default
'
]
=
generator
socket
=
self
.
server_conn
(
self
.
__RDOS_Host__
,
self
.
__RDOS_Port__
)
req
=
json
.
dumps
(
query
)
print
(
"
data send to server :
"
,
req
)
socket
.
send
(
bytes
((
req
),
"
utf-8
"
))
recv
=
socket
.
recv
(
4096
)
resp
=
((
recv
.
decode
(
'
utf-8
'
)))
print
(
"
data received:
"
,
resp
)
return
resp
# Function get_objects connects client to server by socket
# Function get_objects takes 2 parameters
# Function get_objects returns the state of the server
def
get_objects
(
self
):
try
:
s
=
self
.
server_conn
(
__RDOS_Host__
,
__RDOS_Port__
)
s
=
self
.
server_conn
(
self
.
__RDOS_Host__
,
self
.
__RDOS_Port__
)
message
=
json
.
dump
((
__RDOS_Req__
))
recv
=
self
.
send_st
(
s
,
message
)
print
(
"
Message ENVOYE :
"
,
recv
)
...
...
@@ -57,7 +71,7 @@ class RdosClient():
# Function missing_keys returns non existing fields in a dict
# Function input biblio and dict
# Function returns a list containing missing values else raises an Exception
def
missing_keys
(
biblio
:
dict
,
gen
:
dict
):
def
missing_keys
(
self
,
biblio
:
dict
,
gen
:
dict
):
missing
=
[]
if
(
biblio
is
not
None
and
gen
is
not
None
):
for
key
in
biblio
:
...
...
@@ -92,33 +106,15 @@ class RdosClient():
self
.
run_client
(
Host
,
Port
,
data
)
print
(
"
Data send to server :
"
,
data
)
# send_mess Function that returns a message from a server to a client
# Function takes 2 parameters (Socket & Message )
# Function Output message send from server
def
send_query
(
self
,
s
:
socket
,
message
:
dict
):
if
(
message
is
not
None
):
try
:
if
self
.
match_query_dict
(
message
,
__RDOS_Gen__
):
try
:
s
.
send
(
bytes
(
message
,
"
utf-8
"
))
data
=
s
.
recv
(
1024
)
return
(
data
)
except
Exception
:
tool
=
data
.
keys
().
strip
(
'
[]
'
)
match
=
self
.
missing_keys
(
message
,
__RDOS_Gen__
[
tool
])
print
(
"
Missing parameters:
"
%
match
)
except
ValueError
as
msg
:
print
(
"
Erreur requete Vide
"
%
msg
)
# Function server_conn creates a socket and connects it to server
# Function server_conn take No arguments
# Function returns a socket after making connexion
def
server_conn
(
host
,
port
):
serve_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
def
server_conn
(
self
,
host
,
port
):
self
.
serve_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
serve_sock
.
connect
((
host
,
port
))
return
serve_sock
except
socket
.
error
as
exc
:
self
.
serve_sock
.
connect
((
host
,
port
))
return
self
.
serve_sock
except
self
.
socket
.
error
as
exc
:
print
(
"
%s
"
%
exc
)
# Function dict_to_JSON transforms DICTIONNARY TO Json String
...
...
@@ -126,7 +122,7 @@ class RdosClient():
# Function OUTPUT Json string Format
def
dict_to_JSON
(
self
,
biblio
:
dict
):
if
(
biblio
is
not
None
):
if
(
self
.
missing_keys
(
biblio
,
__RDOS_Gen__
)
==
[]):
if
(
self
.
missing_keys
(
biblio
)
==
[]):
return
json
.
dumps
(
biblio
)
else
:
for
a
in
__RDOS_Gen__
:
...
...
@@ -135,17 +131,25 @@ class RdosClient():
raise
Exception
(
"
Dictionnaire Vide!!
"
)
# Function json_to_dict changes a json file into a Dict
# Function
json_to_dict
returns a dictionary
def
json_to_dict
(
js
):
# Function
takes a json dict as input and
returns a dictionary
def
json_to_dict
(
self
,
js
):
if
js
is
not
None
:
data
=
json
.
loads
(
js
)
return
data
else
:
raise
Exception
(
"
Dictionnaire Vide!!
"
)
# Function get_generators returns a list of all available generetaros$
def
get_generators
(
self
):
if
self
.
__RDOS_Gen__
is
not
None
:
return
list
(
self
.
__RDOS_Gen__
.
keys
())
else
:
return
Exception
(
"
DICTIONNAIRE Vide !!
"
)
# Function help prints the generators parameters
# Function returns generator parameters
def
help
():
def
help
(
self
,
generator
):
print
(
'
Generator parameters :
'
)
for
a
in
__RDOS_Gen__
:
print
(
"
Parameter: {}, Default Value : {}
"
.
format
(
a
,
__RDOS_Gen__
[
a
]))
default
=
self
.
generator_default
(
generator
)
print
(
"
Parameter:
"
,
list
(
json
.
loads
(
default
))[
0
])
print
(
"
Default Values :
"
,
list
(
json
.
loads
(
default
))[
1
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment