Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
2938666b
Commit
2938666b
authored
12 years ago
by
Francois Henrotte
Browse files
Options
Downloads
Patches
Plain Diff
python-onelab with subclients
parent
187fcb36
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
contrib/onelab/python/OnelabClient.py
+38
-18
38 additions, 18 deletions
contrib/onelab/python/OnelabClient.py
contrib/onelab/python/sub.py
+14
-0
14 additions, 0 deletions
contrib/onelab/python/sub.py
contrib/onelab/python/test.py
+13
-11
13 additions, 11 deletions
contrib/onelab/python/test.py
with
65 additions
and
29 deletions
contrib/onelab/python/OnelabClient.py
+
38
−
18
View file @
2938666b
...
...
@@ -78,7 +78,8 @@ class client :
_GMSH_CONNECT
=
27
_GMSH_OLPARSE
=
28
_GMSH_PARAM_NOT_FOUND
=
29
_GMSH_OPTION_1
=
100
def
_receive
(
self
)
:
def
buffered_receive
(
l
)
:
msg
=
b
''
...
...
@@ -97,8 +98,13 @@ class client :
def
_send
(
self
,
t
,
msg
)
:
m
=
msg
.
encode
(
'
utf-8
'
)
if
self
.
socket
.
send
(
struct
.
pack
(
'
ii%is
'
%
len
(
m
),
t
,
len
(
m
),
m
))
==
0
:
RuntimeError
(
'
onelab socket closed
'
)
try
:
if
self
.
socket
.
send
(
struct
.
pack
(
'
ii%is
'
%
len
(
m
),
t
,
len
(
m
),
m
))
==
0
:
RuntimeError
(
'
onelab socket closed
'
)
except
socket
.
error
:
self
.
socket
.
close
()
self
.
_createSocket
()
self
.
socket
.
send
(
struct
.
pack
(
'
ii%is
'
%
len
(
m
),
t
,
len
(
m
),
m
))
def
_def_parameter
(
self
,
param
)
:
if
not
self
.
socket
:
...
...
@@ -145,17 +151,23 @@ class client :
def
sub_client
(
self
,
name
,
command
):
print
'
Defining the subclient
'
+
name
msg
=
[
name
,
command
]
## msg.append(name + '\0')
## msg.append(command + '\0')
if
not
self
.
socket
:
return
self
.
_send
(
self
.
_GMSH_CONNECT
,
'
\0
'
.
join
(
msg
))
(
t
,
msg
)
=
self
.
_receive
()
print
(
"
python receive :
"
,
t
,
msg
)
if
t
==
self
.
_GMSH_CONNECT
and
msg
:
print
"
python launch :
"
+
command
+
"
-onelab
"
+
name
+
"
"
+
msg
os
.
system
(
command
+
"
-onelab
"
+
name
+
"
"
+
msg
)
## (t, msg) = self._receive()
## print ("python receive : ", t, msg)
## if t == self._GMSH_CONNECT and msg :
## print "The client %s is now connected" %(msg)
## print "python launch : "+ command + " -onelab " + name + " " + msg
## os.system(command + " -onelab " + name + " " + msg)
def
wait_on_subclient
(
self
,
name
):
if
not
self
.
socket
:
return
(
t
,
msg
)
=
self
.
_receive
()
if
t
==
self
.
_GMSH_OPTION_1
:
print
'
Client <%s> done, proceeding with the script...
'
%
(
name
)
def
merge_file
(
self
,
filename
)
:
if
not
self
.
socket
:
return
...
...
@@ -170,19 +182,26 @@ class client :
filename
=
os
.
getcwd
()
+
"
/
"
+
filename
;
self
.
_send
(
self
.
_GMSH_OLPARSE
,
filename
)
def
_createSocket
(
self
)
:
addr
=
self
.
addr
if
'
/
'
in
addr
or
'
\\
'
in
addr
or
'
:
'
not
in
addr
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
else
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
addr
)
#self.socket.setblocking(1)
#self.socket.settimeout(5.0)
def
__init__
(
self
):
self
.
socket
=
None
self
.
name
=
""
self
.
addr
=
""
for
i
,
v
in
enumerate
(
sys
.
argv
)
:
if
v
==
'
-onelab
'
:
self
.
name
=
sys
.
argv
[
i
+
1
]
addr
=
sys
.
argv
[
2
]
if
'
/
'
in
addr
or
'
\\
'
in
addr
or
'
:
'
not
in
addr
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
else
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
socket
.
connect
(
sys
.
argv
[
i
+
2
])
self
.
_send
(
self
.
_GMSH_START
,
str
(
os
.
getpid
))
self
.
addr
=
sys
.
argv
[
i
+
2
]
self
.
_createSocket
()
self
.
_send
(
self
.
_GMSH_START
,
str
(
os
.
getpid
()))
self
.
action
=
self
.
get_string
(
'
python/Action
'
)
if
self
.
action
==
"
initialize
"
:
exit
(
0
)
...
...
@@ -190,3 +209,4 @@ class client :
if
self
.
socket
:
self
.
_send
(
self
.
_GMSH_STOP
,
'
Goodbye!
'
)
self
.
socket
.
close
()
print
'
Destructor called for %s
'
%
(
self
.
name
)
This diff is collapsed.
Click to expand it.
contrib/onelab/python/sub.py
0 → 100755
+
14
−
0
View file @
2938666b
#!/usr/bin/env python
#coding=utf-8
import
OnelabClient
oc
=
OnelabClient
.
client
()
A
=
oc
.
get_number
(
'
A
'
)
B
=
oc
.
def_number
(
'
Group/B
'
,
20
)
print
'
A= %f B = %f
'
%
(
A
,
B
)
print
(
'
Action=%s
'
%
(
oc
.
get_string
(
'
python/Action
'
)))
This diff is collapsed.
Click to expand it.
contrib/onelab/python/test.py
+
13
−
11
View file @
2938666b
...
...
@@ -7,30 +7,32 @@ oc = OnelabClient.client()
#name and default value are required
A
=
oc
.
def_number
(
'
A
'
,
10
)
#other attributes are optionals
B
=
oc
.
def_number
(
'
Group/B
'
,
0
,
min
=
-
10
,
max
=
10
,
step
=
1
)
C
=
oc
.
def_number
(
'
Group/C
'
,
2
,
choices
=
[
0
,
1
,
2
,
3
],
attributes
=
{
'
Highlight
'
:
'
Pink
'
})
D
=
oc
.
def_number
(
'
Group/D
'
,
2
,
labels
=
{
0
:
'
zero
'
,
1
:
'
un
'
,
2
:
'
deux
'
,
3
:
'
trois
'
},
attributes
=
{
'
Highlight
'
:
'
Blue
'
})
#utf-8 are allowed everywhere (should be prefixed by 'u' in python 2, not required in python 3)
#Omega = oc.get_string(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org', choices = ['oui', 'non', u'peut-être'])
#B = oc.def_number('Group/B', 0, min = -10, max = 10, step = 1)
modelName
=
'
coin
'
oc
.
merge_file
(
modelName
+
'
.geo
'
)
#print('Action=%s pour %s' %(oc.action,'python'))
print
(
'
Action=%s
'
%
(
oc
.
get_string
(
'
python/Action
'
)))
oc
.
sub_client
(
'
gmsh
'
,
'
gmsh
'
+
modelName
+
'
.geo -2
'
)
oc
.
merge_file
(
modelName
+
'
.msh
'
)
oc
.
sub_client
(
'
subclient
'
,
'
sub.py
'
)
print
'
script is waiting until subclient is done
'
oc
.
wait_on_subclient
(
'
subclient
'
);
C
=
oc
.
def_number
(
'
Group/C
'
,
2
,
choices
=
[
0
,
1
,
2
,
3
],
attributes
=
{
'
Highlight
'
:
'
Pink
'
})
D
=
oc
.
def_number
(
'
Group/D
'
,
2
,
labels
=
{
0
:
'
zero
'
,
1
:
'
un
'
,
2
:
'
deux
'
,
3
:
'
trois
'
},
attributes
=
{
'
Highlight
'
:
'
Blue
'
})
#utf-8 are allowed everywhere (should be prefixed by 'u' in python 2,
#not required in python 3)
#Omega = oc.get_string(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org',
#choices = ['oui', 'non', u'peut-être'])
oc
.
convert_olfile
(
modelName
+
'
.txt
'
)
oc
.
sub_client
(
'
python
'
,
'
python
'
+
modelName
+
'
.py
'
)
if
oc
.
action
!=
'
compute
'
:
exit
(
0
)
## insert here the client's script
exit
(
0
)
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