Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ActEV
diva_evaluation_cli
Commits
e0b6d6a0
Commit
e0b6d6a0
authored
Mar 17, 2020
by
Baptiste CHOCOT
Browse files
Add wrapper for calling shell commands/scripts
parent
8c125f86
Pipeline
#164564
failed with stage
in 32 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
diva_evaluation_cli/bin/private_src/entry_points/actev_clear_logs.py
View file @
e0b6d6a0
...
...
@@ -4,6 +4,9 @@ This file should not be modified.
"""
import
os
from
diva_evaluation_cli
.
bin
.
private_src
.
implementation
.
utils
.
\
shell_wrapper
import
run_shell
def
entry_point
():
"""Private entry point.
...
...
@@ -14,15 +17,4 @@ def entry_point():
# go into the right directory to execute the script
path
=
os
.
path
.
dirname
(
__file__
)
script
=
os
.
path
.
join
(
path
,
'../implementation/clear_logs/clear_logs.sh'
)
# status is a 16-bit long integer
# The 8 strongest bits are exit_code
# The 8 weakest bits are signal_number
status
=
os
.
system
(
script
)
exit_code
=
status
>>
8
signal_number
=
status
&
(
2
**
8
-
1
)
if
status
!=
0
:
if
signal_number
==
2
:
# SIGINT
raise
KeyboardInterrupt
else
:
raise
Exception
(
"Error occured in clear_logs.sh"
)
run_shell
(
script
)
diva_evaluation_cli/bin/private_src/entry_points/actev_get_system.py
View file @
e0b6d6a0
...
...
@@ -9,6 +9,8 @@ from diva_evaluation_cli.bin.private_src.implementation.utils.\
from
diva_evaluation_cli
.
bin
.
private_src
.
implementation
.
get_system
.
\
system_types_definition
import
system_types
from
diva_evaluation_cli
.
bin
.
private_src
.
implementation
.
utils
.
\
shell_wrapper
import
run_shell
def
entry_point
(
url
,
system_type
,
location
=
None
,
user
=
None
,
password
=
None
,
...
...
@@ -86,16 +88,4 @@ def entry_point(url, system_type, location=None, user=None, password=None,
" "
+
install_cli
+
\
" "
+
sha
+
\
" "
+
name
# status is a 16-bit long integer
# The 8 strongest bits are exit_code
# The 8 weakest bits are signal_number
status
=
os
.
system
(
script
)
exit_code
=
status
>>
8
signal_number
=
status
&
(
2
**
8
-
1
)
if
status
!=
0
:
if
signal_number
==
2
:
# SIGINT
raise
KeyboardInterrupt
else
:
raise
Exception
(
"Error occured in %s (error code: %d)"
%
(
command
.
entry_point
,
exit_code
))
run_shell
(
script
)
diva_evaluation_cli/bin/private_src/entry_points/actev_validate_execution.py
View file @
e0b6d6a0
...
...
@@ -9,6 +9,9 @@ import os
from
collections
import
Counter
from
diva_evaluation_cli
.
bin
.
private_src
.
implementation
.
utils
.
\
shell_wrapper
import
run_shell
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -46,19 +49,9 @@ def entry_point(output, reference, activity_index, file_index, result, score):
if
not
result
and
score
:
raise
Exception
(
"Please provide a -R option when using --score"
)
# status is a 16-bit long integer
# The 8 strongest bits are exit_code
# The 8 weakest bits are signal_number
cmd
=
'cd '
+
execution_validation_dir
+
'; '
cmd
+=
'. '
+
installation_script
+
';'
+
scoring_cmd
status
=
os
.
system
(
cmd
)
exit_code
=
status
>>
8
signal_number
=
status
&
(
2
**
8
-
1
)
if
status
!=
0
:
if
signal_number
==
2
:
# SIGINT
raise
KeyboardInterrupt
else
:
raise
Exception
(
"Error occured in install.sh or score.sh"
)
run_shell
(
cmd
)
# If the system output is scored, make it also check the alignments
# Produced by the scorer. This is a reproducibility check made to compare
...
...
diva_evaluation_cli/bin/private_src/implementation/utils/shell_wrapper.py
0 → 100644
View file @
e0b6d6a0
"""Utils module
Can be used by any other module of the CLI
Implements function to call shell commands and get correct informations on fail
"""
import
subprocess
class
ShellException
(
Exception
):
"""
Bare exception class for running shell commands.
"""
def
__init__
(
self
,
exception
):
Exception
.
__init__
(
self
)
self
.
exception
=
exception
def
__str__
(
self
):
return
"Failed to execute: {}
\n
Error code: {}
\n
stderr: {}"
.
format
(
self
.
exception
.
cmd
,
self
.
exception
.
returncode
,
self
.
exception
.
stderr
)
def
run_shell
(
command
:
tuple
):
"""
Run shell script or command.
"""
try
:
process
=
subprocess
.
run
(
command
,
shell
=
True
,
capture_output
=
True
,
text
=
True
,
check
=
True
)
except
subprocess
.
CalledProcessError
as
e
:
raise
ShellException
(
e
)
Write
Preview
Supports
Markdown
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