1*** Settings ***
2Resource                ../lib/utils.robot
3Resource                ../lib/connection_client.robot
4Resource                ../lib/boot_utils.robot
5
6*** Variables ***
7# User defined path to do the cleanup.
8${CLEANUP_DIR_PATH}  ${EMPTY}
9# List that holds space separated filepaths to skip from cleanup.
10${SKIP_LIST}  ${EMPTY}
11
12*** Keywords ***
13
14
15Cleanup Dir
16    [Documentation]  Remove leftover files in cleanup directory path.
17    [Arguments]      ${cleanup_dir_path}=${CLEANUP_DIR_PATH}
18    ...              ${skip_list}=${SKIP_LIST}
19
20    # Description of argument(s):
21    # cleanup_dir_path  Directory path to do the cleanup.
22    # skip_list  List of files to skip from cleanup.
23
24    Should Not Be Empty  ${cleanup_dir_path}
25    Should Not Be Empty  ${SKIP_LIST}
26
27    ${skip_list_string}=  Set Variable  cd ${cleanup_dir_path}
28    FOR  ${file}  IN  @{skip_list}
29        ${skip_list_string}=   Set Variable  ${skip_list_string} && rm ${file}
30    END
31
32    ${file_count1}  ${stderr}  ${rc}=  BMC Execute Command
33    ...  find ${cleanup_dir_path} | wc -l
34    BMC Execute Command  ${skip_list_string}
35
36    ${file_count2}  ${stderrt}  ${rc}=  BMC Execute Command
37    ...  find ${cleanup_dir_path} | wc -l
38    Should Be True  ${file_count2} < ${file_count1}
39    # Delete the directory if it is empty.
40    Run Keyword If  ${file_count2} <= 1
41    ...  BMC Execute Command  rm -r ${cleanup_dir_path}
42