Skip to content

Commit 580def3

Browse files
committed
Support MLC_TMP_FOLDER for file search in script automation
1 parent d838850 commit 580def3

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

automation/script/module.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def __init__(self, action_object, automation_file, run_args={}):
7878
"SOCKS_PROXY"]
7979

8080
self.input_flags_converted_to_tmp_env = {
81-
'path': {'desc': 'Filesystem path to search for executable', 'default': ''}}
81+
'path': {'desc': 'Filesystem path to search for executable', 'default': ''},
82+
'folder': {'desc': 'Folder to search first before other paths', 'default': ''}}
8283

8384
self.input_flags_converted_to_env = {'input': {'desc': 'Input to the script passed using the env key `MLC_INPUT`', 'default': ''},
8485
'output': {'desc': 'Output from the script passed using the env key `MLC_OUTPUT`', 'default': ''},
@@ -3984,13 +3985,33 @@ def find_artifact(self, i):
39843985
# [] if default_path_env_key == '' else \
39853986
# os.environ.get(default_path_env_key,'').split(os_info['env_separator'])
39863987

3988+
3989+
# Check if a prioritized folder is provided
3990+
# Search order: MLC_TMP_PATH -> priority folder (MLC_TMP_FOLDER) -> default_path_list
3991+
priority_folder = env.get('MLC_TMP_FOLDER', '').strip()
3992+
priority_folder_paths = []
3993+
3994+
if priority_folder and os.path.isdir(priority_folder):
3995+
logger.info(self.recursion_spaces + ' # Prioritizing search in folder: {}'.format(priority_folder))
3996+
# Add the folder and its subdirectories to priority paths (max depth to avoid NFS issues)
3997+
priority_folder_paths.append(priority_folder)
3998+
max_depth = int(env.get('MLC_TMP_FOLDER_MAX_DEPTH', '4'))
3999+
for root, dirs, files_in_dir in os.walk(priority_folder):
4000+
# Calculate current depth relative to priority_folder
4001+
depth = root[len(priority_folder):].count(os.sep)
4002+
if depth >= max_depth:
4003+
# Stop descending into subdirectories at this level
4004+
dirs[:] = []
4005+
if root not in priority_folder_paths:
4006+
priority_folder_paths.append(root)
4007+
39874008
if path == '':
3988-
path_list_tmp = default_path_list
4009+
path_list_tmp = priority_folder_paths + default_path_list
39894010
else:
39904011
logger.info(
39914012
self.recursion_spaces +
39924013
' # Requested paths: {}'.format(path))
3993-
path_list_tmp = path.split(os_info['env_separator'])
4014+
path_list_tmp = path.split(os_info['env_separator']) + priority_folder_paths
39944015

39954016
# Check soft links
39964017
path_list_tmp2 = []

0 commit comments

Comments
 (0)