Compare commits

...

2 Commits

Author SHA1 Message Date
f7ab347316 cleanup 2025-10-04 19:47:56 +02:00
2b1167b3ce cleanup 2025-10-04 19:44:41 +02:00
3 changed files with 46 additions and 64 deletions

View File

@@ -153,14 +153,14 @@ def get_current_path(path) -> str:
sys.exit(1)
# TODO: - add dynamic name input
# - add docstring
def create_linear_directories(input_path, target_depth, current_depth):
"""Creates the linear directories for the x*y pattern"""
logger.debug(
f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
)
# TODO: - add dynamic name input
# - add docstring
# logger.debug(
# f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
# )
if current_depth > target_depth:
return
@@ -173,24 +173,29 @@ def create_linear_directories(input_path, target_depth, current_depth):
os.mkdir(path)
create_linear_directories(path, target_depth, current_depth + 1)
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)
# 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}'"
# )
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)
create_linear_directories(
path,
target_depth,
current_depth=0,
)

View File

@@ -35,21 +35,11 @@ class Refit_Create:
logger.debug(f"FUNC: create_n_folders() ARGS: n={n} input={input} name={name}")
# Creating the length of the suffix number_string.
length_n = len(str(n))
logger.debug(
f"FUNC: create_n_folders() MSG: Length of numbering string added to the name:{length_n}"
)
length_n = librefit.get_int_length(n)
# Get either the default folder name or the input name as string.
logger.debug(
f"FUNC: create_n_folders() MSG: Type of name value: {type(name)} name={name}"
)
folder_name = librefit.get_standard_folder_name(name)
logger.debug(
f"FUNC: create_n_folders() MSG: Folder name: {folder_name} post get_standard_folder_name() call"
)
while n > 0:
# iterating down for the files number.
folder_number = n - 1
@@ -76,17 +66,13 @@ class Refit_Create:
# Get the name from the input argument.
file_name = librefit.get_standard_file_name(name)
# Get the length of the entered number to fill it with 0
length_n = len(str(n))
logger.debug(
f"FUNC: create_n_files() MSG: file name='{file_name}' length_n={length_n}"
)
while n > 0:
# Get number of the file(s) to create
file_number = n - 1
number_string = librefit.get_standard_name_number(file_number, length_n)
number_string = librefit.get_standard_name_number(
file_number, librefit.get_int_length(n)
)
# Get the name of the file, either applying default or using first list item.
temp_name = f"{file_name}_{number_string}"
@@ -94,26 +80,18 @@ class Refit_Create:
file_path = Path(os.path.join(input, temp_name)) # Build file path
file_path.touch(exist_ok=True) # creating file
logger.debug(
f"FUNC: create_n_files MSG: created file at {os.path.join(input, temp_name)}"
)
# Counting down n for the next ieration of the while-loop
n -= 1
def create_recursive(self, recursive, name, input, n):
def create_recursive(self, recursive, name, input):
"""Creating directories recursively"""
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}'"
)
# 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]
input_path=input,
target_depth=recursive[0],
width=recursive[1],
)
def input_validator(self):
@@ -125,19 +103,22 @@ class Refit_Create:
# Check working directory
if self.input is None:
self.input = librefit.get_current_path(self.input)
logger.info(
"FUNC: input_validator() MSG: No directory passed to the command, continue with current directory"
)
logger.info(f"FUNC: input_validator(input check) VALUE: input={self.input}")
# Check for conflicting flags
if self.recursive is not None and self.filemode:
logger.error("Filemode and recursive do not work together.")
logger.error(
f"FUNC: input_validator(recursive&filemode?) VALUES: recursive='{self.recursive}', filemode={self.filemode}"
)
print("Filemode and recursive do not work together.")
sys.exit(1)
# Check if recursive input is an empty list
if self.recursive is not None:
if len(self.recursive) < 2:
logger.error("Recursive flag cannot be set without values.")
logger.error(
"FUNC:input_validator(recursive) MSG: Invalid input, enter 2 numbers!"
)
sys.exit(1)
# Exit the program if the -n argument is not passed
@@ -158,10 +139,6 @@ class Refit_Create:
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function")
if self.input_validator():
logger.debug(
f"FUNC: create_dispatcher() MSG: n={self.n} after input validating"
)
if self.filemode:
logger.debug(
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}"
@@ -172,7 +149,7 @@ class Refit_Create:
logger.debug(
f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
)
self.create_recursive(self.recursive, self.name, self.input, self.n)
self.create_recursive(self.recursive, self.name, self.input)
elif not self.recursive and not self.filemode:
logger.debug(

View File

@@ -16,18 +16,18 @@ CONFIG_FILE = "version.cfg"
# TODO: see the TODO in librefit: move the config file section into the
# libary
def read_version_config():
logger.debug(f"Start read_version_config() with config file: {CONFIG_FILE}")
# logger.debug(f"Start read_version_config() with config file: {CONFIG_FILE}")
config = configparser.ConfigParser()
config.read(CONFIG_FILE)
if not os.path.exists(CONFIG_FILE):
logger.error(
f"FUNC: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'"
)
# logger.error(
# f"FUNC: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'"
# )
return "x.x.x"
if "VERSION" not in config:
logger.error(f"Could not find VERSION-variable in config file '{CONFIG_FILE}'")
# logger.error(f"Could not find VERSION-variable in config file '{CONFIG_FILE}'")
return "x.x.x"
try:
@@ -35,10 +35,10 @@ def read_version_config():
major = v.get("major", "0")
minor = v.get("minor", "0")
patch = v.get("patch", "0")
logger.debug(f"Config file read successfully. Version: {major}.{minor}.{patch}")
# logger.debug(f"Config file read successfully. Version: {major}.{minor}.{patch}")
return f"{major}.{minor}.{patch}"
except Exception:
logger.warning("Couldn not read version from config file")
# logger.warning("Couldn not read version from config file")
return "x.x.x"
@@ -95,7 +95,7 @@ args = parser.parse_args()
# Dispatcher
# determines what code gets addressed based of the users chosen flags.
if hasattr(args, "command_class"):
logger.debug(f"In dispatcher with args: {args}")
# logger.debug(f"In dispatcher with args: {args}")
Refit_Create = args.command_class
create_command_instance = Refit_Create(args)
create_command_instance()