added custom naming to recursion and fixed naming in filemode
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user