def init_robot_file_path(robot_file_path):
    r"""
    Determine full path name for the file path passed in robot_file_path and
    return it.

    If robot_file_path contains a fully qualified path name, this function
    will verify that the file exists.  If robot_file_path contains a relative
    path, this function will search for the file and set robot_file_path so
    that it contains the absolute path to the robot file.  This function will
    search for the robot file using the raw_robot_file_search_path (defined
    above).  Note that if ROBOT_TEST_BASE_DIR_PATH is not set, this function
    will call init_robot_test_base_dir_path to set it.

    Description of arguments:
    robot_file_path                 The absolute or relative path to a robot
                                    file.
    """

    gv.valid_value(robot_file_path)

    try:
        if ROBOT_TEST_BASE_DIR_PATH is NONE:
            init_robot_test_base_dir_path()
    except NameError:
        init_robot_test_base_dir_path()

    if not re.match(r".*\.(robot|py)$", robot_file_path):
        # No suffix so we'll assign one of "\.robot".
        robot_file_path = robot_file_path + ".robot"

    abs_path = 0
    if robot_file_path[0:1] == "/":
        abs_path = 1

    gp.dprint_vars(abs_path, robot_file_path)

    if not abs_path:
        cmd_buf = "echo -n \"" + raw_robot_file_search_path + "\""
        shell_rc, out_buf = gc.shell_cmd(cmd_buf,
                                         quiet=(not debug),
                                         print_output=0)
        robot_file_search_paths = out_buf
        gp.dprint_var(robot_file_search_paths)
        robot_file_search_paths_list = robot_file_search_paths.split(':')
        for search_path in robot_file_search_paths_list:
            search_path = gm.add_trailing_slash(search_path)
            candidate_file_path = search_path + robot_file_path
            gp.dprint_var(candidate_file_path)
            if os.path.isfile(candidate_file_path):
                gp.dprint_timen("Found full path to " + robot_file_path + ".")
                robot_file_path = candidate_file_path
                break

    gp.dprint_var(robot_file_path)
    gv.valid_file_path(robot_file_path)

    return robot_file_path
def init_robot_file_path(robot_file_path):
    r"""
    Determine full path name for the file path passed in robot_file_path and
    return it.

    If robot_file_path contains a fully qualified path name, this function
    will verify that the file exists.  If robot_file_path contains a relative
    path, this function will search for the file and set robot_file_path so
    that it contains the absolute path to the robot file.  This function will
    search for the robot file using the raw_robot_file_search_path (defined
    above).  Note that if ROBOT_TEST_BASE_DIR_PATH is not set, this function
    will call init_robot_test_base_dir_path to set it.

    Description of arguments:
    robot_file_path                 The absolute or relative path to a robot
                                    file.
    """

    if not gv.valid_value(robot_file_path):
        raise ValueError('Programmer error.')

    try:
        if ROBOT_TEST_BASE_DIR_PATH is NONE:
            init_robot_test_base_dir_path()
    except NameError:
        init_robot_test_base_dir_path()

    if not re.match(r".*\.(robot|py)$", robot_file_path):
        # No suffix so we'll assign one of "\.robot".
        robot_file_path = robot_file_path + ".robot"

    abs_path = 0
    if robot_file_path[0:1] == "/":
        abs_path = 1

    gp.dprint_vars(abs_path, robot_file_path)

    if not abs_path:
        cmd_buf = "echo -n \"" + raw_robot_file_search_path + "\""
        shell_rc, out_buf = gc.shell_cmd(cmd_buf, quiet=(not debug),
                                         print_output=0)
        robot_file_search_paths = out_buf
        gp.dprint_var(robot_file_search_paths)
        robot_file_search_paths_list = robot_file_search_paths.split(':')
        for search_path in robot_file_search_paths_list:
            search_path = gm.add_trailing_slash(search_path)
            candidate_file_path = search_path + robot_file_path
            gp.dprint_var(candidate_file_path)
            if os.path.isfile(candidate_file_path):
                gp.dprint_timen("Found full path to " + robot_file_path + ".")
                robot_file_path = candidate_file_path
                break

    gp.dprint_var(robot_file_path)
    if not gv.valid_file_path(robot_file_path):
        raise ValueError('Programmer error.')

    return robot_file_path
Exemple #3
0
def valid_file_path(var_name, *args, **kwargs):

    var_value, args, kwargs = valid_init(var_name, *args, **kwargs)
    error_message = \
        gv.valid_file_path(var_value, *args, var_name=var_name, **kwargs)
    process_error_message(error_message)