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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
925c3819
Commit
925c3819
authored
10 years ago
by
Maxime Graulich
Browse files
Options
Downloads
Patches
Plain Diff
ONELAB2
parent
130961d6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/onelab2/python/onelab2.py
+78
-5
78 additions, 5 deletions
contrib/onelab2/python/onelab2.py
with
78 additions
and
5 deletions
contrib/onelab2/python/onelab2.py
+
78
−
5
View file @
925c3819
...
@@ -232,9 +232,28 @@ class client :
...
@@ -232,9 +232,28 @@ class client :
print
(
'
onelab info : %s
'
%
msg
)
print
(
'
onelab info : %s
'
%
msg
)
return
t
,
msg
return
t
,
msg
def
_parseParameter
(
msg
):
def
extract_attr
(
b
):
t
,
l
=
struct
.
unpack
(
'
!HH
'
,
b
[:
4
])
if
l
+
4
>
len
(
b
):
RuntimeError
(
'
onelab invalid parameter
'
)
return
t
,
b
[
4
:]
ptype
,
p
=
extract_attr
(
msg
)
if
ptype
==
0x06
:
param
=
_parameter
(
'
number
'
)
param
.
frombytes
(
msg
)
return
param
elif
ptype
==
0x07
:
param
=
_parameter
(
'
string
'
)
param
.
frombytes
(
msg
)
return
param
else
:
return
None
def
_getParameter
(
self
,
param
,
warn_if_not_found
=
True
)
:
def
_getParameter
(
self
,
param
,
warn_if_not_found
=
True
)
:
def
extract_attr
(
b
):
def
extract_attr
(
b
):
print
(
len
(
b
))
t
,
l
=
struct
.
unpack
(
'
!HH
'
,
b
[:
4
])
t
,
l
=
struct
.
unpack
(
'
!HH
'
,
b
[:
4
])
if
l
+
4
>
len
(
b
):
if
l
+
4
>
len
(
b
):
RuntimeError
(
'
onelab invalid parameter
'
)
RuntimeError
(
'
onelab invalid parameter
'
)
...
@@ -246,8 +265,7 @@ class client :
...
@@ -246,8 +265,7 @@ class client :
(
t
,
msg
)
=
self
.
_receive
()
(
t
,
msg
)
=
self
.
_receive
()
if
t
==
self
.
_ONELAB_RESPONSE
:
if
t
==
self
.
_ONELAB_RESPONSE
:
ptype
,
p
=
extract_attr
(
msg
)
ptype
,
p
=
extract_attr
(
msg
)
if
ptype
==
0x06
or
ptype
==
0x05
:
if
ptype
==
0x06
or
ptype
==
0x07
:
print
(
"
recv
"
)
param
.
frombytes
(
msg
)
param
.
frombytes
(
msg
)
elif
ptype
==
0x0A
and
warn_if_not_found
:
elif
ptype
==
0x0A
and
warn_if_not_found
:
print
(
'
Unknown parameter %s
'
%
(
param
.
name
))
print
(
'
Unknown parameter %s
'
%
(
param
.
name
))
...
@@ -270,14 +288,67 @@ class client :
...
@@ -270,14 +288,67 @@ class client :
p
.
modify
(
**
param
)
p
.
modify
(
**
param
)
self
.
_send
(
self
.
_ONELAB_UPDATE
,
p
.
tobytes
())
self
.
_send
(
self
.
_ONELAB_UPDATE
,
p
.
tobytes
())
def
setString
(
self
,
name
,
**
param
):
if
not
self
.
socket
:
return
p
=
_parameter
(
'
string
'
,
name
=
name
)
self
.
_getParameter
(
p
,
False
)
p
.
modify
(
**
param
)
self
.
_send
(
self
.
_ONELAB_UPDATE
,
p
.
tobytes
())
def
_sendMessage
(
self
,
msg
,
lvl
=
5
):
def
_sendMessage
(
self
,
msg
,
lvl
=
5
):
if
not
self
.
socket
:
if
not
self
.
socket
:
print
(
msg
)
print
(
msg
)
return
return
self
.
_send
(
self
.
_ONELAB_MESSAGE
,
struct
.
pack
(
"
!HHB
"
,
0x0A
,
len
(
msg
)
+
1
,
lvl
)
+
msg
)
self
.
_send
(
self
.
_ONELAB_MESSAGE
,
struct
.
pack
(
"
!HHB
"
,
0x0A
,
len
(
msg
)
+
1
,
lvl
)
+
msg
)
def
sendFatal
(
self
,
msg
)
:
self
.
_sendMessage
(
msg
+
'
\0
'
,
1
)
def
sendError
(
self
,
msg
)
:
self
.
_sendMessage
(
msg
+
'
\0
'
,
2
)
def
sendWarning
(
self
,
msg
)
:
self
.
_sendMessage
(
msg
+
'
\0
'
,
3
)
def
sendInfo
(
self
,
msg
)
:
def
sendInfo
(
self
,
msg
)
:
self
.
_sendMessage
(
msg
+
'
\0
'
)
self
.
_sendMessage
(
msg
+
'
\0
'
,
5
)
def
sendDebug
(
self
,
msg
)
:
self
.
_sendMessage
(
msg
+
'
\0
'
,
99
)
def
waitOnSubClient
(
self
,
name
):
if
not
self
.
socket
:
return
while
self
.
_numSubClients
>
0
:
(
t
,
msg
)
=
self
.
_receive
()
if
t
==
_ONELAB_UPDATE
:
param
=
_parseParameter
(
msg
)
if
param
.
type
==
'
string
'
and
param
.
name
[
-
7
:]
==
'
/Action
'
and
param
.
value
==
'
stop
'
:
if
param
.
name
[
-
7
:]
==
name
:
return
self
.
_numSubClients
-=
1
# FIXME check that the client is a subclient ?
def
waitOnSubClients
(
self
):
if
not
self
.
socket
:
return
while
self
.
_numSubClients
>
0
:
(
t
,
msg
)
=
self
.
_receive
()
if
t
==
_ONELAB_UPDATE
:
param
=
_parseParameter
(
msg
)
if
param
.
type
==
'
string
'
and
param
.
name
[:
-
7
]
==
'
/Action
'
and
param
.
value
==
'
stop
'
:
self
.
_numSubClients
-=
1
# FIXME check that the client is a subclient ?
def
runNonBlockingSubClient
(
self
,
name
,
command
,
arguments
=
''
):
if
self
.
action
==
'
check
'
:
cmd
=
command
else
:
cmd
=
command
+
'
'
+
arguments
os
.
system
(
cmd
);
self
.
_numSubClients
+=
1
self
.
getString
(
name
+
'
/Action
'
,
False
)
def
runSubClient
(
self
,
name
,
command
,
arguments
=
''
):
self
.
runNonBlockingSubClient
(
name
,
command
,
arguments
)
self
.
waitOnSubClient
(
name
)
# makes the subclient blocking
#if self.action == 'compute':
#TODO self.setChanged(name, False)
def
__init__
(
self
,
ref
=
''
):
def
__init__
(
self
,
ref
=
''
):
self
.
socket
=
None
self
.
socket
=
None
...
@@ -306,12 +377,14 @@ class client :
...
@@ -306,12 +377,14 @@ class client :
def
finalize
(
self
):
def
finalize
(
self
):
# code aster python interpreter does not call the destructor at exit, it is
# code aster python interpreter does not call the destructor at exit, it is
# necessary to call finalize() epxlicitely
# necessary to call finalize() epxlicitely
print
(
"
finalize
"
)
if
self
.
socket
:
if
self
.
socket
:
#TODO
self.waitOnSubClients()
self
.
waitOnSubClients
()
self
.
_send
(
self
.
_ONELAB_STOP
)
self
.
_send
(
self
.
_ONELAB_STOP
)
self
.
_receive
()
self
.
_receive
()
self
.
socket
.
close
()
self
.
socket
.
close
()
self
.
socket
=
None
self
.
socket
=
None
print
(
"
finalize end
"
)
def
__del__
(
self
):
def
__del__
(
self
):
self
.
finalize
()
self
.
finalize
()
...
...
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