Skip to content
Snippets Groups Projects
Commit 2d2279cf 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 -> layers/meta-browser/meta-chromium). The function still work
if the only given path is the meta-layer executing a child finding process which take to the same solution
(e.g. meta-chromium -> layers/meta-browser/meta-chromium). To make all work correctly use meta-layers after layers
(e.g. if the layer can be found in layers/meta-browser/meta-chromium -> use only meta-browser/meta-chromiumwq).

Signed-off-by: default avatarcarlo <carlo.ferriolo@seco.com>
parent a28e2d64
No related branches found
No related tags found
1 merge request!36[FIX] fix function for path
Pipeline #272841 failed with stage
in 50 seconds
...@@ -335,9 +335,15 @@ def add_layer_to_bblayer_conf(layer_name, layers_dir, bblayers_conf_path): ...@@ -335,9 +335,15 @@ def add_layer_to_bblayer_conf(layer_name, layers_dir, bblayers_conf_path):
layer_path = ssu.find_directory_in_children(layers_dir, layer_name) layer_path = ssu.find_directory_in_children(layers_dir, layer_name)
if layer_path != None: if layer_path != None:
logger.debug(f"Adding to bblayers.conf the layer {layer_path}") logger.debug(f"Adding to bblayers.conf the layer {layer_path}")
# This condition is useful to determine the position of "layers" in the layer_path
# such that the string can be written correctly
parts = layer_path.split("/")
if "layers" in parts:
idx = parts.index("layers")
path = "/".join(parts[idx + 1:])
string = ("\n" string = ("\n"
"BBLAYERS += \"\\\n" "BBLAYERS += \"\\\n"
" ${BSPDIR}/layers/" + layer_name + " \\\n" " ${BSPDIR}/layers/" + path + " \\\n"
"\"") "\"")
ssu.append_to_file(bblayers_conf_path, string) ssu.append_to_file(bblayers_conf_path, string)
clean_bblayers_conf(bblayers_conf_path) clean_bblayers_conf(bblayers_conf_path)
......
...@@ -245,13 +245,14 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern): ...@@ -245,13 +245,14 @@ 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 the target_dir_name given is a path, this is used as path to be appended to parent_dir
# 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 +265,20 @@ def find_files_with_pattern_in_children_dirs(start_dir, pattern): ...@@ -264,12 +265,20 @@ 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):
target_dirs = target_dir_name.split("/")
if len(target_dirs) > 1 :
path = os.path.join(parent_dir,target_dir_name)
else:
for root, dirs, _ in os.walk(parent_dir):
if target_dir_name in dirs:
return os.path.join(root, target_dir_name)
return None
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 +315,4 @@ def find_folder_in_parents_dirs(start_dir, folder_name): ...@@ -306,4 +315,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