Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
ng6
Commits
26461747
Commit
26461747
authored
Oct 09, 2013
by
Jerome Mariette
Browse files
handle exlude for sub parameters
parent
9b812608
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/jflow/parameter.py
View file @
26461747
...
...
@@ -25,9 +25,10 @@ from workflows.types import *
class
MiltipleParameters
(
object
):
def
__init__
(
self
,
types
,
required
,
choices
):
def
__init__
(
self
,
types
,
required
,
choices
,
excludes
):
self
.
types
=
types
self
.
choices
=
choices
self
.
excludes
=
excludes
self
.
index
=
None
self
.
required
=
required
self
.
__name__
=
"MiltipleParameters"
...
...
@@ -43,30 +44,54 @@ class MiltipleParameters(object):
except
:
raise
argparse
.
ArgumentTypeError
(
"invalid "
+
self
.
types
[
parts
[
0
]].
__name__
+
" value: '"
+
parts
[
1
]
+
"' for sub parameter '"
+
parts
[
0
]
+
"'"
)
self
.
index
=
parts
[
0
]
return
(
parts
[
0
],
value
,
self
.
required
)
return
(
parts
[
0
],
value
,
self
.
required
,
self
.
excludes
)
class
MiltipleAction
(
argparse
.
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
given_params
=
[]
# first check for required parameters
try
:
required
=
_copy
.
copy
(
values
[
0
][
2
])
for
val
in
values
:
given_params
.
append
(
val
[
0
])
if
val
[
0
]
in
required
:
del
required
[
required
.
index
(
val
[
0
])]
except
:
pass
if
len
(
required
)
==
1
:
parser
.
error
(
", "
.
join
(
required
)
+
" is a required parameter!"
)
elif
len
(
required
)
>
1
:
parser
.
error
(
", "
.
join
(
required
)
+
" are required parameters!"
)
# then for exclude ones
for
exclude_group
in
values
[
0
][
3
]:
found
=
None
for
param
in
values
[
0
][
3
][
exclude_group
]:
if
param
in
given_params
and
found
!=
None
:
parser
.
error
(
"argument '"
+
found
+
"': not allowed with argument '"
+
param
+
"'"
)
break
elif
param
in
given_params
:
found
=
param
# if ok add the value
setattr
(
namespace
,
self
.
dest
,
values
)
class
MiltipleAppendAction
(
argparse
.
Action
):
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
given_params
=
[]
# first check for required parameters
try
:
required
=
_copy
.
copy
(
values
[
0
][
2
])
for
val
in
values
:
given_params
.
append
(
val
[
0
])
if
val
[
0
]
in
required
:
del
required
[
required
.
index
(
val
[
0
])]
except
:
pass
if
len
(
required
)
==
1
:
parser
.
error
(
", "
.
join
(
required
)
+
" is a required parameter!"
)
elif
len
(
required
)
>
1
:
parser
.
error
(
", "
.
join
(
required
)
+
" are required parameters!"
)
# then for exclude ones
for
exclude_group
in
values
[
0
][
3
]:
found
=
None
for
param
in
values
[
0
][
3
][
exclude_group
]:
if
param
in
given_params
and
found
!=
None
:
parser
.
error
(
"argument '"
+
found
+
"': not allowed with argument '"
+
param
+
"'"
)
break
elif
param
in
given_params
:
found
=
param
# if ok add the value
items
=
_copy
.
copy
(
_ensure_value
(
namespace
,
self
.
dest
,
[]))
items
.
append
(
values
)
setattr
(
namespace
,
self
.
dest
,
items
)
...
...
@@ -99,7 +124,7 @@ class Parameter(object):
if
type
==
"date"
:
self
.
type
=
date
elif
type
==
"multiple"
:
sub_param_hash
,
sub_param_types
,
sub_param_names
,
sub_param_required
,
sub_param_choices
=
{},
[],
[],
[],
{}
sub_param_hash
,
sub_param_types
,
sub_param_names
,
sub_param_required
,
sub_param_choices
,
sub_param_excludes
=
{},
[],
[],
[],
{}
,
{}
for
sub_param
in
self
.
sub_parameters
:
try
:
sub_type
=
sub_param
.
type
except
:
sub_type
=
types
.
StringType
...
...
@@ -107,8 +132,13 @@ class Parameter(object):
sub_param_names
.
append
(
sub_param
.
flag
)
sub_param_types
.
append
(
sub_type
)
sub_param_choices
[
sub_param
.
flag
]
=
sub_param
.
choices
if
sub_param
.
group
.
startswith
(
"exclude-"
):
if
sub_param
.
group
in
sub_param_excludes
.
keys
():
sub_param_excludes
[
sub_param
.
group
].
append
(
sub_param
.
flag
)
else
:
sub_param_excludes
[
sub_param
.
group
]
=
[
sub_param
.
flag
]
if
sub_param
.
required
:
sub_param_required
.
append
(
sub_param
.
flag
)
self
.
type
=
MiltipleParameters
(
sub_param_hash
,
sub_param_required
,
sub_param_choices
)
self
.
type
=
MiltipleParameters
(
sub_param_hash
,
sub_param_required
,
sub_param_choices
,
sub_param_excludes
)
if
self
.
action
==
"append"
:
self
.
action
=
MiltipleAppendAction
else
:
...
...
src/jflow/workflow.py
View file @
26461747
...
...
@@ -330,7 +330,7 @@ class Workflow(threading.Thread):
if
cparam
not
in
param_order
:
param_order
.
append
(
cparam
)
for
param_name
in
param_order
:
sub_params
,
current_params
,
sub_objs
=
{},
{},
[]
sub_params
,
current_params
,
sub_objs
,
sub_excludes
,
hash_sub_params
=
{},
{},
[]
,
[],
{}
for
param
in
params
[
param_name
]:
sub_params_values
=
param
.
split
(
"."
)
if
len
(
sub_params_values
)
==
2
:
...
...
@@ -340,11 +340,22 @@ class Workflow(threading.Thread):
key
=
"display_name"
else
:
key
=
sub_params_values
[
1
]
if
not
sub_params
.
has_key
(
sub_params_values
[
0
]):
sub_params
[
sub_params_values
[
0
]]
=
{
key
:
params
[
param_name
][
param
]}
sub_params
[
sub_params_values
[
0
]][
"name"
]
=
sub_params_values
[
0
]
if
key
==
"exclude"
:
found
=
False
for
exclude_group
in
sub_excludes
:
if
sub_params_values
[
0
]
in
exclude_group
:
exclude_group
.
append
(
params
[
param_name
][
param
])
found
=
True
elif
params
[
param_name
][
param
]
in
exclude_group
:
exclude_group
.
append
(
sub_params_values
[
0
])
found
=
True
if
not
found
:
sub_excludes
.
append
([
sub_params_values
[
0
],
params
[
param_name
][
param
]])
else
:
sub_params
[
sub_params_values
[
0
]][
key
]
=
params
[
param_name
][
param
]
if
not
sub_params
.
has_key
(
sub_params_values
[
0
]):
sub_params
[
sub_params_values
[
0
]]
=
{
key
:
params
[
param_name
][
param
]}
sub_params
[
sub_params_values
[
0
]][
"name"
]
=
sub_params_values
[
0
]
else
:
sub_params
[
sub_params_values
[
0
]][
key
]
=
params
[
param_name
][
param
]
else
:
if
param
==
"name"
:
current_params
[
"display_name"
]
=
params
[
param_name
][
param
]
elif
param
==
"exclude"
:
...
...
@@ -362,7 +373,13 @@ class Workflow(threading.Thread):
if
sub_order
.
has_key
(
param_name
):
for
sub_param
in
sub_order
[
param_name
]:
sub
=
Parameter
(
**
sub_params
[
sub_param
])
hash_sub_params
[
sub
.
name
]
=
sub
sub_objs
.
append
(
sub
)
# overwrite the group to exclude some parameters
for
i
,
exclude_group
in
enumerate
(
sub_excludes
):
group_name
=
"exclude-"
+
str
(
i
)
for
sparam
in
set
(
exclude_group
):
hash_sub_params
[
sparam
].
group
=
group_name
current_params
[
"sub_parameters"
]
=
sub_objs
oparam
=
Parameter
(
**
current_params
)
parameters
.
append
(
oparam
)
...
...
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