added recursion, needs debugging

This commit is contained in:
2025-10-03 19:13:53 +02:00
parent 0e84c959ce
commit acd3f5fe39
4 changed files with 78 additions and 40 deletions

View File

@@ -7,7 +7,7 @@ from .refit_logger import logger
# reusable
def get_standard_name_number(current_number: str, number_str_length: int) -> str:
def get_standard_name_number(current_number: int, number_str_length: int) -> str:
"""Returns a number string filled to the length of the input number
This function returns the number in a standartized way as a string.
@@ -27,8 +27,8 @@ def get_standard_name_number(current_number: str, number_str_length: int) -> str
# logger.debug(
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
# )
current_number = str(current_number)
standard_name_number = str.zfill(current_number, number_str_length)
temp_current_number = str(current_number)
standard_name_number = str.zfill(temp_current_number, number_str_length)
# logger.debug(
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
# )
@@ -121,13 +121,6 @@ def get_current_path(path) -> str:
str: _Returns the path of the current directory after check for existence_
"""
# TODO: write test for the current path function, test for:
# - None
# - for existing path
# - for non existing path
# NOTE: research how to check for paths in test functions...
logger.debug(f"FUNC: get_current_path() MSG: entered function with path = '{path}'")
if path is None:
# Set the current directory if none is passed with the command.
@@ -150,3 +143,38 @@ def get_current_path(path) -> str:
logger.warning(ERROR_MESSAGE)
print(ERROR_MESSAGE)
sys.exit(1)
# FIXME: th function needs some attention
# TODO:
# - add proper debugging
# - make it walk down one directory.
def create_recursive_folders(
input_path, target_depth, current_depth, width, curret_width
):
"""Creates a recursive directory structure with y as depth and x as width"""
if current_depth == target_depth:
sys.exit(1)
# length_width = str(len(width))
length_width = len(str(width))
logger.debug(
f"FUNC: create_recursive_folders(length_width) MSG: length_width='{length_width}'"
)
while curret_width < width:
# TODO: fix the issue, that the number gets appended to an existing number
new_directory_name = "sub_dir" + get_standard_name_number(length_width, width)
new_directory_path = os.path.join(input_path, new_directory_name)
print(new_directory_path)
curret_width += 1
create_recursive_folders(
new_directory_path,
target_depth,
width,
current_depth + 1,
curret_width,
)
# create_recursive_folders(".", 2, 0, 3)