def search_actions(cls):
# if we load the actions yet, return them
if len(Action.python_files) > 0:
return Action.python_files
# elsewere, load all the custom actions you find
Global.LOGGER.debug("searching for installed actions... it can takes a while")
site_packages = site.getsitepackages()
Global.LOGGER.debug(f"current path: {os.getcwd()}")
# get custom actions in current path
Global.LOGGER.debug("looking inside the current directory")
tmp_python_files_in_current_directory = glob.glob(f"{os.getcwd()}/*Action.py", recursive=False)
Global.LOGGER.debug(f"found {len(tmp_python_files_in_current_directory)} actions in current directory")
basenames = list(map(os.path.basename, tmp_python_files_in_current_directory))
tmp_python_files_dict = dict(zip(basenames, tmp_python_files_in_current_directory))
# get custom actions in current /Action subdir
Global.LOGGER.debug("looking inside any ./Actions subdirectory")
tmp_python_files_in_current_action_subdirectory = glob.glob(f"{os.getcwd()}/**/Actions/*Action.py", recursive=True)
Global.LOGGER.debug(f"found {len(tmp_python_files_in_current_action_subdirectory)} actions in a ./Actions subdirectory")
for action_file in tmp_python_files_in_current_action_subdirectory:
action_filename = os.path.basename(action_file)
if action_filename not in tmp_python_files_dict:
tmp_python_files_dict[action_filename] = action_file
# get custom actions in site_packages directory
Global.LOGGER.debug("looking inside the Python environment")
for my_site in site_packages:
tmp_python_files_in_site_directory = glob.glob(f"{my_site}/**/Actions/*Action.py", recursive=True)
Global.LOGGER.debug(f"found {len(tmp_python_files_in_site_directory)} actions in {my_site}")
for action_file in tmp_python_files_in_site_directory:
action_filename = os.path.basename(action_file)
if action_filename not in tmp_python_files_dict:
tmp_python_files_dict[action_filename] = action_file
# Action.python_files = list(set(tmp_python_files))
action_files = tmp_python_files_dict.values()
if len(action_files) > 0:
Global.LOGGER.debug(f"{len(action_files)} actions found")
if Global.CONFIG_MANAGER.tracing_mode:
actions_found = "\n".join(action_files)
Global.LOGGER.debug(f"actions found: \n{actions_found}")
else:
Global.LOGGER.debug(f"no actions found on {my_site}")
Action.python_files = action_files
return action_files
评论列表
文章目录