Compare commits

..

4 Commits

Author SHA1 Message Date
e9b491e81d patch bump 2025-10-04 19:19:48 +02:00
e243f5f379 added linear recursion 2025-10-04 19:19:22 +02:00
c1e76b660a added recursive functions and number length function 2025-10-04 19:17:17 +02:00
1c557913f9 update README.md 2025-10-04 19:16:07 +02:00
4 changed files with 87 additions and 61 deletions

View File

@@ -23,8 +23,12 @@ n -> valid input check back for no arguments passed?
positional
- implement back in the valid input check
## Changelog
## Changelog
<2025-10-04> V0.3.5 - Added a function which returns the length of a
number
<2025-10-04> V0.3.5 - Changed the recursive mode into an linear x*y
pattern
<2025-10-04> V0.3.4 - Added recursive directory creation and fixed
numbered naming
<2025-10-03> V0.3.3 - Added the beginning of recursive mode

View File

@@ -7,6 +7,28 @@ from .refit_logger import logger
# reusable
def get_int_length(number: int) -> int:
"""Takes an number as its input and returns the numbers diget amount.
This function takes an integer number, converts it into a string and
converts its digets. It returns the length of the number as an integer.
Args:
number (int): The number you need the length of
Examples:
>>> get_int_length(100)
'3'
>>> get_int_length(10)
'2'
>>> get_int_length(4000)
'4'
"""
number_string = str(number)
amount_didgets = len(number_string)
return amount_didgets
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
@@ -24,14 +46,14 @@ def get_standard_name_number(current_number: int, number_str_length: int) -> str
>>> get_standard_name_number(23, 4)
'0023'
"""
logger.debug(
f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
)
# logger.debug(
# f"FUNC: get_standard_name_number() index={current_number} string_length={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}'"
)
# logger.debug(
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
# )
return standard_name_number
@@ -59,15 +81,8 @@ def get_standard_folder_name(name: str) -> str:
'directory_name'
"""
logger.debug(
f"FUNC: get_standard_folder_name() MSG: entered function with value: '{name}'"
)
standard_folder_name = name[0] if name is not None else "directory"
logger.debug(
f"FUNC: get_standard_folder_name() MSG: exiting function with folder name: '{standard_folder_name}'"
)
return standard_folder_name
@@ -95,15 +110,8 @@ def get_standard_file_name(name) -> str:
'file_name'
"""
logger.debug(
f"FUNC: get_standard_file_name() MSG: entered function with name='{name}'"
)
standard_file_name = name[0] if name is not None else "file"
logger.debug(
f"FUNC: get_standard_file_name MSG: Continuing with expected input: '{standard_file_name}'"
)
logger.debug("FUNC get_standard_file_name() MSG: Exit")
return standard_file_name
@@ -125,16 +133,16 @@ def get_current_path(path) -> str:
if path is None:
# Set the current directory if none is passed with the command.
path = "."
logger.warning(
f"FUNC: {get_current_path.__name__}() MSG: Path now has the value: '{path}'"
)
# logger.warning(
# f"FUNC: {get_current_path.__name__}() MSG: Path now has the value: '{path}'"
# )
return path
else:
# Checks if the path, entered by the user, exists.
if os.path.exists(path) is True:
logger.debug(
f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue...."
)
# logger.debug(
# f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue...."
# )
return path
else:
ERROR_MESSAGE = (
@@ -145,37 +153,44 @@ def get_current_path(path) -> str:
sys.exit(1)
# TODO: - add logging
# TODO: - add dynamic name input
# - add docstring
# - add proper naming to the files
def create_recursive_folders(input_path, target_depth, current_depth, width):
"""Creates a recursive directory structure with y as depth and x as width"""
def create_linear_directories(input_path, target_depth, current_depth):
"""Creates the linear directories for the x*y pattern"""
# Exits the recursion if the target depth is reached.
if current_depth >= target_depth:
return
# Getting the lenth of the number string which gets added to the dir name.
length_width = len(str(width))
logger.debug(
f"FUNC: create_recursive_folders(length_width) MSG: given values: path={input_path} target_depth={target_depth} current_depth={current_depth}, with={width}"
f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
)
# Creates the directories of the current depth
for i in range(width):
# Getting the numbering of the folder.
folder_index = i + 1
new_directory_name = "sub_dir" + get_standard_name_number(
folder_index, length_width
)
new_directory_path = os.path.join(input_path, new_directory_name)
os.mkdir(new_directory_path)
print(new_directory_path)
logger.debug(f"New Path: path={new_directory_path}")
if current_depth > target_depth:
return
create_recursive_folders(
new_directory_path,
target_depth,
current_depth + 1,
width,
)
directory_name = "level_" + get_standard_name_number(
current_depth,
get_int_length(target_depth),
)
path = os.path.join(input_path, directory_name)
os.mkdir(path)
create_linear_directories(path, target_depth, current_depth + 1)
# TODO: - add dynamic name input
# - add docstring
def create_parallel_directories(input_path, target_depth, width):
"""Creates directories after the pattern x*y"""
logger.debug(
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}'"
)
# # Getting the lenth of the number string which gets addedto the dir name.
# length_width = get_int_length(width)
for i in range(width):
directory_name = "branch_" + get_standard_name_number(i, get_int_length(width))
path = os.path.join(input_path, directory_name)
os.mkdir(path)
create_linear_directories(path, target_depth, current_depth=0)

View File

@@ -105,16 +105,23 @@ class Refit_Create:
logger.debug(
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'"
)
librefit.create_recursive_folders(
input_path=input,
target_depth=recursive[0],
current_depth=0,
width=recursive[1],
# librefit.create_recursive_folders(
# input_path=input,
# target_depth=recursive[0],
# current_depth=0,
# width=recursive[1],
# )
librefit.create_parallel_directories(
input_path=input, target_depth=recursive[0], width=recursive[1]
)
def input_validator(self):
"""Function, which checks if the user input is valid"""
# TODO: make the input validator pass without the n argument
# when recursive mode is active
# Check working directory
if self.input is None:
self.input = librefit.get_current_path(self.input)

View File

@@ -1,5 +1,5 @@
[VERSION]
major = 0
minor = 3
patch = 4
patch = 5