Compare commits
4 Commits
67e68da880
...
e9b491e81d
| Author | SHA1 | Date | |
|---|---|---|---|
| e9b491e81d | |||
| e243f5f379 | |||
| c1e76b660a | |||
| 1c557913f9 |
@@ -25,6 +25,10 @@ n -> valid input check back for no arguments passed?
|
|||||||
|
|
||||||
## 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
|
<2025-10-04> V0.3.4 - Added recursive directory creation and fixed
|
||||||
numbered naming
|
numbered naming
|
||||||
<2025-10-03> V0.3.3 - Added the beginning of recursive mode
|
<2025-10-03> V0.3.3 - Added the beginning of recursive mode
|
||||||
|
|||||||
@@ -7,6 +7,28 @@ from .refit_logger import logger
|
|||||||
# reusable
|
# 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:
|
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
|
"""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)
|
>>> get_standard_name_number(23, 4)
|
||||||
'0023'
|
'0023'
|
||||||
"""
|
"""
|
||||||
logger.debug(
|
# logger.debug(
|
||||||
f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
|
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
|
||||||
)
|
# )
|
||||||
temp_current_number = str(current_number)
|
temp_current_number = str(current_number)
|
||||||
standard_name_number = str.zfill(temp_current_number, number_str_length)
|
standard_name_number = str.zfill(temp_current_number, number_str_length)
|
||||||
logger.debug(
|
# logger.debug(
|
||||||
f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
|
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
|
||||||
)
|
# )
|
||||||
return standard_name_number
|
return standard_name_number
|
||||||
|
|
||||||
|
|
||||||
@@ -59,15 +81,8 @@ def get_standard_folder_name(name: str) -> str:
|
|||||||
'directory_name'
|
'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"
|
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
|
return standard_folder_name
|
||||||
|
|
||||||
|
|
||||||
@@ -95,15 +110,8 @@ def get_standard_file_name(name) -> str:
|
|||||||
'file_name'
|
'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"
|
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
|
return standard_file_name
|
||||||
|
|
||||||
|
|
||||||
@@ -125,16 +133,16 @@ def get_current_path(path) -> str:
|
|||||||
if path is None:
|
if path is None:
|
||||||
# Set the current directory if none is passed with the command.
|
# Set the current directory if none is passed with the command.
|
||||||
path = "."
|
path = "."
|
||||||
logger.warning(
|
# logger.warning(
|
||||||
f"FUNC: {get_current_path.__name__}() MSG: Path now has the value: '{path}'"
|
# f"FUNC: {get_current_path.__name__}() MSG: Path now has the value: '{path}'"
|
||||||
)
|
# )
|
||||||
return path
|
return path
|
||||||
else:
|
else:
|
||||||
# Checks if the path, entered by the user, exists.
|
# Checks if the path, entered by the user, exists.
|
||||||
if os.path.exists(path) is True:
|
if os.path.exists(path) is True:
|
||||||
logger.debug(
|
# logger.debug(
|
||||||
f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue...."
|
# f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue...."
|
||||||
)
|
# )
|
||||||
return path
|
return path
|
||||||
else:
|
else:
|
||||||
ERROR_MESSAGE = (
|
ERROR_MESSAGE = (
|
||||||
@@ -145,37 +153,44 @@ def get_current_path(path) -> str:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# TODO: - add logging
|
# TODO: - add dynamic name input
|
||||||
# - add docstring
|
# - add docstring
|
||||||
# - add proper naming to the files
|
def create_linear_directories(input_path, target_depth, current_depth):
|
||||||
def create_recursive_folders(input_path, target_depth, current_depth, width):
|
"""Creates the linear directories for the x*y pattern"""
|
||||||
"""Creates a recursive directory structure with y as depth and x as width"""
|
|
||||||
|
|
||||||
# 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(
|
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
|
if current_depth > target_depth:
|
||||||
for i in range(width):
|
return
|
||||||
# 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}")
|
|
||||||
|
|
||||||
create_recursive_folders(
|
directory_name = "level_" + get_standard_name_number(
|
||||||
new_directory_path,
|
current_depth,
|
||||||
target_depth,
|
get_int_length(target_depth),
|
||||||
current_depth + 1,
|
)
|
||||||
width,
|
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)
|
||||||
|
|||||||
@@ -105,16 +105,23 @@ class Refit_Create:
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'"
|
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'"
|
||||||
)
|
)
|
||||||
librefit.create_recursive_folders(
|
# librefit.create_recursive_folders(
|
||||||
input_path=input,
|
# input_path=input,
|
||||||
target_depth=recursive[0],
|
# target_depth=recursive[0],
|
||||||
current_depth=0,
|
# current_depth=0,
|
||||||
width=recursive[1],
|
# width=recursive[1],
|
||||||
|
# )
|
||||||
|
|
||||||
|
librefit.create_parallel_directories(
|
||||||
|
input_path=input, target_depth=recursive[0], width=recursive[1]
|
||||||
)
|
)
|
||||||
|
|
||||||
def input_validator(self):
|
def input_validator(self):
|
||||||
"""Function, which checks if the user input is valid"""
|
"""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
|
# Check working directory
|
||||||
if self.input is None:
|
if self.input is None:
|
||||||
self.input = librefit.get_current_path(self.input)
|
self.input = librefit.get_current_path(self.input)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[VERSION]
|
[VERSION]
|
||||||
major = 0
|
major = 0
|
||||||
minor = 3
|
minor = 3
|
||||||
patch = 4
|
patch = 5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user