From d19a158e10ada652fb1bf1549dac4f1f3446aa5a Mon Sep 17 00:00:00 2001 From: lecorguille Date: Thu, 23 Feb 2017 16:58:30 +0100 Subject: [PATCH 1/4] Allow nest param in the dynamic_tool rule -> argument --- lib/galaxy/jobs/dynamic_tool_destination.py | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/jobs/dynamic_tool_destination.py b/lib/galaxy/jobs/dynamic_tool_destination.py index bec27cb7ef7..d187917d498 100755 --- a/lib/galaxy/jobs/dynamic_tool_destination.py +++ b/lib/galaxy/jobs/dynamic_tool_destination.py @@ -28,6 +28,22 @@ class ScannerError(Exception): pass +def is_arg_in_options(arg_list,options): + """ + This recursive function check if an argument in the options dictionary + The argument can have those shape: input or inputs|input + """ + arg_parent = arg_list[0] + log.debug(arg_parent) + log.debug(options) + if not arg_parent in options: + return False + else: + if len(arg_list) > 1: + return(is_arg_in_options(arg_list[1:],options[arg_parent])) + else: + return options[arg_parent] + class RuleValidator: """ This class is the primary facility for validating configs. It's always called @@ -1290,18 +1306,18 @@ def map_tool_to_destination( elif rule["rule_type"] == "arguments": options = job.get_param_values(app) matched = True - # check if the args in the config file are available for arg in rule["arguments"]: - if arg in options: - if rule["arguments"][arg] != options[arg]: + value = is_arg_in_options(arg.split("|"),options) + if value: + if rule["arguments"][arg] != value: matched = False options = "test" else: matched = False if verbose: error = "Argument '" + str(arg) - error = + "' not recognized!" + error += "' not recognized!" log.debug(error) # if we matched a rule From 73921a21e9164bad342269ed3fe3c347d42a5c8d Mon Sep 17 00:00:00 2001 From: lecorguille Date: Tue, 28 Feb 2017 16:09:47 +0100 Subject: [PATCH 2/4] change the tool_destinations.yml the argument rules syntax --- lib/galaxy/jobs/dynamic_tool_destination.py | 35 ++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/galaxy/jobs/dynamic_tool_destination.py b/lib/galaxy/jobs/dynamic_tool_destination.py index d187917d498..e5c1a596c67 100755 --- a/lib/galaxy/jobs/dynamic_tool_destination.py +++ b/lib/galaxy/jobs/dynamic_tool_destination.py @@ -28,21 +28,17 @@ class ScannerError(Exception): pass -def is_arg_in_options(arg_list,options): +def get_keys_from_dict(dl, keys_list): """ - This recursive function check if an argument in the options dictionary - The argument can have those shape: input or inputs|input + This function builds a list using the keys from nest dictionaries """ - arg_parent = arg_list[0] - log.debug(arg_parent) - log.debug(options) - if not arg_parent in options: - return False - else: - if len(arg_list) > 1: - return(is_arg_in_options(arg_list[1:],options[arg_parent])) - else: - return options[arg_parent] + if isinstance(dl, dict): + keys_list += dl.keys() + map(lambda x: get_keys_from_dict(x, keys_list), dl.values()) + elif isinstance(dl, list): + map(lambda x: get_keys_from_dict(x, keys_list), dl) + + class RuleValidator: """ @@ -1308,12 +1304,15 @@ def map_tool_to_destination( matched = True # check if the args in the config file are available for arg in rule["arguments"]: - value = is_arg_in_options(arg.split("|"),options) - if value: - if rule["arguments"][arg] != value: + arg_dict = {arg : rule["arguments"][arg]} + arg_keys_list = [] + get_keys_from_dict(arg_dict, arg_keys_list) + try: + options_value=reduce(dict.__getitem__, arg_keys_list, options) + arg_value=reduce(dict.__getitem__, arg_keys_list, arg_dict) + if (arg_value != options_value): matched = False - options = "test" - else: + except KeyError: matched = False if verbose: error = "Argument '" + str(arg) From 705eb17b02b748ce76b5644386c793a610d9ab90 Mon Sep 17 00:00:00 2001 From: lecorguille Date: Tue, 28 Feb 2017 16:25:58 +0100 Subject: [PATCH 3/4] fix python syntax --- lib/galaxy/jobs/dynamic_tool_destination.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/jobs/dynamic_tool_destination.py b/lib/galaxy/jobs/dynamic_tool_destination.py index e5c1a596c67..5c2187087be 100755 --- a/lib/galaxy/jobs/dynamic_tool_destination.py +++ b/lib/galaxy/jobs/dynamic_tool_destination.py @@ -11,6 +11,7 @@ import sys import copy import collections import re +from functools import reduce # log to galaxy's logger @@ -39,7 +40,6 @@ def get_keys_from_dict(dl, keys_list): map(lambda x: get_keys_from_dict(x, keys_list), dl) - class RuleValidator: """ This class is the primary facility for validating configs. It's always called @@ -1306,10 +1306,10 @@ def map_tool_to_destination( for arg in rule["arguments"]: arg_dict = {arg : rule["arguments"][arg]} arg_keys_list = [] - get_keys_from_dict(arg_dict, arg_keys_list) + get_keys_from_dict(arg_dict, arg_keys_list) try: - options_value=reduce(dict.__getitem__, arg_keys_list, options) - arg_value=reduce(dict.__getitem__, arg_keys_list, arg_dict) + options_value = reduce(dict.__getitem__, arg_keys_list, options) + arg_value = reduce(dict.__getitem__, arg_keys_list, arg_dict) if (arg_value != options_value): matched = False except KeyError: From d624b04f25510475bd1cb48fbcbdca471bc1a5d7 Mon Sep 17 00:00:00 2001 From: lecorguille Date: Tue, 28 Feb 2017 16:29:01 +0100 Subject: [PATCH 4/4] update the documentation --- config/tool_destinations.yml.sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/tool_destinations.yml.sample b/config/tool_destinations.yml.sample index 296a14fc84d..189cc86f583 100644 --- a/config/tool_destinations.yml.sample +++ b/config/tool_destinations.yml.sample @@ -121,7 +121,9 @@ # destination: fail # fail_message: Don't do that # arguments: -# careful: true +# my_section: +# my_condition: +# careful: true # default_destination: cluster_low # default_destination: cluster # verbose: False