Skip to content
Snippets Groups Projects
Commit 01a13757 authored by Carlo Ferriolo's avatar Carlo Ferriolo
Browse files

[FIX] fix function for path


The function find_directory_in_children has been modified to set correctly the path if more directory is given as
reference (e.g.  meta-browser/meta-chromium)

Signed-off-by: default avatarcarlo <carlo.ferriolo@seco.com>
parent 703ac883
No related branches found
No related tags found
No related merge requests found
Pipeline #244907 passed with stage
in 1 minute and 14 seconds
...@@ -245,13 +245,13 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern): ...@@ -245,13 +245,13 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern):
return matching_paths return matching_paths
## @brief Searches for a directory with a specific name in the child directories of a given parent directory. ## @brief Searches for a directory with a specific name in the child directories of a given parent directory.
# This function traverses all the child directories of the specified parent directory, looking for # This function look for the path starting from the parent directory to the directory with the specified name,
# a directory with the specified name. If found, it returns the absolute path to the directory; # verifying that this exists.
# If found, it returns the path to the directory;
# otherwise, it returns `None`. # otherwise, it returns `None`.
# @param parent_dir The directory from which to start searching. All child directories within this directory # @param parent_dir The directory from which to start searching.
# will be searched recursively.
# @param target_dir_name The name of the directory to search for within the child directories. # @param target_dir_name The name of the directory to search for within the child directories.
# @return The absolute path to the directory if found, otherwise `None`. # @return The path to the directory if found, otherwise `None`.
# @note This function does not follow symbolic links to directories. # @note This function does not follow symbolic links to directories.
# @note The search is case-sensitive, meaning it will look for an exact match of `target_dir_name`. # @note The search is case-sensitive, meaning it will look for an exact match of `target_dir_name`.
# @example # @example
...@@ -264,12 +264,13 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern): ...@@ -264,12 +264,13 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern):
# else: # else:
# print("Directory not found.") # print("Directory not found.")
# @endcode # @endcode
def find_directory_in_children(parent_dir, target_dir_name):
for root, dirs, _ in os.walk(parent_dir):
if target_dir_name in dirs:
return os.path.join(root, target_dir_name)
return None
def find_directory_in_children(parent_dir, target_dir_name):
path = os.path.join(parent_dir,target_dir_name)
if os.path.exists(path):
return path
else:
return None
## @brief Searches for a file in parent directories starting from the specified directory. ## @brief Searches for a file in parent directories starting from the specified directory.
# This function traverses parent directories starting from `start_dir` and searches for the specified filename. # This function traverses parent directories starting from `start_dir` and searches for the specified filename.
...@@ -306,4 +307,4 @@ def find_folder_in_parents_dirs(start_dir, folder_name): ...@@ -306,4 +307,4 @@ def find_folder_in_parents_dirs(start_dir, folder_name):
return folder_path return folder_path
current_dir = os.path.dirname(current_dir) current_dir = os.path.dirname(current_dir)
return None return None
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment