From fe562e142339674566c5e443a58d2b2c208d01f0 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Wed, 25 Mar 2020 13:42:59 +0000 Subject: [PATCH] updated create_arg_string to have more options --- binarycpython/utils/functions.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index 18371010a..f1ef1fad5 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -364,13 +364,29 @@ def get_help_all(print_help=True, return_dict=False): return None -def create_arg_string(arg_dict): +def create_arg_string(arg_dict, sort=False, filter_values=False): """ Function that creates the arg string + + Options: + sort: sort the order of the keys + filter_values: filters the input dict on keys that have NULL or `function` as value + """ arg_string = "" - for key in arg_dict.keys(): - arg_string += "{key} {value} ".format(key=key, value=arg_dict[key]) + + # + keys = sorted(arg_dict.keys()) if sort else arg_dict.keys() + + # + for key in keys: + # Filter out NULLS (not compiled anyway) + if filter_values: + if not value in ["NULL", "Function"]: + if not value == "": + default_dict[key] = value + else: + arg_string += "{key} {value} ".format(key=key, value=arg_dict[key]) arg_string = arg_string.strip() return arg_string -- GitLab