added custom naming to recursion and fixed naming in filemode
This commit is contained in:
@@ -13,18 +13,14 @@
|
||||
3. file removal
|
||||
3.1 remove all files like '*.tar'
|
||||
|
||||
- ~~make input default the current directory and the
|
||||
second argument after `refit create`~~
|
||||
- ~~maybe get rid of valid input ??~~
|
||||
- rework rf_create_decider() so it does not execute if no inputs are give
|
||||
n -> valid input check back for no arguments passed?
|
||||
- check done in rf_create_decider()
|
||||
- get rid of input argument, default to current directory and make it
|
||||
positional
|
||||
- implement back in the valid input check
|
||||
- implement config file containing version, default names and other
|
||||
configurations
|
||||
- make file and directory creation start counting at 1 instead of 0
|
||||
|
||||
## Changelog
|
||||
|
||||
<2025-10-05> V0.3.7 - Added custom naming for level and branch in
|
||||
recursive mode
|
||||
<2025-10-05> V0.3.6 - Recursive mode no longer requires the -n flag
|
||||
<2025-10-04> V0.3.5 - Added a function which returns the length of a
|
||||
number
|
||||
|
||||
@@ -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}"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[VERSION]
|
||||
major = 0
|
||||
minor = 3
|
||||
patch = 6
|
||||
patch = 7
|
||||
|
||||
|
||||
Reference in New Issue
Block a user