Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
jflow
Commits
0229c050
Commit
0229c050
authored
Jul 03, 2017
by
cnoirot
Browse files
Cut admin and workflow part.
parent
38f4f2c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
bin/jflow_admin.py
0 → 100755
View file @
0229c050
#!/usr/bin/env python3
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import
sys
import
argparse
try
:
import
_preamble
except
ImportError
:
sys
.
exc_clear
()
from
jflow.workflows_manager
import
WorkflowsManager
from
jflow.workflow
import
Workflow
import
jflow.utils
as
utils
from
jflow.exceptions
import
RuleException
,
RuleIgnore
from
jflow.argument_parser
import
JflowArgumentParser
if
__name__
==
'__main__'
:
# Create a workflow manager to get access to our workflows
wfmanager
=
WorkflowsManager
()
# Create the top-level parser
parser
=
JflowArgumentParser
()
subparsers
=
parser
.
add_subparsers
(
title
=
'Available sub commands'
)
# Add rerun workflow availability
sub_parser
=
subparsers
.
add_parser
(
"rerun"
,
help
=
"Rerun a specific workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be rerun"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"rerun"
)
# Add rerun workflow availability
sub_parser
=
subparsers
.
add_parser
(
"reset"
,
help
=
"Reset a workflow component"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be used"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
add_argument
(
"--component-name"
,
type
=
str
,
help
=
"Which component should be reseted"
,
required
=
True
,
dest
=
"component_name"
)
sub_parser
.
set_defaults
(
cmd_object
=
"reset"
)
# Add delete workflow availability
sub_parser
=
subparsers
.
add_parser
(
"delete"
,
help
=
"Delete a workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be deleted"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"delete"
)
# Add print details workflow availability
sub_parser
=
subparsers
.
add_parser
(
"print"
,
help
=
"Print workflow details"
)
sub_parser
.
add_argument
(
"what"
,
help
=
"What to print [outputs, outputs_logs, execution_graph, programs]"
,
metavar
=
"COMMAND"
,
choices
=
[
"outputs"
,
"outputs_logs"
,
"execution_graph"
,
"programs"
])
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Workflow for which display outputs"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"print"
)
# Add status workflow availability
sub_parser
=
subparsers
.
add_parser
(
"status"
,
help
=
"Monitor a specific workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow status should be displayed"
,
default
=
None
,
dest
=
"workflow_id"
)
sub_parser
.
add_argument
(
"--all"
,
action
=
"store_true"
,
help
=
"Display all workflows status"
,
default
=
False
,
dest
=
"all"
)
sub_parser
.
add_argument
(
"--errors"
,
action
=
"store_true"
,
help
=
"Display failed commands"
,
default
=
False
,
dest
=
"display_errors"
)
sub_parser
.
set_defaults
(
cmd_object
=
"status"
)
args
=
vars
(
parser
.
parse_args
())
if
not
"cmd_object"
in
args
:
print
(
parser
.
format_help
())
parser
.
exit
(
0
,
""
)
if
args
[
"cmd_object"
]
in
wf_classes
:
try
:
workflow
=
wfmanager
.
get_workflow_by_class
(
args
[
"cmd_object"
])
workflow
.
check_parameters_rules
(
args
)
except
RuleException
as
e
:
sub_parser
.
error
(
e
)
except
RuleIgnore
:
pass
wfmanager
.
run_workflow
(
args
[
"cmd_object"
],
args
)
elif
args
[
"cmd_object"
]
==
"rerun"
:
wfmanager
.
rerun_workflow
(
args
[
"workflow_id"
])
elif
args
[
"cmd_object"
]
==
"reset"
:
try
:
wfmanager
.
reset_workflow_component
(
args
[
"workflow_id"
],
args
[
"component_name"
])
except
Exception
as
e
:
utils
.
display_error_message
(
str
(
e
))
elif
args
[
"cmd_object"
]
==
"delete"
:
try
:
wfmanager
.
delete_workflow
(
args
[
"workflow_id"
])
except
Exception
as
e
:
utils
.
display_error_message
(
str
(
e
))
elif
args
[
"cmd_object"
]
==
"print"
:
my_workflow
=
None
try
:
my_workflow
=
wfmanager
.
get_workflow
(
args
[
"workflow_id"
])
except
Exception
as
e
:
utils
.
display_error_message
(
str
(
e
))
if
my_workflow
is
not
None
:
my_workflow
.
print_output
(
args
[
"what"
])
elif
args
[
"cmd_object"
]
==
"status"
:
if
args
[
"workflow_id"
]:
try
:
workflow
=
wfmanager
.
get_workflow
(
args
[
"workflow_id"
])
except
Exception
as
e
:
utils
.
display_error_message
(
str
(
e
))
print
((
Workflow
.
get_status_under_text_format
(
workflow
,
True
,
args
[
"display_errors"
])))
else
:
try
:
workflows
=
wfmanager
.
get_workflows
(
use_cache
=
True
)
except
Exception
as
e
:
utils
.
display_error_message
(
str
(
e
))
if
len
(
workflows
)
>
0
:
workflows_by_id
,
wfids
=
{},
[]
# first sort workflow by ID
for
workflow
in
workflows
:
wfids
.
append
(
workflow
.
id
)
workflows_by_id
[
workflow
.
id
]
=
workflow
status
=
"ID
\t
NAME
\t
STATUS
\t
ELAPSED_TIME
\t
START_TIME
\t
END_TIME
\n
"
for
i
,
wfid
in
enumerate
(
sorted
(
wfids
,
reverse
=
True
)):
status
+=
Workflow
.
get_status_under_text_format
(
workflows_by_id
[
wfid
])
if
i
<
len
(
workflows
)
-
1
:
status
+=
"
\n
"
else
:
status
=
"no workflow available"
print
(
status
)
\ No newline at end of file
bin/jflow_cli.py
View file @
0229c050
...
...
@@ -31,31 +31,7 @@ import jflow.utils as utils
from
jflow.exceptions
import
RuleException
,
RuleIgnore
class
JflowArgumentParser
(
argparse
.
ArgumentParser
):
def
_read_args_from_files
(
self
,
arg_strings
):
# expand arguments referencing files
new_arg_strings
=
[]
for
arg_string
in
arg_strings
:
# if it's not a comment or an empty line
if
not
arg_string
.
startswith
(
"#"
)
and
arg_string
:
# for regular arguments, just add them back into the list
if
not
arg_string
or
arg_string
[
0
]
not
in
self
.
fromfile_prefix_chars
:
new_arg_strings
.
append
(
arg_string
)
# replace arguments referencing files with the file content
else
:
try
:
with
open
(
arg_string
[
1
:])
as
args_file
:
arg_strings
=
[]
# give to the convert_arg_line_to_args a table of lines instead of line per line
for
arg
in
self
.
convert_arg_line_to_args
(
args_file
.
read
().
splitlines
()):
arg_strings
.
append
(
arg
)
arg_strings
=
self
.
_read_args_from_files
(
arg_strings
)
new_arg_strings
.
extend
(
arg_strings
)
except
OSError
:
err
=
_sys
.
exc_info
()[
1
]
self
.
error
(
str
(
err
))
# return the modified argument list
return
new_arg_strings
from
jflow.argument_parser
import
JflowArgumentParser
if
__name__
==
'__main__'
:
...
...
@@ -66,43 +42,7 @@ if __name__ == '__main__':
parser
=
JflowArgumentParser
()
subparsers
=
parser
.
add_subparsers
(
title
=
'Available sub commands'
)
# Add rerun workflow availability
sub_parser
=
subparsers
.
add_parser
(
"rerun"
,
help
=
"Rerun a specific workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be rerun"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"rerun"
)
# Add rerun workflow availability
sub_parser
=
subparsers
.
add_parser
(
"reset"
,
help
=
"Reset a workflow component"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be used"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
add_argument
(
"--component-name"
,
type
=
str
,
help
=
"Which component should be reseted"
,
required
=
True
,
dest
=
"component_name"
)
sub_parser
.
set_defaults
(
cmd_object
=
"reset"
)
# Add delete workflow availability
sub_parser
=
subparsers
.
add_parser
(
"delete"
,
help
=
"Delete a workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow should be deleted"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"delete"
)
# Add print details workflow availability
sub_parser
=
subparsers
.
add_parser
(
"print"
,
help
=
"Print workflow details"
)
sub_parser
.
add_argument
(
"what"
,
help
=
"What to print [outputs, outputs_logs, execution_graph, programs]"
,
metavar
=
"COMMAND"
,
choices
=
[
"outputs"
,
"outputs_logs"
,
"execution_graph"
,
"programs"
])
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Workflow for which display outputs"
,
required
=
True
,
dest
=
"workflow_id"
)
sub_parser
.
set_defaults
(
cmd_object
=
"print"
)
# Add status workflow availability
sub_parser
=
subparsers
.
add_parser
(
"status"
,
help
=
"Monitor a specific workflow"
)
sub_parser
.
add_argument
(
"--workflow-id"
,
type
=
str
,
help
=
"Which workflow status should be displayed"
,
default
=
None
,
dest
=
"workflow_id"
)
sub_parser
.
add_argument
(
"--all"
,
action
=
"store_true"
,
help
=
"Display all workflows status"
,
default
=
False
,
dest
=
"all"
)
sub_parser
.
add_argument
(
"--errors"
,
action
=
"store_true"
,
help
=
"Display failed commands"
,
default
=
False
,
dest
=
"display_errors"
)
sub_parser
.
set_defaults
(
cmd_object
=
"status"
)
# Add available pipelines
wf_instances
,
wf_methodes
=
wfmanager
.
get_available_workflows
()
...
...
src/jflow/argument_parser.py
0 → 100644
View file @
0229c050
#
# Copyright (C) 2015 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import
argparse
class
JflowArgumentParser
(
argparse
.
ArgumentParser
):
def
_read_args_from_files
(
self
,
arg_strings
):
# expand arguments referencing files
new_arg_strings
=
[]
for
arg_string
in
arg_strings
:
# if it's not a comment or an empty line
if
not
arg_string
.
startswith
(
"#"
)
and
arg_string
:
# for regular arguments, just add them back into the list
if
not
arg_string
or
arg_string
[
0
]
not
in
self
.
fromfile_prefix_chars
:
new_arg_strings
.
append
(
arg_string
)
# replace arguments referencing files with the file content
else
:
try
:
with
open
(
arg_string
[
1
:])
as
args_file
:
arg_strings
=
[]
# give to the convert_arg_line_to_args a table of lines instead of line per line
for
arg
in
self
.
convert_arg_line_to_args
(
args_file
.
read
().
splitlines
()):
arg_strings
.
append
(
arg
)
arg_strings
=
self
.
_read_args_from_files
(
arg_strings
)
new_arg_strings
.
extend
(
arg_strings
)
except
OSError
:
err
=
_sys
.
exc_info
()[
1
]
self
.
error
(
str
(
err
))
# return the modified argument list
return
new_arg_strings
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment