@@ -13,18 +13,23 @@ class ConfigManager:
1313 Class for handling metadata of reports from YAML config file and creating report objects.
1414 """
1515
16- def __init__ (self , logger : Optional [logging .Logger ] = None ):
16+ def __init__ (self , logger : Optional [logging .Logger ] = None , max_depth : int = 2 ):
1717 """
1818 Initializes the ConfigManager with a logger.
1919
2020 Parameters
2121 ----------
2222 logger : logging.Logger, optional
2323 A logger instance for the class. If not provided, a default logger will be created.
24+ max_depth : int, optional
25+ The maximum depth of the directory structure to consider when generating the report
26+ config from a directory.
27+ The default is 2, which means it will include sections and subsections.
2428 """
2529 if logger is None :
2630 logger , _ = get_logger ("report" )
2731 self .logger = logger
32+ self .max_depth = max_depth
2833
2934 def _create_title_fromdir (self , file_dirname : str ) -> str :
3035 """
@@ -198,7 +203,7 @@ def _read_description_file(self, folder_path: Path) -> str:
198203 return ""
199204
200205 def _create_subsect_config_fromdir (
201- self , subsection_dir_path : Path
206+ self , subsection_dir_path : Path , level : int = 2
202207 ) -> Dict [str , Union [str , List [Dict ]]]:
203208 """
204209 Creates subsection config from a directory.
@@ -217,7 +222,6 @@ def _create_subsect_config_fromdir(
217222 sorted_files = self ._sort_paths_by_numprefix (
218223 list (subsection_dir_path .iterdir ())
219224 )
220-
221225 components = []
222226 for file in sorted_files :
223227 if file .is_file ():
@@ -227,9 +231,17 @@ def _create_subsect_config_fromdir(
227231 continue
228232 # Add component config to list
229233 components .append (component_config )
230- # ! if folder go into folder and pull files out?
231- # nesting level already at point 2
232- # loop of components in a folder
234+ elif file .is_dir ():
235+ if level > self .max_depth :
236+ self .logger .warning (
237+ "Subsection nesting level exceeded: %s. Skipping." , file .name
238+ )
239+ continue
240+ # components are added to subsection
241+ # ! Alternatively, one could add (sub-)sections to the subsection
242+ # ? Then one could remove differentiation between sections and subsections
243+ nested_components = self ._create_subsect_config_fromdir (file , level + 1 )
244+ components .extend (nested_components ["components" ])
233245
234246 subsection_config = {
235247 "title" : self ._create_title_fromdir (subsection_dir_path .name ),
0 commit comments