Example #1
0
def parseArgs(args):
    """
    Parses arguments and returns dictionary.
    """
    arg_dict = {}
    a = arg_dict

    # Set up defaults
    a["nc_file"] = None
    a["var_ids"] = None
    a["requested_ffi"] = None
    a["float_format"] = nappy.default_float_format
    a["delimiter"] = nappy.default_delimiter
    a["size_limit"] = None
    a["exclude_vars"] = []
    a["na_items_to_override"] = {}
    a["only_return_file_names"] = False
    a["na_file"] = None
    a["no_header"] = False
    a["annotation"] = False

    try:
        (arg_list, dummy) = getopt.getopt(args, "i:o:v:f:d:l:e:",
                              ["ffi=", "overwrite-metadata=", "names-only",
                               "no-header", "annotated"])
    except getopt.GetoptError as e:
        exitNicely(str(e))

    for arg, value in arg_list:
        if arg == "-i":
            a["nc_file"] = value
        elif arg == "-o":
            a["na_file"] = value
        elif arg == "-v":
            a["var_ids"] = value.split(",")
        elif arg == "--ffi":
            a["requested_ffi"] = int(value)
        elif arg == "-f":
            a["float_format"] = value
        elif arg == "-d":
            a["delimiter"] = value
        elif arg == "--limit_ffi_1001_rows":
            a["size_limit"] = int(value)
        elif arg == "-e":
            a["exclude_vars"] = value.split(",")
        elif arg == "--overwrite-metadata":
            a["na_items_to_override"] = makeDictFromCommaSepString(value)
        elif arg == "--names-only":
            a["only_return_file_names"] = True
        elif arg == "--no-header":
            a["no_header"] = True
        elif arg == "--annotated":
            a["annotation"] = True
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["nc_file"]:
        exitNicely("Please provide argument '-i <nc_file>'")

    return a
Example #2
0
def parseArgs(args):
    """
    Parses arguments and returns dictionary.
    """
    arg_dict = {}
    a = arg_dict

    # Set up defaults
    a["na_file"] = None
    a["mode"] = "w"
    a["variables"] = "all"
    a["aux_variables"]  = "all"
    a["global_attributes"] = {}
    a["rename_variables"] = {}
    a["time_units"] = None
    a["time_warning"] = True
    a["nc_file"] = None

    try:
        (arg_list, dummy) = getopt.getopt(args, "i:o:m:v:a:g:t:nr:")
    except getopt.GetoptError as e:
        exitNicely(str(e))

    for arg, value in arg_list:
        if arg == "-i":
            a["na_file"] = value
        elif arg == "-o":
            a["nc_file"] = value
        elif arg == "-m":
            a["mode"] = value
        elif arg == "-v":
            a["variables"] = value.split(",")
            exitNicely("OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry." % arg)
        elif arg == "-a":
            a["aux_variables"] = value.split(",")
            exitNicely("OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry." % arg)
        elif arg == "-g":
            a["global_attributes"] = makeListFromCommaSepString(value)
        elif arg == "-t":
            a["time_units"] = value
        elif arg == "-n":
            a["time_warning"] = False
        elif arg == "-r":
            a["rename_variables"] = makeDictFromCommaSepString(value)
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["na_file"]:
        exitNicely("Please provide argument '-i <na_file>'")

    if not a["nc_file"]:
        fn = a["na_file"]
        if fn[-3:] == ".na": fn = fn[:-3]
        nc_file = fn + ".nc"
        print("Auto-generating output file name:", nc_file)
        a["nc_file"] = nc_file

    return a
Example #3
0
            exitNicely(
                "OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry."
                % arg)
        elif arg == "-a":
            a["aux_variables"] = value.split(",")
            exitNicely(
                "OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry."
                % arg)
        elif arg == "-g":
            a["global_attributes"] = makeListFromCommaSepString(value)
        elif arg == "-t":
            a["time_units"] = value
        elif arg == "-n":
            a["time_warning"] = False
        elif arg == "-r":
            a["rename_variables"] = makeDictFromCommaSepString(value)
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["na_file"]:
        exitNicely("Please provide argument '-i <na_file>'")

    if not a["nc_file"]:
        fn = a["na_file"]
        if fn[-3:] == ".na": fn = fn[:-3]
        nc_file = fn + ".nc"
        print "Auto-generating output file name:", nc_file
        a["nc_file"] = nc_file

    return a
Example #4
0
        elif arg == "-o":
            a["na_file"] = value
        elif arg == "-v":
            a["var_ids"] = value.split(",")
        elif arg == "--ffi":
            a["requested_ffi"] = int(value)
        elif arg == "-f":
            a["float_format"] = value
        elif arg == "-d":
            a["delimiter"] = value
        elif arg == "--limit_ffi_1001_rows":
            a["size_limit"] = long(value)
        elif arg == "-e":
            a["exclude_vars"] = value.split(",")
        elif arg == "--overwrite-metadata":
            a["na_items_to_override"] = makeDictFromCommaSepString(value)
        elif arg == "--names-only":
            a["only_return_file_names"] = True
        elif arg == "--no-header":
            a["no_header"] = True
        elif arg == "--annotated":
            a["annotation"] = True
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["nc_file"]:
        exitNicely("Please provide argument '-i <nc_file>'")

    return a

Example #5
0
        elif arg == "-m":
            a["mode"] = value
        elif arg == "-v":
            a["variables"] = value.split(",")
            exitNicely("OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry." % arg)
        elif arg == "-a":
            a["aux_variables"] = value.split(",")
            exitNicely("OPTION NOT IMPLEMENTED: %s : Not yet fully functional. Sorry." % arg)
        elif arg == "-g":
            a["global_attributes"] = makeListFromCommaSepString(value)
        elif arg == "-t":
            a["time_units"] = value
        elif arg == "-n":
            a["time_warning"] = False
        elif arg == "-r":
            a["rename_variables"] = makeDictFromCommaSepString(value)
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["na_file"]:
        exitNicely("Please provide argument '-i <na_file>'")

    if not a["nc_file"]:
        fn = a["na_file"]
        if fn[-3:] == ".na": fn = fn[:-3]
        nc_file = fn + ".nc"
        print "Auto-generating output file name:", nc_file
        a["nc_file"] = nc_file

    return a
Example #6
0
        elif arg == "-o":
            a["na_file"] = value
        elif arg == "-v":
            a["var_ids"] = value.split(",")
        elif arg == "--ffi":
            a["requested_ffi"] = int(value)
        elif arg == "-f":
            a["float_format"] = value
        elif arg == "-d":
            a["delimiter"] = value
        elif arg == "--limit_ffi_1001_rows":
            a["size_limit"] = long(value)
        elif arg == "-e":
            a["exclude_vars"] = value.split(",")
        elif arg == "--overwrite-metadata":
            a["na_items_to_override"] = makeDictFromCommaSepString(value)
        elif arg == "--names-only":
            a["only_return_file_names"] = True
        elif arg == "--no-header":
            a["no_header"] = True
        elif arg == "--annotated":
            a["annotation"] = True
        else:
            exitNicely("Argument '" + arg + "' not recognised!")

    if not a["nc_file"]:
        exitNicely("Please provide argument '-i <nc_file>'")

    return a