Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ensembl-gh-mirror
ensembl-hive
Commits
9d2b33b7
Commit
9d2b33b7
authored
Dec 01, 2020
by
Matthieu Muffato
Committed by
ens-bwalts
Jul 27, 2021
Browse files
Use a named tuple to better organise the data
parent
a370a19d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
wrappers/python3/wrapper
wrappers/python3/wrapper
+14
-12
No files found.
wrappers/python3/wrapper
View file @
9d2b33b7
...
...
@@ -16,6 +16,7 @@
# limitations under the License.
import
collections
import
sys
import
eHive
...
...
@@ -43,17 +44,18 @@ def do_build():
## And here we select the mode
WrapperMode
=
collections
.
namedtuple
(
'WrapperMode'
,
[
'function'
,
'args'
])
available_modes
=
{
'version'
:
(
do_version
,
[]),
'build'
:
(
do_build
,
[]),
'check_exists'
:
(
do_check_exists
,
[
'module_name'
]),
'run'
:
(
do_run
,
[
'module_name'
,
'fd_in'
,
'fd_out'
,
'debug'
])
'version'
:
WrapperMode
(
do_version
,
[]),
'build'
:
WrapperMode
(
do_build
,
[]),
'check_exists'
:
WrapperMode
(
do_check_exists
,
[
'module_name'
]),
'run'
:
WrapperMode
(
do_run
,
[
'module_name'
,
'fd_in'
,
'fd_out'
,
'debug'
])
}
def
usage
(
msg
):
error
=
"Command-line error: "
+
msg
+
"
\n
Usage:
\n
"
for
(
mode
,
(
_
,
args
)
)
in
available_modes
.
items
():
error
+=
"
\t
"
+
" "
.
join
([
sys
.
argv
[
0
],
mode
]
+
args
)
+
"
\n
"
for
(
mode
,
impl
)
in
available_modes
.
items
():
error
+=
"
\t
"
+
" "
.
join
([
sys
.
argv
[
0
],
mode
]
+
impl
.
args
)
+
"
\n
"
print
(
error
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
...
...
@@ -63,11 +65,11 @@ if len(sys.argv) == 1:
mode
=
sys
.
argv
[
1
]
if
mode
not
in
available_modes
:
usage
(
'Unknown mode "{0}"'
.
format
(
mode
))
impl
=
available_modes
[
mode
]
if
len
(
sys
.
argv
)
-
2
<
len
(
available_modes
[
mode
][
1
]):
usage
(
'Not enough arguments for mode "'
+
mode
+
'". Expecting: '
+
' '
.
join
(
available_modes
[
mode
][
1
]))
if
len
(
sys
.
argv
)
-
2
>
len
(
available_modes
[
mode
][
1
]):
usage
(
'Too many arguments for mode "'
+
mode
+
'". Expecting: '
+
(
' '
.
join
(
available_modes
[
mode
][
1
])
if
available_modes
[
mode
][
1
]
else
'(none)'
))
available_modes
[
mode
][
0
]()
if
len
(
sys
.
argv
)
-
2
<
len
(
impl
.
args
):
usage
(
'Not enough arguments for mode "'
+
mode
+
'". Expecting: '
+
' '
.
join
(
impl
.
args
))
if
len
(
sys
.
argv
)
-
2
>
len
(
impl
.
args
):
usage
(
'Too many arguments for mode "'
+
mode
+
'". Expecting: '
+
(
' '
.
join
(
impl
.
args
)
if
impl
.
args
else
'(none)'
))
impl
.
function
()
Write
Preview
Markdown
is supported
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