Exemple #1
0
def check_args(arguments, data_frame):
    """
    check arguments against a command_line_dataframe.
    checks that:
    all arguments are valid
    all required arguments are present
    default values are used where needed
    """
    stripped_args = [a[0] for a in arguments]
    df = data_frame.df
    # first make sure all args are valid
    for a in arguments:
        if a[0] not in df.index:
            print("-I- ignoring invalid argument: {}".format(a[0]))
            print("-")
    # next make sure required arguments are present
    condition = df['reqd']
    reqd_args = df[condition]
    for arg in reqd_args['arg_name']:
        if arg not in stripped_args:
            raise pmag.MissingCommandLineArgException("-" + arg)
    #next, assign any default values as needed

    #condition = df['default'] != '' # don't need this, and sometimes the correct default argument IS ''
    default_args = df  #[condition]
    using_defaults = []
    for arg_name, row in default_args.iterrows():
        default = row['default']
        if arg_name not in stripped_args:
            using_defaults.append(arg_name)
            arguments.append([arg_name, default])
    using_defaults = ["-" + arg for arg in using_defaults]
    print('Using default arguments for: {}'.format(', '.join(using_defaults)))
    return arguments
def check_args(arguments, data_frame):
    """
    check arguments against a command_line_dataframe.
    checks that:
    all arguments are valid
    all required arguments are present
    default values are used where needed
    """
    stripped_args = [a[0] for a in arguments]
    df = data_frame.df
    # first make sure all args are valid
    for a in arguments:
        if a[0] not in df.index:
            print "-I- ignoring invalid argument: {}".format(a[0])
            print "-"
    # next make sure required arguments are present
    condition = df['reqd']
    reqd_args = df[condition]
    for arg in reqd_args['arg_name']:
        if arg not in stripped_args:
            raise pmag.MissingCommandLineArgException("-"+arg)
    #next, assign any default values as needed
    
    #condition = df['default'] != '' # don't need this, and sometimes the correct default argument IS ''
    default_args = df #[condition]
    for value in default_args.values:
        arg_name, default = value[0], value[1]
        if arg_name not in stripped_args:
            print "-I- using default for arg:", arg_name
            print "-"
            arguments.append([arg_name, default])
    return arguments