added custom naming to recursion and fixed naming in filemode

This commit is contained in:
2025-10-05 15:58:36 +02:00
parent 46ea1db65d
commit 9c39b773da
5 changed files with 40 additions and 36 deletions

View File

@@ -153,7 +153,7 @@ def get_current_path(path) -> str:
sys.exit(1)
def create_linear_directories(input_path, target_depth, current_depth):
def create_linear_directories(input_path, target_depth, current_depth, name):
"""Creates the linear directories for the x*y pattern"""
# TODO: - add dynamic name input
@@ -162,40 +162,49 @@ def create_linear_directories(input_path, target_depth, current_depth):
# f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
# )
if name is None:
base_name = "level"
else:
base_name = name[1]
if current_depth > target_depth:
return
directory_name = "level_" + get_standard_name_number(
current_depth,
get_int_length(target_depth),
directory_name = (
base_name
+ "_"
+ 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,
)
create_linear_directories(path, target_depth, current_depth + 1, name)
def create_parallel_directories(input_path, target_depth, width):
def create_parallel_directories(input_path, target_depth, width, name):
"""Creates directories after the pattern x*y"""
# TODO: - add dynamic name input
# - add docstring
# logger.debug(
# f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}'"
# )
logger.debug(
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}', name={name}"
)
if name is None:
base_name = "branch"
else:
base_name = name[0]
for i in range(width):
directory_name = "branch_" + get_standard_name_number(i, get_int_length(width))
directory_name = (
base_name + "_" + 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,
input_path=path,
target_depth=target_depth,
current_depth=0,
name=name,
)

View File

@@ -58,6 +58,9 @@ class Refit_Create:
f"FUNC: create_n_files() MSG: Entered function VALUES: n={self.n} name={self.name} input={self.input}"
)
# Creating the length of the suffix number_string.
length_n = librefit.get_int_length(n)
# Get the name from the input argument.
file_name = librefit.get_standard_file_name(name)
@@ -65,9 +68,7 @@ class Refit_Create:
# Get number of the file(s) to create
file_number = n - 1
number_string = librefit.get_standard_name_number(
file_number, librefit.get_int_length(n)
)
number_string = librefit.get_standard_name_number(file_number, length_n)
# Get the name of the file, either applying default or using first list item.
temp_name = f"{file_name}_{number_string}"
@@ -87,14 +88,12 @@ class Refit_Create:
input_path=input,
target_depth=recursive[0],
width=recursive[1],
name=name,
)
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)
@@ -138,6 +137,9 @@ class Refit_Create:
self.create_n_files(self.n, self.input, self.name)
elif self.recursive is not None:
# NOTE: for the dynamic name use two more args, if they
# exist, take them as name for the two dirs. else use
# default names
logger.debug(
f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
)

View File

@@ -41,9 +41,6 @@ REFIT_VERSION = f"Refit Beta {read_version_config()}"
# ---------------------------ARGPARSE START---------------------------
# TODO: Rework the structure of the argument parsing
# Main Parser
parser = argparse.ArgumentParser(
prog="Refit",
@@ -79,7 +76,7 @@ create_parser.add_argument(
"--recursive",
type=int,
nargs=2,
help="Sets the recursive mode for folders to true. First argumet\n is for the depth and the second for the width.",
help="Sets the recursive mode for folders to true. First argumet is for the depth and the second for the width.",
)
create_parser.set_defaults(command_class=Refit_Create)

View File

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